Mspthrd.h
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:3k
源码类别:

模拟服务器

开发平台:

C/C++

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4.     mspthrd.h
  5. Abstract:
  6.     Definitions for MSP thread management classes.
  7. --*/
  8. #ifndef __MSPTHRD_H
  9. #define __MSPTHRD_H
  10. //
  11. // Commands that the worker worker thread can handle.
  12. //
  13. typedef enum
  14. {
  15.     WORK_ITEM,          // process a work item
  16.     STOP,               // kill the worker thread.
  17. } COMMAND;
  18. typedef struct
  19. {
  20.     COMMAND                cmd;
  21.     LPTHREAD_START_ROUTINE pfn;
  22.     PVOID                  pContext;
  23.     HANDLE                 hEvent;
  24. } COMMAND_NODE;
  25. typedef struct
  26. {
  27.     LIST_ENTRY  link;
  28.     COMMAND_NODE node;
  29. } COMMAND_QUEUE_ITEM;
  30. typedef struct _NOTIF_LIST
  31. {
  32.     CMSPAddress      *addr;
  33.     _NOTIF_LIST      *next;
  34. } NOTIF_LIST, *PNOTIF_LIST;
  35. class CMSPThread
  36. {
  37. public:
  38.     CMSPThread()
  39.     {
  40.         InitializeListHead(&m_CommandQueue);
  41.         m_hCommandEvent = NULL;
  42.         m_hThread       = NULL;
  43.         m_NotifList     = NULL;
  44.         m_iStartCount = 0;
  45.     }
  46.     ~CMSPThread() { };
  47.     HRESULT Start();
  48.     HRESULT Stop();
  49.     // Shutdown is used to clean up the thread unconditionally. This can be
  50.     // used as an alternative to matched Start() / Stop() calls.
  51.     HRESULT Shutdown();
  52.     HRESULT ThreadProc();
  53.     static LRESULT CALLBACK NotifWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  54.     HRESULT RegisterPnpNotification(CMSPAddress *pCMSPAddress);
  55.     HRESULT UnregisterPnpNotification(CMSPAddress *pCMSPAddress);
  56.     HRESULT QueueWorkItem(
  57.         LPTHREAD_START_ROUTINE Function,
  58.         PVOID Context,
  59.         BOOL  fSynchronous
  60.         );
  61. private:
  62.     BOOL SignalThreadProc() { return SetEvent(m_hCommandEvent); }
  63. private:
  64.     CMSPCritSection         m_CountLock;     // Protects start count
  65.     CMSPCritSection         m_QueueLock;     // Protects command queue
  66.     int                     m_iStartCount;   // number of times we've been
  67.                                              // started minus number of times
  68.                                              // we've been stopped. If == 0
  69.                                              // then we actually stop thread.
  70.     LIST_ENTRY              m_CommandQueue;  // Queue of commands for thread
  71.                                              // to process.
  72.     HANDLE                  m_hCommandEvent; // Signaled to tell us to do
  73.                                              // something.
  74.     HANDLE                  m_hThread;       // The thread handle. We need to
  75.                                              // save it so that we can wait
  76.                                              // for it when stopping the
  77.                                              // thread.
  78.     HDEVNOTIFY              m_hDevNotifyVideo;  // Handles of device notification registration
  79.     HDEVNOTIFY              m_hDevNotifyAudio;  // for video and audio devices.
  80.     HWND                    m_hWndNotif;     // Window handle for notification window
  81.     PNOTIF_LIST             m_NotifList;     // List of notification functions to call
  82.                                              // on a PNP event
  83.     CMSPCritSection         m_NotifLock;     // Notification list critical section
  84. };
  85. extern CMSPThread g_Thread;
  86. #endif // __MSPTHRD_H
  87. // eof