/// <summary> /// After no reading will be done for the given reader ticket, release it with this method. /// </summary> public static void ReleaseReaderTicket(ref ReadTicket ticket) { var node = (VersionEntry)ticket; ticket = null; Interlocked.Decrement(ref node.ReaderCount); }
/// <summary> /// Reader should keep a reference to his ticket, and release it with a call /// to <see cref="ReleaseReaderTicket"/> when done. /// </summary> public static void GetReaderTicket(out ReadTicket ticket) { try {} finally { while (true) { var curr = _current; // trimming sets this to int.MinValue, so unless 2 billion threads are doing this // simultaneously, we're safe. if (Interlocked.Increment(ref curr.ReaderCount) > 0) { ticket = curr; break; } } } }