Alex Bikfalvi
SimStream Documentation
SimWorker.h
00001 #pragma once 00002 00003 #include "SimWorkItem.h" 00004 00005 class CSimWorker 00006 { 00007 public: 00008 enum EWorkerState 00009 { 00010 WORKER_STATE_STOPPED = 0, 00011 WORKER_STATE_STARTING = 1, 00012 WORKER_STATE_STARTED_IDLE = 2, 00013 WORKER_STATE_STARTED_BUSY = 3, 00014 WORKER_STATE_STOPPING = 4 00015 }; 00016 00017 private: 00018 unsigned int id; 00019 EWorkerState state; 00020 00021 unsigned int queueSize; 00022 unsigned int queueCount; 00023 unsigned int queuePtr; 00024 CSimWorkItem** queue; 00025 00026 #ifdef WIN32 00027 HANDLE threadHandle; // Thread handle 00028 DWORD threadId; // Thread id 00029 CRITICAL_SECTION threadMutex; // Thread mutex : used to synchronize shared variables with the worker thread 00030 00031 HANDLE stateHandle; // State event handle 00032 HANDLE workHandle; // Work event handle 00033 #elif POSIX 00034 pthread_t threadHandle; // Thread handle 00035 pthread_mutex_t threadMutex; // Thread mutex 00036 00037 pthread_cond_t stateCond; // State condition 00038 pthread_mutex_t stateMutex; // State mutex 00039 00040 pthread_cond_t workCond; // Work condition 00041 pthread_mutex_t workMutex; // Work mutex 00042 #endif 00043 00044 public: 00045 CSimWorker( 00046 unsigned int id, 00047 unsigned int queueSize 00048 ); 00049 ~CSimWorker(); 00050 00051 void Start(); 00052 void Stop(); 00053 00054 void Enqueue(CSimWorkItem* item); 00055 00056 private: 00057 00058 #ifdef WIN32 00059 static DWORD WINAPI Execute(__in LPVOID parameter); 00060 #else 00061 static void* Execute(void* parameter); 00062 #endif 00063 };
Last updated: February 8, 2011