Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.3 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) Microsoft Corporation
  4. //
  5. // SYNOPSIS
  6. //
  7. // Declares the class CommandPool.
  8. //
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef COMMANDPOOL_H
  11. #define COMMANDPOOL_H
  12. #pragma once
  13. #include "reporteventcmd.h"
  14. // Maintains a blocking pool of command objects.
  15. class CommandPool
  16. {
  17. public:
  18. CommandPool() throw ();
  19. ~CommandPool() throw ();
  20. HRESULT FinalConstruct() throw ();
  21. // Set the maximum number of pooled commands.
  22. void SetMaxCommands(size_t newValue) throw ();
  23. // Current version of the pool.
  24. unsigned int Version() throw ();
  25. // Allocate a command object, blocking until one is available.
  26. ReportEventCommand* Alloc() throw ();
  27. // Free a command object.
  28. void Free(ReportEventCommand* cmd) throw ();
  29. // Unprepare all commands in the pool. Commands that are currently in use
  30. // will be unprepared when they are freed.
  31. void UnprepareAll() throw ();
  32. private:
  33. void Lock() throw ();
  34. void Unlock() throw ();
  35. // Acquire both the lock and a resource.
  36. void LockAndWait() throw ();
  37. // Release both the lock and a resource.
  38. void UnlockAndRelease() throw ();
  39. void Push(ReportEventCommand* cmd) throw ();
  40. ReportEventCommand* Pop() throw ();
  41. // Version of the pool; used to detect stale command objects.
  42. unsigned int version;
  43. // Singly-linked list of commands available for use.
  44. ReportEventCommand* pool;
  45. // Maximum number of command objects allowed in existence. This limit may be
  46. // temporarily exceeded if maxCommands is reduced while commands are in use.
  47. size_t maxCommands;
  48. // Number of command objects in existence.
  49. size_t numCommands;
  50. // Number of threads that own a command.
  51. size_t owners;
  52. // Number of threads waiting for a command.
  53. size_t waiters;
  54. // Semaphore used to signal threads waiting for a command.
  55. HANDLE semaphore;
  56. // Serialize access.
  57. CRITICAL_SECTION lock;
  58. // Not implemented.
  59. CommandPool(const CommandPool&);
  60. CommandPool& operator=(const CommandPool&);
  61. };
  62. inline unsigned int CommandPool::Version() throw ()
  63. {
  64. return version;
  65. }
  66. #endif // COMMANDPOOL_H