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.

128 lines
3.3 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999-2002 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: SyncEvent.h
  6. * Content: Synchronization Events FPM Header File
  7. *@@BEGIN_MSINTERNAL
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 12/20/99 mjn Created
  12. * 01/19/00 mjn Replaced DN_SYNC_EVENT with CSyncEvent
  13. *@@END_MSINTERNAL
  14. *
  15. ***************************************************************************/
  16. #ifndef __SYNC_EVENT_H__
  17. #define __SYNC_EVENT_H__
  18. #undef DPF_SUBCOMP
  19. #define DPF_SUBCOMP DN_SUBCOMP_CORE
  20. //**********************************************************************
  21. // Constant definitions
  22. //**********************************************************************
  23. //**********************************************************************
  24. // Macro definitions
  25. //**********************************************************************
  26. //**********************************************************************
  27. // Structure definitions
  28. //**********************************************************************
  29. class CFixedPool;
  30. //**********************************************************************
  31. // Variable definitions
  32. //**********************************************************************
  33. extern CFixedPool g_SyncEventPool;
  34. //**********************************************************************
  35. // Function prototypes
  36. //**********************************************************************
  37. //**********************************************************************
  38. // Class prototypes
  39. //**********************************************************************
  40. // class for RefCount buffer
  41. class CSyncEvent
  42. {
  43. public:
  44. #undef DPF_MODNAME
  45. #define DPF_MODNAME "CSyncEvent::FPMAlloc"
  46. static BOOL FPMAlloc( void* pvItem, void* pvContext )
  47. {
  48. CSyncEvent* pSyncEvent = (CSyncEvent*)pvItem;
  49. if ((pSyncEvent->m_hEvent = DNCreateEvent(NULL,TRUE,FALSE,NULL)) == NULL)
  50. {
  51. return(FALSE);
  52. }
  53. return(TRUE);
  54. };
  55. #undef DPF_MODNAME
  56. #define DPF_MODNAME "CSyncEvent::FPMInitialize"
  57. static void FPMInitialize( void* pvItem, void* pvContext )
  58. {
  59. CSyncEvent* pSyncEvent = (CSyncEvent*)pvItem;
  60. pSyncEvent->Reset();
  61. pSyncEvent->m_pIDPThreadPoolWork = (IDirectPlay8ThreadPoolWork*) pvContext;
  62. };
  63. #undef DPF_MODNAME
  64. #define DPF_MODNAME "CSyncEvent::FPMDealloc"
  65. static void FPMDealloc( void* pvItem )
  66. {
  67. CSyncEvent* pSyncEvent = (CSyncEvent*)pvItem;
  68. DNCloseHandle(pSyncEvent->m_hEvent);
  69. pSyncEvent->m_hEvent = NULL;
  70. };
  71. void ReturnSelfToPool( void )
  72. {
  73. g_SyncEventPool.Release( this );
  74. };
  75. HRESULT Reset( void ) const
  76. {
  77. if (DNResetEvent(m_hEvent) == 0)
  78. {
  79. return(DPNERR_GENERIC);
  80. }
  81. return(DPN_OK);
  82. }
  83. HRESULT Set( void ) const
  84. {
  85. if (DNSetEvent(m_hEvent) == 0)
  86. {
  87. return(DPNERR_GENERIC);
  88. }
  89. return(DPN_OK);
  90. }
  91. HRESULT WaitForEvent(void) const
  92. {
  93. return(IDirectPlay8ThreadPoolWork_WaitWhileWorking(m_pIDPThreadPoolWork,
  94. HANDLE_FROM_DNHANDLE(m_hEvent),
  95. 0));
  96. }
  97. private:
  98. DNHANDLE m_hEvent;
  99. IDirectPlay8ThreadPoolWork *m_pIDPThreadPoolWork;
  100. };
  101. #undef DPF_MODNAME
  102. #endif // __SYNC_EVENT_H__