public static CompareExchange ( long &location, long value, long comparand ) : long | ||
location | long | |
value | long | |
comparand | long | |
return | long |
public static long CompareExchange(ref long location, long value, long comparand)
{
return Interlocked.CompareExchange(ref location, value, comparand);
}
ClientInterlocked::CompareExchange ( |
|
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 ( object &location, object value, object comparand ) : object |
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); }