internal void AddNode(LibraryNode node) { lock (this) { // re-create root node here because we may have handed out the node before and don't want to mutate it's list. _root = _root.Clone(); _root.AddNode(node); _updateCount++; } }
private void ApplyUpdates(bool assumeLockHeld) { if (!assumeLockHeld) { if (!_searching.Wait(0)) { // Didn't get the lock immediately, which means we are // currently searching. Once the search is done, updates // will be applied. return; } } try { lock (_updates) { if (_updates.Count == 0) { return; } // re-create root node here because we may have handed out // the node before and don't want to mutate it's list. _root = _root.Clone(); _updateCount += 1; foreach (var kv in _updates) { switch (kv.Key) { case UpdateType.Add: _root.AddNode(kv.Value); break; case UpdateType.Remove: _root.RemoveNode(kv.Value); break; default: Debug.Fail("Unsupported update type " + kv.Key.ToString()); break; } } _updates.Clear(); } } finally { if (!assumeLockHeld) { _searching.Release(); } } }