internal override void RegisterRetryLatch(IRetryLatch latch, BaseVBoxBody expectedBody, int expectedEra) { if (_body != expectedBody) { //if it currently already contains a different version, we are done. latch.Open(expectedEra); return; } while (true) { if (_body != expectedBody) { //if it currently already contains a different version, we are done. latch.Open(expectedEra); return; } var initialValue = _listeners; var result = Interlocked.CompareExchange(ref _listeners, _listeners.Add(latch), initialValue); if (result != initialValue) { continue; } if (_body == expectedBody) { return; } //version has changed unregister while (true) { initialValue = _listeners; result = Interlocked.CompareExchange(ref _listeners, _listeners.Add(latch), initialValue); if (result != initialValue) { continue; } return; } } }
internal abstract void RegisterRetryLatch(IRetryLatch latch, BaseVBoxBody expectedBody, int expectedEra);