00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00026 #ifndef OW32_IoCompletionThreadPool_h
00027 #define OW32_IoCompletionThreadPool_h
00028
00029 #include <OW32/OW32Libs.h>
00030 #include <OW32/IoCompletion.h>
00031 #include <OW32/Thread.h>
00032 #include <OW32/auto_array_ptr.h>
00033
00034 namespace OW32
00035 {
00036
00037 #ifdef _MSC_VER
00038 #pragma warning(disable: 4251)
00039 #endif
00040
00042 class OW32_LIB_EXPORT CIoCompletionThread :
00043 public CThread
00044 {
00045 public:
00047 CIoCompletionThread() :
00048 CThread(false)
00049 {
00050 }
00051
00057 void SetCompletionPort(HANDLE hCompletionPort) { m_hCompletionPort = hCompletionPort; }
00058
00060 virtual unsigned int Run();
00061
00062 private:
00063 HANDLE m_hCompletionPort;
00064 };
00065
00067 class OW32_LIB_EXPORT CIoCompletionThreadPool
00068 {
00069 public:
00076 CIoCompletionThreadPool(HANDLE hExistingCompletionPort = NULL, bool fCloseCompletionPort = false) :
00077 m_hCompletionPort(hExistingCompletionPort),
00078 m_fCloseCompletionPort(fCloseCompletionPort),
00079 m_bCreated(FALSE),
00080 m_nWorkers(0)
00081 {
00082 }
00083
00092 BOOL Create(DWORD threads, DWORD concurrentThreads = 0, int priority = THREAD_PRIORITY_NORMAL);
00093
00099 BOOL Destroy();
00100
00104 operator HANDLE() const { return m_hCompletionPort; }
00105
00111 HANDLE GetCompletionPort() const { return m_hCompletionPort; }
00112
00122 void SetCompletionPort(HANDLE hCompletionPort, bool fCloseCompletionPort = false) {
00123 m_hCompletionPort = hCompletionPort;
00124 m_fCloseCompletionPort = fCloseCompletionPort;
00125 }
00126
00127 private:
00129 CIoCompletionThreadPool operator= (const CIoCompletionThreadPool &rhs);
00130 CIoCompletionThreadPool(const CIoCompletionThreadPool &other);
00131
00133 bool m_fCloseCompletionPort;
00134
00136 HANDLE m_hCompletionPort;
00137
00139 BOOL m_bCreated;
00140
00142 DWORD m_nWorkers;
00144 auto_array_ptr<CIoCompletionThread> m_Workers;
00145 };
00146
00147 #ifdef _MSC_VER
00148 #pragma warning(default: 4251)
00149 #endif
00150
00151 }
00152
00153 #endif // OW32_IoCompletionThreadPool_h