00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __GZ_DIST_CLIENT_THREAD_POOL_H__
00022 #define __GZ_DIST_CLIENT_THREAD_POOL_H__
00023
00029
00030 #include "gzDistBase.h"
00031
00032
00033 class gzDistClientThread;
00034 class gzDistClientInterface;
00035
00036
00037
00038 class gzDistThreadInterface
00039 {
00040 public:
00041 gzDistThreadInterface() : m_threadId(0){}
00042 virtual ~gzDistThreadInterface() {}
00043
00044 gzVoid trigger();
00045
00046 gzULong getThreadId();
00047
00048 protected:
00049
00050
00051 gzDistTrigger m_trigger;
00052
00053
00054 gzULong m_threadId;
00055 };
00056
00057
00058
00059
00060 class gzDistClientThreadPool : public gzDistThreadInterface
00061 {
00062 public:
00063
00064 gzDistClientThreadPool();
00065 ~gzDistClientThreadPool();
00066
00067 gzDistThreadInterface* registerClient(gzDistClientInterface* client, gzULong poolId, gzULong threadId);
00068 gzBool unregisterClient(gzDistClientInterface* client, gzULong poolId, gzULong threadId);
00069 gzVoid shutDown();
00070
00071
00072 gzBool isActive();
00073
00074 gzBool processCustomThreadClients(gzBool waitForTrigger);
00075
00076 gzULong getCustomThreadId();
00077
00078
00079 gzBool processPool();
00080
00081 protected:
00082
00083 private:
00084
00085 gzDistClientThread* getThreadPool(gzULong poolId);
00086
00087 gzDistClientThread* getThreadPoolByThread(gzULong threadId);
00088
00089
00090
00091 gzList<gzDistClientThread> m_threadPool;
00092
00093
00094 gzList<gzDistClientInterface> m_customClients;
00095
00096
00097 gzMutex m_customClientsLocker;
00098
00099
00100 gzBool m_doReset;
00101 };
00102
00103
00104
00105
00106
00107 class gzDistClientThread : public gzThread, public gzDistThreadInterface
00108 {
00109 public:
00110
00111 gzDistClientThread(gzULong poolId);
00112 virtual ~gzDistClientThread();
00113
00114
00115 gzBool addClient(gzDistClientInterface* client);
00116
00117
00118 gzBool addClientUnlocked(gzDistClientInterface* client);
00119
00120
00121 gzBool removeClient(gzDistClientInterface* client);
00122
00123
00124 gzBool removeClientUnlocked(gzDistClientInterface* client);
00125
00126
00127 gzUInt getClients();
00128
00129
00130 gzVoid activate();
00131
00132
00133 gzVoid terminate();
00134
00135 gzULong getPoolId();
00136
00137 gzULong getPoolThreadId();
00138
00139 gzVoid singleProcess();
00140
00141 protected:
00142
00143 gzVoid process();
00144
00145 private:
00146
00147 gzList<gzDistClientInterface> m_clients;
00148 gzMutex m_clientsLocker;
00149
00150
00151 const gzULong m_poolId;
00152
00153
00154 gzBool m_running;
00155
00156
00157 gzBool m_doReset;
00158 };
00159
00160
00161 #endif