00001
00002 #ifndef CPTHREADS_H
00003 #define CPTHREADS_H
00004
00005 #include <converse.h>
00006
00007 #include <sys/types.h>
00008
00009 #ifdef __cplusplus
00010 extern "C" {
00011 #endif
00012
00013 #define CPTHREAD_THREADS_MAX 1000000000
00014 #define CPTHREAD_KEYS_MAX 1000000000
00015 #define CPTHREAD_STACK_MIN 32768
00016 #define CPTHREAD_CREATE_DETACHED 1
00017 #define CPTHREAD_CREATE_JOINABLE 0
00018
00019 struct Cpthread_attr_s
00020 {
00021 int magic;
00022 int detached;
00023 int stacksize;
00024 };
00025
00026 struct Cpthread_mutexattr_s
00027 {
00028 int magic;
00029 int pshared;
00030 };
00031
00032 struct Cpthread_mutex_s
00033 {
00034 int magic;
00035 int onpe;
00036 void *users;
00037 };
00038
00039 struct Cpthread_condattr_s
00040 {
00041 int magic;
00042 int pshared;
00043 };
00044
00045 struct Cpthread_cond_s
00046 {
00047 int magic;
00048 int onpe;
00049 void *users;
00050 };
00051
00052 typedef struct { int flag[32]; } Cpthread_once_t;
00053
00054 #define CPTHREAD_ONCE_INIT {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
00055
00056 typedef struct Cpthread_attr_s Cpthread_attr_t;
00057 typedef struct Cpthread_key_s *Cpthread_key_t;
00058 typedef struct Cpthread_cleanup_s *Cpthread_cleanup_t;
00059 typedef struct Cpthread_mutexattr_s Cpthread_mutexattr_t;
00060 typedef struct Cpthread_condattr_s Cpthread_condattr_t;
00061 typedef struct Cpthread_mutex_s Cpthread_mutex_t;
00062 typedef struct Cpthread_cond_s Cpthread_cond_t;
00063 typedef struct Cpthread_s *Cpthread_t;
00064
00065 #ifdef CPTHREAD_IS_HERE
00066 CtvDeclare(Cpthread_t, Cpthread_current);
00067 CtvDeclare(int, Cpthread_errcode);
00068 #else
00069 CtvExtern(Cpthread_t, Cpthread_current);
00070 CtvExtern(int, Cpthread_errcode);
00071 #endif
00072
00073 #define Cpthread_self() (CtvAccess(Cpthread_current))
00074 #define Cpthread_errno (CtvAccess(Cpthread_errcode))
00075
00076 int Cpthread_attr_init(Cpthread_attr_t *attr);
00077 int Cpthread_attr_destroy(Cpthread_attr_t *attr);
00078 int Cpthread_attr_getstacksize(Cpthread_attr_t *attr, size_t *size);
00079 int Cpthread_attr_setstacksize(Cpthread_attr_t *attr, size_t size);
00080 int Cpthread_attr_getdetachstate(Cpthread_attr_t *attr, int *state);
00081 int Cpthread_attr_setdetachstate(Cpthread_attr_t *attr, int state);
00082 int Cpthread_key_create(Cpthread_key_t *keyp, void (*destructo)(void *));
00083 int Cpthread_key_delete(Cpthread_key_t key);
00084 int Cpthread_setspecific(Cpthread_key_t key, void *val);
00085 void *Cpthread_getspecific(Cpthread_key_t key);
00086 void Cpthread_cleanup_push(void (*routine)(void*), void *arg);
00087 void Cpthread_cleanup_pop(int execute);
00088 void Cpthread_exit(void *status);
00089 void Cpthread_top(Cpthread_t pt);
00090 int Cpthread_create(Cpthread_t *thread, Cpthread_attr_t *attr,
00091 void *(*fn)(void *), void *arg);
00092 int Cpthread_equal(Cpthread_t t1, Cpthread_t t2);
00093 int Cpthread_detach(Cpthread_t pt);
00094 int Cpthread_join(Cpthread_t pt, void **status);
00095 int Cpthread_mutexattr_init(Cpthread_mutexattr_t *mattr);
00096 int Cpthread_mutexattr_destroy(Cpthread_mutexattr_t *mattr);
00097 int Cpthread_mutexattr_getpshared(Cpthread_mutexattr_t *mattr,int *pshared);
00098 int Cpthread_mutexattr_setpshared(Cpthread_mutexattr_t *mattr,int pshared);
00099 int Cpthread_mutex_init(Cpthread_mutex_t *mutex,Cpthread_mutexattr_t *mattr);
00100 int Cpthread_mutex_destroy(Cpthread_mutex_t *mutex);
00101 int Cpthread_mutex_lock(Cpthread_mutex_t *mutex);
00102 int Cpthread_mutex_trylock(Cpthread_mutex_t *mutex);
00103 int Cpthread_mutex_unlock(Cpthread_mutex_t *mutex);
00104 int Cpthread_condattr_init(Cpthread_condattr_t *cattr);
00105 int Cpthread_condattr_destroy(Cpthread_condattr_t *cattr);
00106 int Cpthread_condattr_getpshared(Cpthread_condattr_t *cattr, int *pshared);
00107 int Cpthread_condattr_setpshared(Cpthread_condattr_t *cattr, int pshared);
00108 int Cpthread_cond_init(Cpthread_cond_t *cond, Cpthread_condattr_t *cattr);
00109 int Cpthread_cond_destroy(Cpthread_cond_t *cond);
00110 int Cpthread_cond_wait(Cpthread_cond_t *cond, Cpthread_mutex_t *mutex);
00111 int Cpthread_cond_signal(Cpthread_cond_t *cond);
00112 int Cpthread_cond_broadcast(Cpthread_cond_t *cond);
00113 int Cpthread_once(Cpthread_once_t *once, void (*fn)(void));
00114
00115 int Cpthread_init(void);
00116
00117 void Cpthread_initialize(void);
00118 void Cpthread_start_main(CmiStartFn fn, int argc, char **argv);
00119
00120 #define Cpthread_yield() (CthYield())
00121
00122 #ifndef SUPPRESS_PTHREADS
00123
00124 #define _POSIX_THREADS
00125 #define _POSIX_THREAD_ATTR_STACKSIZE
00126
00127
00128
00129
00130
00131
00132 #define PTHREAD_THREADS_MAX CPTHREAD_THREADS_MAX
00133 #define PTHREAD_KEYS_MAX CPTHREAD_KEYS_MAX
00134 #define PTHREAD_STACK_MIN CPTHREAD_STACK_MIN
00135 #define PTHREAD_CREATE_DETACHED CPTHREAD_CREATE_DETACHED
00136 #define PTHREAD_CREATE_JOINABLE CPTHREAD_CREATE_JOINABLE
00137
00138 #define PTHREAD_ONCE_INIT CPTHREAD_ONCE_INIT
00139
00140 #define pthread_once_t Cpthread_once_t
00141 #define pthread_attr_t Cpthread_attr_t
00142 #define pthread_key_t Cpthread_key_t
00143 #define pthread_cleanup_t Cpthread_cleanup_t
00144 #define pthread_mutexattr_t Cpthread_mutexattr_t
00145 #define pthread_condattr_t Cpthread_condattr_t
00146 #define pthread_mutex_t Cpthread_mutex_t
00147 #define pthread_cond_t Cpthread_cond_t
00148 #define pthread_t Cpthread_t
00149 #define pthread_attr_init Cpthread_attr_init
00150 #define pthread_attr_destroy Cpthread_attr_destroy
00151 #define pthread_attr_getstacksize Cpthread_attr_getstacksize
00152 #define pthread_attr_setstacksize Cpthread_attr_setstacksize
00153 #define pthread_attr_getdetachstate Cpthread_attr_getdetachstate
00154 #define pthread_attr_setdetachstate Cpthread_attr_setdetachstate
00155 #define pthread_key_create Cpthread_key_create
00156 #define pthread_key_delete Cpthread_key_delete
00157 #define pthread_setspecific Cpthread_setspecific
00158 #define pthread_getspecific Cpthread_getspecific
00159 #define pthread_cleanup_push Cpthread_cleanup_push
00160 #define pthread_cleanup_pop Cpthread_cleanup_pop
00161 #define pthread_exit Cpthread_exit
00162 #define pthread_top Cpthread_top
00163 #define pthread_create Cpthread_create
00164 #define pthread_equal Cpthread_equal
00165 #define pthread_self Cpthread_self
00166 #define pthread_detach Cpthread_detach
00167 #define pthread_join Cpthread_join
00168 #define pthread_mutexattr_init Cpthread_mutexattr_init
00169 #define pthread_mutexattr_destroy Cpthread_mutexattr_destroy
00170 #define pthread_mutexattr_getpshared Cpthread_mutexattr_getpshared
00171 #define pthread_mutexattr_setpshared Cpthread_mutexattr_setpshared
00172 #define pthread_mutex_init Cpthread_mutex_init
00173 #define pthread_mutex_destroy Cpthread_mutex_destroy
00174 #define pthread_mutex_lock Cpthread_mutex_lock
00175 #define pthread_mutex_trylock Cpthread_mutex_trylock
00176 #define pthread_mutex_unlock Cpthread_mutex_unlock
00177 #define pthread_condattr_init Cpthread_condattr_init
00178 #define pthread_condattr_destroy Cpthread_condattr_destroy
00179 #define pthread_condattr_getpshared Cpthread_condattr_getpshared
00180 #define pthread_condattr_setpshared Cpthread_condattr_setpshared
00181 #define pthread_cond_init Cpthread_cond_init
00182 #define pthread_cond_destroy Cpthread_cond_destroy
00183 #define pthread_cond_wait Cpthread_cond_wait
00184 #define pthread_cond_signal Cpthread_cond_signal
00185 #define pthread_cond_broadcast Cpthread_cond_broadcast
00186 #define pthread_once Cpthread_once
00187 #define pthread_init Cpthread_init
00188
00189 #define pthread_yield (CthYield())
00190
00191 #endif
00192
00193 #ifdef __cplusplus
00194 }
00195 #endif
00196
00197 #endif
00198