private void RecordTakeFromGlobalPool(int thisThreadID) { PendingEntry <T>[] pending = this.pending; for (int i = 0; i < pending.Length; i++) { int threadID = pending[i].threadID; if (threadID == thisThreadID) { return; } if (threadID == 0) { lock (pending) { if (pending[i].threadID == 0) { pending[i].threadID = thisThreadID; return; } } } } if (pending.Length >= 0x80) { this.pending = new PendingEntry <T> [pending.Length]; } else { PendingEntry <T>[] destinationArray = new PendingEntry <T> [pending.Length * 2]; Array.Copy(pending, destinationArray, pending.Length); this.pending = destinationArray; } }
private void RecordTakeFromGlobalPool(int thisThreadID) { PendingEntry[] localPending = _pending; for (int i = 0; i < localPending.Length; i++) { int threadID = localPending[i].threadID; if (threadID == thisThreadID) { return; } else if (threadID == 0) { lock (localPending) { if (localPending[i].threadID == 0) { localPending[i].threadID = thisThreadID; return; } } } } if (localPending.Length >= maxPendingEntries) { _pending = new PendingEntry[localPending.Length]; } else { PendingEntry[] newPending = new PendingEntry[localPending.Length * 2]; Array.Copy(localPending, newPending, localPending.Length); _pending = newPending; } }
public void Insert(int index, IBaseGameComponent item) { EnsureNotReadOnly(); if (HasActiveEnumerators || _updateSuspended) { var entry = new PendingEntry { Operation = Operation.Insert, Index = index, Item = item }; _pendingQueue.Enqueue(entry); } else { var lastIndex = _components.IndexOf(item); if (lastIndex < 0) { _components.Insert(index, item); } else { if (lastIndex < index) { --index; } _components.RemoveAt(lastIndex); _components.Insert(index, item); } } }
public void Clear() { EnsureNotReadOnly(); if (HasActiveEnumerators || _updateSuspended) { var entry = new PendingEntry { Operation = Operation.Clear }; _pendingQueue.Enqueue(entry); } else { _components.Clear(); } }
public void RemoveAt(int index) { EnsureNotReadOnly(); if (HasActiveEnumerators || _updateSuspended) { var entry = new PendingEntry { Operation = Operation.RemoveAt, Index = index }; _pendingQueue.Enqueue(entry); } else { _components.RemoveAt(index); } }
public void Add(IBaseGameComponent item) { EnsureNotReadOnly(); if (HasActiveEnumerators || _updateSuspended) { var entry = new PendingEntry { Operation = Operation.Add, Item = item }; _pendingQueue.Enqueue(entry); } else { if (!_components.Contains(item)) { _components.Add(item); } } }
public bool Remove(IBaseGameComponent item) { EnsureNotReadOnly(); if (HasActiveEnumerators || _updateSuspended) { var canBeDeleted = ValidateComponentDeletion(item); if (canBeDeleted) { var entry = new PendingEntry { Operation = Operation.Remove, Item = item }; _pendingQueue.Enqueue(entry); } return(canBeDeleted); } else { return(_components.Remove(item)); } }