WorkPool.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #pragma once
  2. // 下列 ifdef 块是创建使从 DLL 导出更简单的
  3. // 宏的标准方法。此 DLL 中的所有文件都是用命令行上定义的 WORKPOOL_EXPORTS
  4. // 符号编译的。在使用此 DLL 的
  5. // 任何其他项目上不应定义此符号。这样,源文件中包含此文件的任何其他项目都会将
  6. // WORKPOOL_API 函数视为是从 DLL 导入的,而此 DLL 则将用此宏定义的
  7. // 符号视为是被导出的。
  8. #ifndef WORKPOOL_EXPORTS
  9. #ifdef _WIN64
  10. #ifdef _DEBUG
  11. #pragma comment(lib, "WorkPoolX64D.lib")
  12. #else
  13. #pragma comment(lib, "WorkPoolX64.lib")
  14. #endif
  15. #else
  16. #ifdef _DEBUG
  17. #pragma comment(lib, "WorkPoolD.lib")
  18. #else
  19. #pragma comment(lib, "WorkPool.lib")
  20. #endif
  21. #endif
  22. #endif
  23. #ifdef WORKPOOL_EXPORTS
  24. #define WORKPOOL_API __declspec(dllexport)
  25. #define WORKPOOL_C_API extern "C" __declspec(dllexport)
  26. #else
  27. #define WORKPOOL_API __declspec(dllimport)
  28. #define WORKPOOL_C_API extern "C" __declspec(dllimport)
  29. #endif
  30. #include "logger.h"
  31. #include "DiosThread.h"
  32. #include "DataBase_IF.h"
  33. #include "ShareMem_Node.h"
  34. #define CmdRecalcAll "RecalcAll"
  35. #define CmdRecalcOne "RecalcOne"
  36. #define CmdSaveCodeAll "SaveCodeAll"
  37. class WORKPOOL_API PoolThread : public Work_Thread
  38. {
  39. protected:
  40. HANDLE m_Standby;
  41. DataBase_IF *m_pDb;
  42. virtual bool Exec();
  43. virtual bool OnStartThread();
  44. virtual bool OnEndThread();
  45. public:
  46. PoolThread(void);
  47. virtual ~PoolThread();
  48. bool SaveRawData(ShareMem_Node *pNode);
  49. bool ReqProcess(ResDataObject &obj);
  50. bool RecalcAllCode(UINT64 StartTime);
  51. bool RecalcOneCode(const char *pszCode,UINT64 StartTime);
  52. bool SaveFullData();
  53. bool GetStandbyStatus();
  54. HANDLE GetStandbyHandle();
  55. };
  56. class WORKPOOL_API WorkPool {
  57. protected:
  58. DWORD ThreadCount;
  59. PoolThread *pThreadList;
  60. HANDLE *pStandbyList;
  61. Logger *m_plogger;
  62. public:
  63. WorkPool(void);
  64. virtual ~WorkPool();
  65. virtual bool CreateWPool(DWORD CountOfThread);
  66. void CloseWPool();
  67. bool RunWPool();
  68. bool StopWPool(DWORD timeout = 5000);
  69. bool PushReqDataObject(ResDataObject &obj,bool AllThread = true);
  70. bool PauseThread(DWORD timeout = INFINITE, bool AllThread = true);
  71. bool ResumeThread(DWORD timeout = INFINITE, bool AllThread = true);
  72. bool RecalcAllCode(UINT64 StartTime);
  73. bool RecalcOneCode(const char *pszCode, UINT64 StartTime);
  74. bool SaveFullData();
  75. };