LockQueue.cs 799 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // System.Threading.LockQueue
  3. //
  4. // Author(s):
  5. // Jackson Harper ([email protected])
  6. //
  7. // (C) 2004 Novell, Inc (http://www.novell.com)
  8. //
  9. using System;
  10. namespace System.Threading {
  11. // Used for queueing on a reader writer lock
  12. internal class LockQueue {
  13. private ReaderWriterLock rwlock;
  14. public LockQueue (ReaderWriterLock rwlock)
  15. {
  16. lock (this) this.rwlock = rwlock;
  17. }
  18. public void Wait (int timeout)
  19. {
  20. bool _lock = false;
  21. try {
  22. lock (this) {
  23. Monitor.Exit (rwlock);
  24. _lock = true;
  25. Monitor.Wait (this, timeout);
  26. }
  27. } finally {
  28. if (_lock)
  29. lock (this) Monitor.Enter (rwlock);
  30. }
  31. }
  32. public void Pulse ()
  33. {
  34. lock (this) Monitor.Pulse (this);
  35. }
  36. public void PulseAll ()
  37. {
  38. lock (this) Monitor.PulseAll (this);
  39. }
  40. }
  41. }