예제 #1
0
        //
        // Int32
        //

        public static int CompareExchange(system.Int32 data, int update, int expect)
        {
            int current = data.VolatileGet();

            data.CompareAndSwap(expect, update);
            return(current);
        }
예제 #2
0
 public static int Exchange(system.Int32 data, int update)
 {
     for (;;)
     {
         int current = data.VolatileGet();
         if (data.CompareAndSwap(current, update))
         {
             return(current);
         }
     }
 }
예제 #3
0
 public static int Add(system.Int32 data, int v)
 {
     for (;;)
     {
         int current = data.VolatileGet();
         int next    = current + v;
         if (data.CompareAndSwap(current, next))
         {
             return(next);
         }
     }
 }
예제 #4
0
 public static int Decrement(system.Int32 data)
 {
     for (;;)
     {
         int current = data.VolatileGet();
         int next    = current - 1;
         if (data.CompareAndSwap(current, next))
         {
             return(next);
         }
     }
 }