Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

IoCompletionThreadPool.h

Go to the documentation of this file.
00001 /*  IoCompletionThreadPool.h - Io Completion Port thread pool
00002     Copyright (C) 2001-2004 Mark Weaver
00003     Written by Mark Weaver <mark@npsl.co.uk>
00004 
00005     Part of the Open-Win32 library.
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public
00017     License along with this library; if not, write to the
00018     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019     Boston, MA  02111-1307, USA.
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 } // namespace OW32
00152 
00153 #endif // OW32_IoCompletionThreadPool_h

Generated on Sun Jun 5 01:29:17 2005 for OW32 by  doxygen 1.3.9.1