Esempio n. 1
0
 internal void RemoveNode(LibraryNode node)
 {
     lock (this) {
         _root = _root.Clone();
         _root.RemoveNode(node);
         _updateCount++;
     }
 }
Esempio n. 2
0
        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();
                }
            }
        }