Main Page Modules Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# deThreadPool.hpp

Go to the documentation of this file.

    00001 ///////////////////////////////////////////////////////////////////////////////
    00002 /// @file deThreadPool.hpp
    00003 ///
    00004 /// @brief
    00005 ///
    00006 /// @author trajar
    00007 ///
    00008 /// This file is the intellectual property of Novus Delta, LLC.. Usage of the
    00009 /// contents of this file is subject to the Destiny3D Member License which
    00010 /// can be found at http://www.destiny3d.com.  Any other usage is prohibited.
    00011 ///
    00012 /// This file is distributed "AS IS" without warranty of any kind.  Novus
    00013 /// Delta, LLC. does not guarantee the fitness of the contents of this file
    00014 /// for any particular purpose.
    00015 ///
    00016 /// Copyright (C) 2001-2003 Novus Delta, LLC. All Rights Reserved.
    00017 ///
    00018 /// <hr>
    00019 ///                                 Change History
    00020 /// <hr>
    00021 ///
    00022 /// @date Jun 2002
    00023 /// @author trajar
    00024 /// @remarks Creation
    00025 ///
    00026 ///////////////////////////////////////////////////////////////////////////////
    00027
    00028 #ifndef _DETHREADPOOL_HPP
    00029 #define _DETHREADPOOL_HPP
    00030
    00031 #ifndef     _DENET_HPP
    00032  #include   "deNet.hpp"
    00033 #endif
    00034
    00035 #ifndef     _DETHREAD_HPP
    00036  #include   "deThread.hpp"
    00037 #endif
    00038
    00039 #ifndef     _DESYNCHOBJECT_HPP
    00040  #include   "deSynchObject.hpp"
    00041 #endif
    00042
    00043 #include    <VECTOR>
    00044 #include    <STACK>
    00045 #include    <QUEUE>
    00046
    00047 class DENET_API deThreadPool
    00048 {
    00049 public:
    00050
    00051     deThreadPool(void);
    00052     virtual ~deThreadPool(void);
    00053
    00054     bool        CreateThreads( int iNum );
    00055     deThread *  ActivateIdleThread( deThread::ActiveProcess process, void * param, DWORD paramSize, DWORD dwDesc = NULL, bool bCreateThread = false );
    00056     int         ActivateQueuedJobs( int iNumCreatedThreads = 0 );
    00057     bool        DestroyAllThreads( bool bForceKill = false );
    00058
    00059     DWORD   GetNumActiveThreads(void);
    00060     DWORD   GetNumIdleThreads(void);
    00061
    00062     // function called by deThread when going to STATUS_SLEEP
    00063     bool    NotifyOnIdle( deThread * pThread );
    00064
    00065     static  deThreadPool * GetMgr(void)     { return m_Singleton; }
    00066
    00067 protected:
    00068
    00069     class JobDesc
    00070     {
    00071     public:
    00072
    00073         JobDesc(void)   : m_pProcessData(NULL)      { }
    00074         ~JobDesc(void)                              { SAFE_DELETE_ARRAY(m_pProcessData); }
    00075
    00076         enum Flags
    00077         {
    00078             JOB_KILL_THREAD_ON_COMPLETION   = 0x0001,
    00079         };
    00080
    00081         deThread *                  m_pThread;
    00082         deThread::ActiveProcess     m_pProcess;
    00083         BYTE     *                  m_pProcessData;
    00084         DWORD                       m_dwDesc;
    00085     };
    00086
    00087     typedef     std::stack<deThread*>   stackThreads;
    00088     typedef     std::vector<JobDesc*>   aJobs;
    00089     typedef     std::queue<JobDesc*>    queueJobs;
    00090
    00091     queueJobs       m_queWaitingJobs;
    00092     stackThreads    m_stkIdleThreads;
    00093     aJobs           m_aActiveJobs;
    00094     deSynchObject   m_SynchObject;
    00095
    00096     static deThreadPool * m_Singleton;
    00097 };
    00098
    00099 #endif