36 #include <sys/types.h>
41 #define MULTI_THREADED TRUE
42 #define SINGLE_THREADED FALSE
43 #define AGENTPP_DEFAULT_STACKSIZE 0x10000
45 #ifdef AGENTPP_NAMESPACE
68 called_class(c), method(m), req(r) {
88 #define TS_SYNCHRONIZED(x) { ThreadSynchronize _ts_synchronize(*this); x }
93 #error "This SYSTEM does not support threads. Undefine _THREADS in agent++.h"
132 virtual void run() = 0;
167 bool wait(
unsigned long timeout);
200 TryLockResult trylock();
219 int cond_timed_wait(
const timespec*);
221 pthread_mutex_t monitor;
269 void wait (
long timeout)
270 {
if (timeout<0) sync.wait();
else sync.wait(timeout);}
302 enum ThreadStatus { IDLE, RUNNING, FINISHED };
306 friend DWORD thread_starter(LPDWORD lpdwParam);
308 friend void* thread_starter(
void*);
337 static void sleep(
long millis);
349 static void sleep(
long millis,
int nanos);
414 HANDLE threadEndEvent;
418 static void nsleep(
int secs,
long nanos);
429 #if !defined (AGENTPP_DECL_TEMPL_ARRAY_THREAD)
430 #define AGENTPP_DECL_TEMPL_ARRAY_THREAD
441 int size()
const {
return list.size(); }
451 #ifdef AGENTPP_USE_THREAD_POOL
453 #if !defined (AGENTPP_DECL_TEMPL_ARRAY_TASKMANAGER)
454 #define AGENTPP_DECL_TEMPL_ARRAY_TASKMANAGER
478 ThreadPool(
int size = 4);
491 ThreadPool(
int size,
int stackSize);
496 virtual ~ThreadPool();
528 unsigned int size() {
return taskList.
size(); }
536 int stack_size() {
return stackSize; }
553 #if !defined (AGENTPP_DECL_TEMPL_LIST_RUNNABLE)
554 #define AGENTPP_DECL_TEMPL_LIST_RUNNABLE
584 QueuedThreadPool(
int size = 4);
597 QueuedThreadPool(
int size,
int stackSize);
602 virtual ~QueuedThreadPool();
616 unsigned int queue_length() {
return queue.
size(); }
627 void stop() { go =
FALSE; }
632 virtual void idle_notification();
657 TaskManager(ThreadPool*,
663 virtual ~TaskManager();
673 bool is_idle() {
return (!task); }
678 void start() { thread.start(); }
683 void stop() { go =
FALSE; }
702 {
return new TaskManager(
703 new ThreadPool(threadPool->size(), threadPool->stack_size()));}
707 ThreadPool* threadPool;
713 #endif // AGENTPP_USE_THREAD_POOL
732 #ifdef NO_FAST_MUTEXES
768 #if !defined (AGENTPP_DECL_TEMPL_LIST_LOCKREQUEST)
769 #define AGENTPP_DECL_TEMPL_LIST_LOCKREQUEST
776 virtual ~LockQueue();
787 void acquire(LockRequest*);
797 void release(LockRequest*);
846 static void start_global_synch();
850 static void end_global_synch();
875 #ifdef AGENTPP_NAMESPACE