From e05c38dcf6d444f5c47cbbbbab2817cd1c450ae3 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Wed, 22 Aug 2018 13:57:46 -0400 Subject: [PATCH] remove ThreadYieldRWGate --- .../spark/core/Utility/ThreadYieldRWGate.cs | 35 ------------------- 1 file changed, 35 deletions(-) delete mode 100644 src/client/spark/core/Utility/ThreadYieldRWGate.cs diff --git a/src/client/spark/core/Utility/ThreadYieldRWGate.cs b/src/client/spark/core/Utility/ThreadYieldRWGate.cs deleted file mode 100644 index 7d77ebe1f..000000000 --- a/src/client/spark/core/Utility/ThreadYieldRWGate.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Threading; - -namespace mbts.utils { - /// - /// Provides mechanisms to ensure that only one write op may execute at a time, and calls to read or write while a write op is underway will Thread.yield until the write-op is completed. - /// If no write-op is underway, read-ops may run concurrently. - /// - class ThreadYieldRWGate { - int _n_write_ops, _n_read_ops; - - public IDisposable read() { - while (_n_write_ops > 0) - Thread.Yield(); - Interlocked.Increment(ref _n_read_ops); - if (_n_write_ops > 0) { - // A write-op was yielding at the same time and beat us to the punch! Try again - Interlocked.Decrement(ref _n_read_ops); - return read(); - } - return Disposable.Create(() => Interlocked.Decrement(ref _n_read_ops)); - } - - public IDisposable write() { - while (_n_read_ops > 0 || _n_write_ops > 0) - Thread.Yield(); - if (Interlocked.Increment(ref _n_write_ops) > 1 || _n_read_ops > 0) { - // Another write/read-op was yielding at the same time and beat us to the punch! Try again - Interlocked.Decrement(ref _n_write_ops); - return write(); - } - return Disposable.Create(() => Interlocked.Decrement(ref _n_write_ops)); - } - } -} \ No newline at end of file