System.Threading.ClientInterlocked.CompareExchange C# (CSharp) Method

CompareExchange() public static method

public static CompareExchange ( IntPtr &location, IntPtr value, IntPtr comparand ) : IntPtr
location System.IntPtr
value System.IntPtr
comparand System.IntPtr
return System.IntPtr
        public static IntPtr CompareExchange(ref IntPtr location, IntPtr value, IntPtr comparand)
        {
            return Interlocked.CompareExchange(ref location, value, comparand);
        }

Same methods

ClientInterlocked::CompareExchange ( double &location, double value, double comparand ) : double
ClientInterlocked::CompareExchange ( float &location, float value, float comparand ) : float
ClientInterlocked::CompareExchange ( int &location, int value, int comparand ) : int
ClientInterlocked::CompareExchange ( long &location, long value, long comparand ) : long
ClientInterlocked::CompareExchange ( object &location, object value, object comparand ) : object

Usage Example

Example #1
0
        public void EnterWriteLock()
        {
            ClientSpinWait sw = new ClientSpinWait();

            do
            {
                int state = rwlock;
                if (state < RwWrite)
                {
                    if (ClientInterlocked.CompareExchange(ref rwlock, RwWrite, state) == state)
                    {
                        return;
                    }
                    state = rwlock;
                }
                // We register our interest in taking the Write lock (if upgradeable it's already done)
                while ((state & RwWait) == 0 && ClientInterlocked.CompareExchange(ref rwlock, state | RwWait, state) != state)
                {
                    state = rwlock;
                }
                // Before falling to sleep
                while (rwlock > RwWait)
                {
                    sw.SpinOnce();
                }
            } while (true);
        }
All Usage Examples Of System.Threading.ClientInterlocked::CompareExchange