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

# deThread_priv.hpp

Go to the documentation of this file.

    00001 #ifndef DETHREAD_PRIV_HPP
    00002 #define DETHREAD_PRIV_HPP
    00003
    00004 #include "deThread.hpp"
    00005 #include "deList.hpp"
    00006
    00007 #ifdef DESTINY3D_PLATFORM_WIN32
    00008 #include <windows.h>
    00009
    00010 class deThread : public IdeThread {
    00011 public:
    00012     deThread(ThreadProc threadProc);
    00013     virtual ~deThread();
    00014     virtual deBoolean Start(void* parameter);
    00015     virtual deBoolean IsRunning();
    00016     virtual u32 GetReturnValue(deBoolean WaitForExit);
    00017     virtual s32 Release();
    00018     void Join(MessageHandler mh);
    00019     void DoMessageJoin(MessageHandler mh);
    00020     void DoWaitJoin();
    00021 protected:
    00022 private:
    00023     ThreadProc  mThreadProc;
    00024     HANDLE      mThreadHandle;
    00025     DWORD       mThreadId;
    00026 };
    00027
    00028 class deThreadLock : public IdeThreadLock {
    00029 public:
    00030     deThreadLock(u32 spinCount);
    00031     virtual ~deThreadLock();
    00032     virtual void Lock();
    00033     virtual void Unlock();
    00034     virtual deBoolean TryLock(u32 waitTimeInMs);
    00035     virtual s32 Release();
    00036 private:
    00037     HANDLE      mLockEvent;
    00038     LONG        mThreadId;
    00039     s32         mCount;
    00040     s32         mDepth;
    00041     u32 const   mSpinCount;
    00042     void operator=(const deThreadLock&) {}
    00043 };
    00044
    00045 class deThreadPool : public IdeThreadPool {
    00046 public:
    00047     deThreadPool(u32 minStartThreadCount);
    00048     virtual void QueueUserWorkItem(IdeThread::ThreadProc, void* parameter);
    00049     virtual u32 GetAvailableThreadCount();
    00050     virtual u32 GetCurrentThreadCount();
    00051     virtual void RemoveUnusedThreads();
    00052     virtual ~deThreadPool();
    00053     static deThreadPool* mInstance;
    00054 private:
    00055     struct ThreadPoolItem {
    00056         IdeThread* thread;
    00057         IdeThread::ThreadProc workerFunction;
    00058         HANDLE workAvailableSignal;
    00059         HANDLE doneSignal;
    00060         void* param;
    00061     };
    00062     typedef deTList<ThreadPoolItem*>::iterator ThreadPoolIterator;
    00063     ThreadPoolItem* GetAvailableThread();
    00064     ThreadPoolItem* CreateNewThread();
    00065     bool IsThreadAvailable(ThreadPoolItem* item);
    00066     void RemoveThread(ThreadPoolItem* item);
    00067
    00068     deTList<ThreadPoolItem*> mThreads;
    00069     IdeThreadLock* mLock;
    00070
    00071     static u32 ThreadPoolWorkerThreadFunc(void* parameter);
    00072 };
    00073
    00074 #elif defined(DESTINY3D_PLATFORM_LINUX)
    00075 #error linux threading system not yet implemented
    00076 #else
    00077 #error unsupported platform configuration
    00078 #endif
    00079
    00080 #endif //DETHREAD_PRIV_HPP