Ejemplo n.º 1
0
 internal void Set <V>(UserDataSlot <V> slot, V userData)
 {
     using (synchronizer.AcquireWriteLock())
     {
         slot.SetUserData(this, userData);
     }
 }
Ejemplo n.º 2
0
            internal V GetOrSet <V, S>(UserDataSlot <V> slot, ref S valueFactory)
                where S : struct, ISupplier <V>
            {
                V userData;

                //fast path - read user data if it is already exists
                //do not use UpgradeableReadLock due to performance reasons
                using (synchronizer.AcquireReadLock())
                {
                    if (slot.GetUserData(this, out userData))
                    {
                        return(userData);
                    }
                }
                //non-fast path, no user data presented
                using (synchronizer.AcquireWriteLock())
                {
                    if (!slot.GetUserData(this, out userData))
                    {
                        slot.SetUserData(this, userData = valueFactory.Supply());
                    }
                    return(userData);
                }
            }