Addons updated to new doc format
[io.git] / addons / Thread / source / Thread.h
blobed83a748d1e662be6b7cfbaf2dc99713c7c2a65e
1 /*
2 copyright
3 Trevor Fancher, 2006
4 license
5 BSD revised
6 */
9 #ifndef THREAD_DEFINED
10 #define THREAD_DEFINED 1
12 #include "Common.h"
13 #ifndef WIN32
14 # include <pthread.h>
15 # include <unistd.h>
16 #endif
17 #include "ThreadMutex.h"
18 #include "List.h"
20 typedef void *(*ThreadFunc)(void*);
22 enum ThreadReturnCode_
24 THREAD_SUCCESS = 0,
25 THREAD_FAILURE
27 typedef enum ThreadReturnCode_ ThreadReturnCode;
29 typedef struct Thread_ Thread;
30 struct Thread_
32 #ifdef WIN32
33 HANDLE thread;
34 DWORD id;
35 #else
36 pthread_t thread;
37 #endif
38 int active;
39 ThreadFunc func;
40 void *funcArg;
41 void *returnValue;
42 void *userData;
45 // --- class functions
46 ThreadReturnCode Thread_Init(void);
47 void Thread_Shutdown(void);
48 Thread * Thread_CurrentThread(void);
49 ThreadReturnCode Thread_WaitOnThread_(Thread *other);
50 List * Thread_Threads(void);
52 // --- constructors
53 Thread * Thread_new(void);
54 Thread * Thread_newWithFunc_arg_(ThreadFunc func, void *funcArg);
56 // --- destructor
57 void Thread_destroy(Thread* self);
59 // --- member functions
60 // -- getter functions
61 ThreadFunc Thread_func(Thread *self);
62 void * Thread_funcArg(Thread *self);
63 void * Thread_userData(Thread *self);
65 // -- setter functions
66 void Thread_setFunc_(Thread *self, ThreadFunc func);
67 void Thread_setFuncArg_(Thread *self, void *funcArg);
68 void Thread_setFunc_arg_(Thread *self, ThreadFunc, void *funcArg);
69 void Thread_setUserData_(Thread *self, void *userData);
71 // -- operational functions
72 ThreadReturnCode Thread_start(Thread *self);
73 ThreadReturnCode Thread_stop(Thread *self);
74 void Thread_exitWithValue_(Thread *self, void *returnValue);
76 #endif