VolatileWrite() public static method

public static VolatileWrite ( System &address, System value ) : void
address System
value System
return void
コード例 #1
0
 private void ExitExtracted(bool useMemoryBarrier)
 {
     if (useMemoryBarrier)
     {
         Thread.VolatileWrite(ref _isHeld, 0);
         Volatile.Write(ref _ownerThread, null);
     }
     else
     {
         _isHeld      = 0;
         _ownerThread = null;
     }
 }
コード例 #2
0
        public void Reset()
        {
            if (Thread.VolatileRead(ref _state) == -1)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }
            var handle = GetWaitHandle();

            if (handle != null)
            {
                handle.Reset();
            }
            Thread.VolatileWrite(ref _state, 0);
        }
コード例 #3
0
        private ManualResetEvent TryGetWaitHandleExtracted()
        {
            var handle = ThreadingHelper.VolatileRead(ref _handle);

            if (handle != null)
            {
                if (Thread.VolatileRead(ref _requested) == 2)
                {
                    return(handle);
                }
                handle.Close();
            }
            Thread.VolatileWrite(ref _requested, -1);
            throw new ObjectDisposedException(GetType().FullName);
        }
コード例 #4
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (Interlocked.Exchange(ref _state, -1) != -1)
         {
             Thread.VolatileWrite(ref _requested, -1);
             var handle = Interlocked.Exchange(ref _handle, null);
             if (handle != null)
             {
                 handle.Close();
             }
         }
     }
 }
コード例 #5
0
 public void Set()
 {
     if (Thread.VolatileRead(ref _state) == -1)
     {
         // Silent fail
     }
     else
     {
         var handle = GetWaitHandle();
         if (handle != null)
         {
             handle.Set();
         }
         Thread.VolatileWrite(ref _state, 1);
     }
 }
コード例 #6
0
 public void Reset(int count)
 {
     CheckDisposed();
     if (count < 0)
     {
         throw new ArgumentOutOfRangeException("count");
     }
     Thread.VolatileWrite(ref _currentCount, count);
     _initialCount = count;
     if (count == 0)
     {
         _event.Set();
     }
     else
     {
         _event.Reset();
     }
 }
コード例 #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Barrier"/> class.
        /// </summary>
        /// <param name="participantCount">The number of participating threads.</param>
        /// <param name="postPhaseAction">The <see cref="T:System.Action`1"/> to be executed after each
        /// phase.</param>
        /// <exception cref="T:System.ArgumentOutOfRangeException"> <paramref name="participantCount"/> is less than 0
        /// or greater than <see cref="T:System.Int32.MaxValue"/>.</exception>
        /// <remarks>
        /// The <paramref name="postPhaseAction"/> delegate will be executed after
        /// all participants have arrived at the barrier in one phase.  The participants
        /// will not be released to the next phase until the postPhaseAction delegate
        /// has completed execution.
        /// </remarks>
        public Barrier(int participantCount, Action <Barrier> postPhaseAction)
        {
            // the count must be non negative value
            if (participantCount < 0 || participantCount > Max_Participants)
            {
                throw new ArgumentOutOfRangeException("participantCount", participantCount, "The participantCount argument must be non-negative and less than or equal to 32767.");
            }
            Thread.VolatileWrite(ref _currentTotalCount, participantCount);
            _postPhaseAction = postPhaseAction;

            //Lazily initialize the events
            _oddEvent  = new ManualResetEventSlim(true);
            _evenEvent = new ManualResetEventSlim(false);

            // Capture the context if the post phase action is not null
            if (postPhaseAction != null && !ExecutionContext.IsFlowSuppressed())
            {
                _ownerThreadContext = ExecutionContext.Capture();
            }

            _actionCallerId = 0;
        }
コード例 #8
0
 public static void Write(ref sbyte location, sbyte value) => Thread.VolatileWrite(ref location, value);
コード例 #9
0
 public static void Write(ref short location, short value) => Thread.VolatileWrite(ref location, value);
コード例 #10
0
 public static void Write(ref long location, long value) => Thread.VolatileWrite(ref location, value);
コード例 #11
0
 public static void Write(ref IntPtr location, IntPtr value) => Thread.VolatileWrite(ref location, value);
コード例 #12
0
 public static void Write(ref float location, float value) => Thread.VolatileWrite(ref location, value);
コード例 #13
0
 public static void Write(ref ushort location, ushort value)
 {
     Thread.VolatileWrite(ref location, value);
 }
コード例 #14
0
 public static void Write(ref uint location, uint value) => Thread.VolatileWrite(ref location, value);
コード例 #15
0
 public static void Write(ref UIntPtr location, UIntPtr value)
 {
     Thread.VolatileWrite(ref location, value);
 }
コード例 #16
0
 public static void Write(ref ulong location, ulong value)
 {
     Thread.VolatileWrite(ref location, value);
 }
コード例 #17
0
 public static void Write(ref int location, int value)
 {
     Thread.VolatileWrite(ref location, value);
 }
コード例 #18
0
 public static void Write(ref double location, double value) => Thread.VolatileWrite(ref location, value);
コード例 #19
0
 public static void Write(ref byte location, byte value)
 {
     Thread.VolatileWrite(ref location, value);
 }