| 1 | //
 | 
|---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2019 University of Waterloo
 | 
|---|
| 3 | //
 | 
|---|
| 4 | // The contents of this file are covered under the licence agreement in the
 | 
|---|
| 5 | // file "LICENCE" distributed with Cforall.
 | 
|---|
| 6 | //
 | 
|---|
| 7 | // pthread.cfa --
 | 
|---|
| 8 | //
 | 
|---|
| 9 | // Author           : Zhenyan Zhu
 | 
|---|
| 10 | // Created On       : Sat Aug 6 16:29:18 2022
 | 
|---|
| 11 | // Last Modified By : Peter A. Buhr
 | 
|---|
| 12 | // Last Modified On : Fri Apr 25 07:28:01 2025
 | 
|---|
| 13 | // Update Count     : 4
 | 
|---|
| 14 | //
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #define __cforall_thread__
 | 
|---|
| 17 | 
 | 
|---|
| 18 | #include <signal.h>
 | 
|---|
| 19 | #include <pthread.h>
 | 
|---|
| 20 | #include <errno.h>
 | 
|---|
| 21 | #include "locks.hfa"
 | 
|---|
| 22 | 
 | 
|---|
| 23 | #define check_nonnull(x) asm("": "+rm"(x)); if( x == 0p ) return EINVAL;
 | 
|---|
| 24 | 
 | 
|---|
| 25 | /* pthread key, pthread once inner routine mutual exclusion */
 | 
|---|
| 26 | static simple_owner_lock once_lock,key_lock,magic_mutex_check, concurrency_lock;
 | 
|---|
| 27 | 
 | 
|---|
| 28 | //######################### Local Storage Helpers #########################
 | 
|---|
| 29 | 
 | 
|---|
| 30 | enum { PTHREAD_KEYS_MAX = 1024 };
 | 
|---|
| 31 | 
 | 
|---|
| 32 | struct pthread_values{
 | 
|---|
| 33 |         inline dlink(pthread_values);
 | 
|---|
| 34 |         void * value;
 | 
|---|
| 35 |         bool in_use;
 | 
|---|
| 36 | };
 | 
|---|
| 37 | P9_EMBEDDED( pthread_values, dlink(pthread_values) )
 | 
|---|
| 38 | 
 | 
|---|
| 39 | struct pthread_keys {
 | 
|---|
| 40 |         bool in_use;
 | 
|---|
| 41 |         void (* destructor)( void * );
 | 
|---|
| 42 |         dlist( pthread_values ) threads;
 | 
|---|
| 43 | };
 | 
|---|
| 44 | 
 | 
|---|
| 45 | static void ?{}(pthread_keys& k) {
 | 
|---|
| 46 |         k.threads{};
 | 
|---|
| 47 | }
 | 
|---|
| 48 | 
 | 
|---|
| 49 | // Create storage separately to ensure no constructors are called.
 | 
|---|
| 50 | static pthread_keys cfa_pthread_keys_storage[PTHREAD_KEYS_MAX] __attribute__((aligned (16)));
 | 
|---|
| 51 | 
 | 
|---|
| 52 | static void init_pthread_storage() {
 | 
|---|
| 53 |         for ( int i = 0; i < PTHREAD_KEYS_MAX; i++ ) {
 | 
|---|
| 54 |                 cfa_pthread_keys_storage[i]{};
 | 
|---|
| 55 |         }
 | 
|---|
| 56 | }
 | 
|---|
| 57 | 
 | 
|---|
| 58 | #define cfa_pthread_keys ((pthread_keys *)cfa_pthread_keys_storage)
 | 
|---|
| 59 | 
 | 
|---|
| 60 | /* Controlling the iterations of destructors for thread-specific data.  */
 | 
|---|
| 61 | #define _POSIX_THREAD_DESTRUCTOR_ITERATIONS     4
 | 
|---|
| 62 | /* Number of iterations this implementation does.  */
 | 
|---|
| 63 | #define PTHREAD_DESTRUCTOR_ITERATIONS   _POSIX_THREAD_DESTRUCTOR_ITERATIONS
 | 
|---|
| 64 | 
 | 
|---|
| 65 | //######################### Parallelism Helpers #########################
 | 
|---|
| 66 | 
 | 
|---|
| 67 | struct Pthread_kernel_threads{
 | 
|---|
| 68 |         inline dlink(Pthread_kernel_threads);
 | 
|---|
| 69 |         processor p;
 | 
|---|
| 70 | };
 | 
|---|
| 71 | P9_EMBEDDED( Pthread_kernel_threads, dlink(Pthread_kernel_threads) )
 | 
|---|
| 72 | 
 | 
|---|
| 73 | static dlist(Pthread_kernel_threads) cfa_pthreads_kernel_threads;
 | 
|---|
| 74 | static bool cfa_pthreads_kernel_threads_zero = false;   // set to zero ?
 | 
|---|
| 75 | static int cfa_pthreads_no_kernel_threads = 1;  // number of kernel threads
 | 
|---|
| 76 | 
 | 
|---|
| 77 | 
 | 
|---|
| 78 | //######################### Cond Helpers #########################
 | 
|---|
| 79 | 
 | 
|---|
| 80 | typedef pthread_cond_var(simple_owner_lock) cfa2pthr_cond_var_t;
 | 
|---|
| 81 | 
 | 
|---|
| 82 | /* condvar helper routines */
 | 
|---|
| 83 | static void init(pthread_cond_t * pcond) {
 | 
|---|
| 84 |         static_assert(sizeof(pthread_cond_t) >= sizeof(cfa2pthr_cond_var_t),"sizeof(pthread_t) < sizeof(cfa2pthr_cond_var_t)");
 | 
|---|
| 85 |         cfa2pthr_cond_var_t * _cond = (cfa2pthr_cond_var_t *)pcond;
 | 
|---|
| 86 |         ?{}(*_cond);
 | 
|---|
| 87 | }
 | 
|---|
| 88 | 
 | 
|---|
| 89 | static cfa2pthr_cond_var_t * get(pthread_cond_t * pcond) {
 | 
|---|
| 90 |         static_assert(sizeof(pthread_cond_t) >= sizeof(cfa2pthr_cond_var_t),"sizeof(pthread_t) < sizeof(cfa2pthr_cond_var_t)");
 | 
|---|
| 91 |         return (cfa2pthr_cond_var_t *)pcond;
 | 
|---|
| 92 | }
 | 
|---|
| 93 | 
 | 
|---|
| 94 | static void destroy(pthread_cond_t * cond) {
 | 
|---|
| 95 |         static_assert(sizeof(pthread_cond_t) >= sizeof(cfa2pthr_cond_var_t),"sizeof(pthread_t) < sizeof(cfa2pthr_cond_var_t)");
 | 
|---|
| 96 |         ^?{}(*get(cond));
 | 
|---|
| 97 | }
 | 
|---|
| 98 | 
 | 
|---|
| 99 | 
 | 
|---|
| 100 | //######################### Mutex Helper #########################
 | 
|---|
| 101 | 
 | 
|---|
| 102 | /* mutex helper routines */
 | 
|---|
| 103 | static void mutex_check(pthread_mutex_t * t) {
 | 
|---|
| 104 |         // Use double check to improve performance.
 | 
|---|
| 105 |         // Check is safe on x86; volatile prevents compiler reordering
 | 
|---|
| 106 |         volatile pthread_mutex_t * const mutex_ = t;
 | 
|---|
| 107 | 
 | 
|---|
| 108 |         // SKULLDUGGERY: not a portable way to access the kind field, /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h
 | 
|---|
| 109 |         int _lock_val = ((pthread_mutex_t *)mutex_)->__data.__lock;
 | 
|---|
| 110 | 
 | 
|---|
| 111 |         // if pthread_mutex_t is initialized by PTHREAD_MUTEX_INITIALIZER, _lock_val should be 0
 | 
|---|
| 112 |         if ( _lock_val == 0 ) {
 | 
|---|
| 113 |                 lock(magic_mutex_check);
 | 
|---|
| 114 |                 _lock_val = ((pthread_mutex_t *)mutex_)->__data.__lock;
 | 
|---|
| 115 |                 if ( _lock_val == 0 ) {
 | 
|---|
| 116 |                         pthread_mutex_init( t, NULL );
 | 
|---|
| 117 |                 }
 | 
|---|
| 118 |                 unlock(magic_mutex_check);
 | 
|---|
| 119 |         }
 | 
|---|
| 120 | } // mutex_check
 | 
|---|
| 121 | 
 | 
|---|
| 122 | 
 | 
|---|
| 123 | static void init(pthread_mutex_t * plock) {
 | 
|---|
| 124 |         static_assert(sizeof(pthread_mutex_t) >= sizeof(simple_owner_lock),"sizeof(pthread_mutex_t) < sizeof(simple_owner_lock)");
 | 
|---|
| 125 |         simple_owner_lock * _lock = (simple_owner_lock *)plock;
 | 
|---|
| 126 |         ?{}(*_lock);
 | 
|---|
| 127 | }
 | 
|---|
| 128 | 
 | 
|---|
| 129 | static simple_owner_lock * get(pthread_mutex_t * plock) {
 | 
|---|
| 130 |         static_assert(sizeof(pthread_mutex_t) >= sizeof(simple_owner_lock),"sizeof(pthread_mutex_t) < sizeof(simple_owner_lock)");
 | 
|---|
| 131 |         return (simple_owner_lock *)plock;
 | 
|---|
| 132 | }
 | 
|---|
| 133 | 
 | 
|---|
| 134 | static void destroy(pthread_mutex_t * plock) {
 | 
|---|
| 135 |         static_assert(sizeof(pthread_mutex_t) >= sizeof(simple_owner_lock),"sizeof(pthread_mutex_t) < sizeof(simple_owner_lock)");
 | 
|---|
| 136 |         ^?{}(*get(plock));
 | 
|---|
| 137 | }
 | 
|---|
| 138 | 
 | 
|---|
| 139 | //######################### Attr helpers #########################
 | 
|---|
| 140 | typedef struct cfaPthread_attr_t {                                              // thread attributes
 | 
|---|
| 141 |                 int contentionscope;
 | 
|---|
| 142 |                 int detachstate;
 | 
|---|
| 143 |                 size_t stacksize;
 | 
|---|
| 144 |                 void * stackaddr;
 | 
|---|
| 145 |                 int policy;
 | 
|---|
| 146 |                 int inheritsched;
 | 
|---|
| 147 |                 struct sched_param param;
 | 
|---|
| 148 | } cfaPthread_attr_t;
 | 
|---|
| 149 | 
 | 
|---|
| 150 | static const cfaPthread_attr_t default_attrs {
 | 
|---|
| 151 |         0,
 | 
|---|
| 152 |         0,
 | 
|---|
| 153 |         65_000,
 | 
|---|
| 154 |         NULL,
 | 
|---|
| 155 |         0,
 | 
|---|
| 156 |         0,
 | 
|---|
| 157 |         {0}
 | 
|---|
| 158 | };
 | 
|---|
| 159 | 
 | 
|---|
| 160 | static cfaPthread_attr_t * get(const pthread_attr_t * attr) {
 | 
|---|
| 161 |         static_assert(sizeof(pthread_attr_t) >= sizeof(cfaPthread_attr_t), "sizeof(pthread_attr_t) < sizeof(cfaPthread_attr_t)");
 | 
|---|
| 162 |         return (cfaPthread_attr_t *)attr;
 | 
|---|
| 163 | }
 | 
|---|
| 164 | 
 | 
|---|
| 165 | 
 | 
|---|
| 166 | //######################### Threads Helper #########################
 | 
|---|
| 167 | 
 | 
|---|
| 168 | // exception for cancel_stack in pthread_exit
 | 
|---|
| 169 | exception pthread_exit_exp {};
 | 
|---|
| 170 | static vtable(pthread_exit_exp) exp_vt;
 | 
|---|
| 171 | 
 | 
|---|
| 172 | thread cfaPthread{
 | 
|---|
| 173 |         cfaPthread_attr_t attr;
 | 
|---|
| 174 |         pthread_t pthreadId;
 | 
|---|
| 175 | 
 | 
|---|
| 176 |         // pthreads return value
 | 
|---|
| 177 |         void * joinval;
 | 
|---|
| 178 | 
 | 
|---|
| 179 |         // pthread attributes
 | 
|---|
| 180 |         pthread_attr_t pthread_attr;
 | 
|---|
| 181 | 
 | 
|---|
| 182 |         void *(* start_routine)(void *);
 | 
|---|
| 183 |         void * start_arg;
 | 
|---|
| 184 | 
 | 
|---|
| 185 |         // thread local data
 | 
|---|
| 186 |         pthread_values * pthreadData;
 | 
|---|
| 187 | 
 | 
|---|
| 188 |         // flag used for tryjoin
 | 
|---|
| 189 |         bool isTerminated;
 | 
|---|
| 190 | };
 | 
|---|
| 191 | 
 | 
|---|
| 192 | /* thread part routines */
 | 
|---|
| 193 | //  cfaPthread entry point
 | 
|---|
| 194 | void main(cfaPthread & _thread) with(_thread) {
 | 
|---|
| 195 |         joinval = start_routine(start_arg);
 | 
|---|
| 196 |         isTerminated = true;
 | 
|---|
| 197 | }
 | 
|---|
| 198 | 
 | 
|---|
| 199 | static cfaPthread * lookup( pthread_t p ) {
 | 
|---|
| 200 |         static_assert(sizeof(pthread_t) >= sizeof(cfaPthread *),"sizeof(pthread_t) < sizeof(cfaPthread *)");
 | 
|---|
| 201 |         return (cfaPthread *)p;
 | 
|---|
| 202 | }
 | 
|---|
| 203 | 
 | 
|---|
| 204 | static void pthread_deletespecific_( pthread_values * values )  { // see uMachContext::invokeTask
 | 
|---|
| 205 |         pthread_values * value;
 | 
|---|
| 206 |         pthread_keys * key;
 | 
|---|
| 207 |         bool destcalled = true;
 | 
|---|
| 208 |         if (values != NULL) {
 | 
|---|
| 209 |                 for ( int attempts = 0; attempts < PTHREAD_DESTRUCTOR_ITERATIONS && destcalled ; attempts += 1 ) {
 | 
|---|
| 210 |                         destcalled = false;
 | 
|---|
| 211 |                         lock(key_lock);
 | 
|---|
| 212 |                         for ( int i = 0; i < PTHREAD_KEYS_MAX; i++ ) {
 | 
|---|
| 213 |                                 // for each valid key
 | 
|---|
| 214 |                                 if ( values[i].in_use) {
 | 
|---|
| 215 |                                         value = &values[i];
 | 
|---|
| 216 |                                         key = &cfa_pthread_keys[i];
 | 
|---|
| 217 |                                         value->in_use = false;
 | 
|---|
| 218 |                                         remove(*value);
 | 
|---|
| 219 | 
 | 
|---|
| 220 |                                         // if  a  key  value  has  a  non-NULL  destructor pointer,  and  the  thread  has  a  non-NULL  value associated with that key,
 | 
|---|
| 221 |                                         // the value of the key is set to NULL, and then the function pointed to is called with the previously associated value as its sole argument.
 | 
|---|
| 222 |                                         if (value->value != NULL && key->destructor != NULL) {
 | 
|---|
| 223 |                                                 unlock(key_lock);
 | 
|---|
| 224 |                                                 key->destructor(value->value); // run destructor
 | 
|---|
| 225 |                                                 lock(key_lock);
 | 
|---|
| 226 |                                                 destcalled = true;
 | 
|---|
| 227 |                                         }   // if
 | 
|---|
| 228 |                                         value->value = NULL;
 | 
|---|
| 229 |                                 }   // if
 | 
|---|
| 230 |                         }   // for
 | 
|---|
| 231 |                         unlock(key_lock);
 | 
|---|
| 232 |                 }   // for
 | 
|---|
| 233 |                 free(values);
 | 
|---|
| 234 |         }   // if
 | 
|---|
| 235 | }
 | 
|---|
| 236 | 
 | 
|---|
| 237 | static void ^?{}(cfaPthread & mutex t) {
 | 
|---|
| 238 |         // delete pthread local storage
 | 
|---|
| 239 |         pthread_values * values = t.pthreadData;
 | 
|---|
| 240 |         pthread_deletespecific_(values);
 | 
|---|
| 241 | }
 | 
|---|
| 242 | 
 | 
|---|
| 243 | static void ?{}(cfaPthread & t, pthread_t * _thread, const pthread_attr_t * _attr,void *(* start_routine)(void *), void * arg) {
 | 
|---|
| 244 |         static_assert(sizeof(pthread_t) >= sizeof(cfaPthread *), "pthread_t too small to hold a pointer: sizeof(pthread_t) < sizeof(cfaPthread *)");
 | 
|---|
| 245 | 
 | 
|---|
| 246 |         // set up user thread stackSize
 | 
|---|
| 247 |         cfaPthread_attr_t * attr = get(_attr);
 | 
|---|
| 248 |         ((thread&)t){ attr ? attr->stacksize: DEFAULT_STACK_SIZE };
 | 
|---|
| 249 | 
 | 
|---|
| 250 |         // initialize _thread & cfaPthread id
 | 
|---|
| 251 |         *_thread = t.pthreadId = (pthread_t)(&t);
 | 
|---|
| 252 | 
 | 
|---|
| 253 |         // if attr null, self attr will be set as default_attrs; else set to attr
 | 
|---|
| 254 |         t.attr = (attr != NULL ? *attr : default_attrs);
 | 
|---|
| 255 | 
 | 
|---|
| 256 |         // init start routine and arguments
 | 
|---|
| 257 |         t.start_routine = start_routine;
 | 
|---|
| 258 |         t.start_arg = arg;
 | 
|---|
| 259 |         t.pthreadData = NULL;
 | 
|---|
| 260 | }
 | 
|---|
| 261 | 
 | 
|---|
| 262 | 
 | 
|---|
| 263 | extern "C"{
 | 
|---|
| 264 |         //######################### Pthread Attrs #########################
 | 
|---|
| 265 | 
 | 
|---|
| 266 |         int pthread_attr_init(pthread_attr_t * attr) libcfa_public __THROW {
 | 
|---|
| 267 |                 cfaPthread_attr_t * _attr = get(attr);
 | 
|---|
| 268 |                 ?{}(*_attr, default_attrs);
 | 
|---|
| 269 |                 return 0;
 | 
|---|
| 270 |         }
 | 
|---|
| 271 |         int pthread_attr_destroy(pthread_attr_t * attr) libcfa_public __THROW {
 | 
|---|
| 272 |                 ^?{}(*get(attr));
 | 
|---|
| 273 |                 return 0;
 | 
|---|
| 274 |         }
 | 
|---|
| 275 | 
 | 
|---|
| 276 |         int pthread_attr_setscope( pthread_attr_t * attr, int contentionscope ) libcfa_public __THROW {
 | 
|---|
| 277 |                 get( attr )->contentionscope = contentionscope;
 | 
|---|
| 278 |                 return 0;
 | 
|---|
| 279 |         } // pthread_attr_setscope
 | 
|---|
| 280 | 
 | 
|---|
| 281 |         int pthread_attr_getscope( const pthread_attr_t * attr, int * contentionscope ) libcfa_public __THROW {
 | 
|---|
| 282 |                 *contentionscope = get( attr )->contentionscope;
 | 
|---|
| 283 |                 return 0;
 | 
|---|
| 284 |         } // pthread_attr_getscope
 | 
|---|
| 285 | 
 | 
|---|
| 286 |         int pthread_attr_setdetachstate( pthread_attr_t * attr, int detachstate ) libcfa_public __THROW {
 | 
|---|
| 287 |                 get( attr )->detachstate = detachstate;
 | 
|---|
| 288 |                 return 0;
 | 
|---|
| 289 |         } // pthread_attr_setdetachstate
 | 
|---|
| 290 | 
 | 
|---|
| 291 |         int pthread_attr_getdetachstate( const pthread_attr_t * attr, int * detachstate ) libcfa_public __THROW {
 | 
|---|
| 292 |                 *detachstate = get( attr )->detachstate;
 | 
|---|
| 293 |                 return 0;
 | 
|---|
| 294 |         } // pthread_attr_getdetachstate
 | 
|---|
| 295 | 
 | 
|---|
| 296 |         int pthread_attr_setstacksize( pthread_attr_t * attr, size_t stacksize ) libcfa_public __THROW {
 | 
|---|
| 297 |                 get( attr )->stacksize = stacksize;
 | 
|---|
| 298 |                 return 0;
 | 
|---|
| 299 |         } // pthread_attr_setstacksize
 | 
|---|
| 300 | 
 | 
|---|
| 301 |         int pthread_attr_getstacksize( const pthread_attr_t * attr, size_t * stacksize ) libcfa_public __THROW {
 | 
|---|
| 302 |                 *stacksize = get( attr )->stacksize;
 | 
|---|
| 303 |                 return 0;
 | 
|---|
| 304 |         } // pthread_attr_getstacksize
 | 
|---|
| 305 | 
 | 
|---|
| 306 |         int pthread_attr_getguardsize( const pthread_attr_t * /* attr */, size_t * /* guardsize */ ) libcfa_public __THROW {
 | 
|---|
| 307 |                 return 0;
 | 
|---|
| 308 |         } // pthread_attr_getguardsize
 | 
|---|
| 309 | 
 | 
|---|
| 310 |         int pthread_attr_setguardsize( pthread_attr_t * /* attr */, size_t /* guardsize */ ) libcfa_public __THROW {
 | 
|---|
| 311 |                 return 0;
 | 
|---|
| 312 |         } // pthread_attr_setguardsize
 | 
|---|
| 313 | 
 | 
|---|
| 314 |         int pthread_attr_setstackaddr( pthread_attr_t * attr, void * stackaddr ) libcfa_public __THROW {
 | 
|---|
| 315 |                 get( attr )->stackaddr = stackaddr;
 | 
|---|
| 316 |                 return 0;
 | 
|---|
| 317 |         } // pthread_attr_setstackaddr
 | 
|---|
| 318 | 
 | 
|---|
| 319 |         int pthread_attr_getstackaddr( const pthread_attr_t * attr, void ** stackaddr ) libcfa_public __THROW {
 | 
|---|
| 320 |                 *stackaddr = get( attr )->stackaddr;
 | 
|---|
| 321 |                 return 0;
 | 
|---|
| 322 |         } // pthread_attr_getstackaddr
 | 
|---|
| 323 | 
 | 
|---|
| 324 |         int pthread_attr_setstack( pthread_attr_t * attr, void * stackaddr, size_t stacksize ) libcfa_public __THROW {
 | 
|---|
| 325 |                 get( attr )->stackaddr = stackaddr;
 | 
|---|
| 326 |                 get( attr )->stacksize = stacksize;
 | 
|---|
| 327 |                 return 0;
 | 
|---|
| 328 |         } // pthread_attr_setstack
 | 
|---|
| 329 | 
 | 
|---|
| 330 |         int pthread_attr_getstack( const pthread_attr_t * attr, void ** stackaddr, size_t * stacksize ) libcfa_public __THROW {
 | 
|---|
| 331 |                 *stackaddr = get( attr )->stackaddr;
 | 
|---|
| 332 |                 *stacksize = get( attr )->stacksize;
 | 
|---|
| 333 |                 return 0;
 | 
|---|
| 334 |         } // pthread_attr_getstack
 | 
|---|
| 335 | 
 | 
|---|
| 336 |         // Initialize thread attribute *attr with attributes corresponding to the
 | 
|---|
| 337 |         // already running thread threadID. It shall be called on unitialized attr
 | 
|---|
| 338 |         // and destroyed with pthread_attr_destroy when no longer needed.
 | 
|---|
| 339 |         int pthread_getattr_np( pthread_t threadID, pthread_attr_t * attr ) libcfa_public __THROW { // GNU extension
 | 
|---|
| 340 |                 check_nonnull(attr);
 | 
|---|
| 341 | 
 | 
|---|
| 342 |                 // copy all fields
 | 
|---|
| 343 |                 *get(attr) = lookup( threadID )->attr;
 | 
|---|
| 344 | 
 | 
|---|
| 345 |                 return 0;
 | 
|---|
| 346 |         } // pthread_getattr_np
 | 
|---|
| 347 | 
 | 
|---|
| 348 | 
 | 
|---|
| 349 |         //######################### Threads #########################
 | 
|---|
| 350 | 
 | 
|---|
| 351 |         int pthread_create(pthread_t * _thread, const pthread_attr_t * attr, void *(* start_routine)(void *), void * arg) libcfa_public __THROW {
 | 
|---|
| 352 |                 cfaPthread * t = alloc();
 | 
|---|
| 353 |                 (*t){_thread, attr, start_routine, arg};
 | 
|---|
| 354 |                 return 0;
 | 
|---|
| 355 |         }
 | 
|---|
| 356 | 
 | 
|---|
| 357 |         int pthread_join(pthread_t _thread, void ** value_ptr) libcfa_public __THROW {
 | 
|---|
| 358 |                 // if thread is invalid
 | 
|---|
| 359 |                 if (_thread == NULL) return EINVAL;
 | 
|---|
| 360 |                 if (_thread == pthread_self()) return EDEADLK;
 | 
|---|
| 361 | 
 | 
|---|
| 362 |                 // get user thr pointer
 | 
|---|
| 363 |                 cfaPthread * p = lookup(_thread);
 | 
|---|
| 364 |                 try {
 | 
|---|
| 365 |                         join(*p);
 | 
|---|
| 366 |                 }
 | 
|---|
| 367 |                 // if thread called pthread_exit
 | 
|---|
| 368 |                 catchResume (ThreadCancelled(cfaPthread) * cancel) {}
 | 
|---|
| 369 | 
 | 
|---|
| 370 |                 // fetch result
 | 
|---|
| 371 |                 if (value_ptr != NULL ) *value_ptr = p->joinval;
 | 
|---|
| 372 |                 delete(p);
 | 
|---|
| 373 |                 return 0;
 | 
|---|
| 374 |         }
 | 
|---|
| 375 | 
 | 
|---|
| 376 |         int pthread_tryjoin_np(pthread_t _thread, void ** value_ptr) libcfa_public __THROW {
 | 
|---|
| 377 |                 // if thread is invalid
 | 
|---|
| 378 |                 if (_thread == NULL) return EINVAL;
 | 
|---|
| 379 |                 if (_thread == pthread_self()) return EDEADLK;
 | 
|---|
| 380 | 
 | 
|---|
| 381 |                 cfaPthread * p = lookup(_thread);
 | 
|---|
| 382 | 
 | 
|---|
| 383 |                 // thread not finished ?
 | 
|---|
| 384 |                 if (!p->isTerminated) return EBUSY;
 | 
|---|
| 385 | 
 | 
|---|
| 386 |                 join( *p );
 | 
|---|
| 387 | 
 | 
|---|
| 388 |                 if (value_ptr != NULL ) *value_ptr = p->joinval;
 | 
|---|
| 389 |                 delete(p);
 | 
|---|
| 390 |                 return 0;
 | 
|---|
| 391 |         }
 | 
|---|
| 392 | 
 | 
|---|
| 393 |         pthread_t pthread_self(void) libcfa_public __THROW {
 | 
|---|
| 394 |                 return (pthread_t)((uintptr_t)active_thread());
 | 
|---|
| 395 |         }
 | 
|---|
| 396 | 
 | 
|---|
| 397 |         void pthread_exit(void * status) libcfa_public __THROW {
 | 
|---|
| 398 |                 pthread_t pid = pthread_self();
 | 
|---|
| 399 |                 cfaPthread * _thread = (cfaPthread *)pid;
 | 
|---|
| 400 |                 _thread->joinval = status;  // set return value
 | 
|---|
| 401 |                 _thread->isTerminated = 1;  // set terminated flag
 | 
|---|
| 402 |                 cancel_stack((pthread_exit_exp){&exp_vt});
 | 
|---|
| 403 |         }   //pthread_exit_
 | 
|---|
| 404 | 
 | 
|---|
| 405 |         int pthread_yield( void ) __THROW {                     // GNU extension
 | 
|---|
| 406 |                 yield();
 | 
|---|
| 407 |                 return 0;
 | 
|---|
| 408 |         }
 | 
|---|
| 409 | 
 | 
|---|
| 410 | 
 | 
|---|
| 411 |         //######################### Mutex #########################
 | 
|---|
| 412 | 
 | 
|---|
| 413 |         int pthread_mutex_init(pthread_mutex_t *_mutex, const pthread_mutexattr_t * attr) libcfa_public __THROW {
 | 
|---|
| 414 |                 check_nonnull(_mutex);
 | 
|---|
| 415 |                 init(_mutex);
 | 
|---|
| 416 |                 return 0;
 | 
|---|
| 417 |         }   //pthread_mutex_init_
 | 
|---|
| 418 | 
 | 
|---|
| 419 | 
 | 
|---|
| 420 |         int pthread_mutex_destroy(pthread_mutex_t *_mutex) libcfa_public __THROW {
 | 
|---|
| 421 |                 check_nonnull(_mutex);
 | 
|---|
| 422 |                 simple_owner_lock * _lock = get(_mutex);
 | 
|---|
| 423 |                 if (_lock->owner != NULL) {
 | 
|---|
| 424 |                         return EBUSY;
 | 
|---|
| 425 |                 }
 | 
|---|
| 426 |                 destroy(_mutex);
 | 
|---|
| 427 |                 return 0;
 | 
|---|
| 428 |         }   //pthread_mutex_destroy_
 | 
|---|
| 429 | 
 | 
|---|
| 430 |         int pthread_mutex_lock(pthread_mutex_t *_mutex) libcfa_public __THROW {
 | 
|---|
| 431 |                 check_nonnull(_mutex);
 | 
|---|
| 432 |                 mutex_check(_mutex);
 | 
|---|
| 433 |                 simple_owner_lock * _lock = get(_mutex);
 | 
|---|
| 434 |                 lock(*_lock);
 | 
|---|
| 435 |                 return 0;
 | 
|---|
| 436 |         }   //pthread_mutex_lock_
 | 
|---|
| 437 | 
 | 
|---|
| 438 |         int pthread_mutex_unlock(pthread_mutex_t *_mutex) libcfa_public __THROW {
 | 
|---|
| 439 |                 check_nonnull(_mutex);
 | 
|---|
| 440 |                 simple_owner_lock * _lock = get(_mutex);
 | 
|---|
| 441 |                 if (_lock->owner != active_thread()) {
 | 
|---|
| 442 |                         return EPERM;
 | 
|---|
| 443 |                 } // current thread does not hold the mutex
 | 
|---|
| 444 |                 unlock(*_lock);
 | 
|---|
| 445 |                 return 0;
 | 
|---|
| 446 |         }   //pthread_mutex_unlock_
 | 
|---|
| 447 | 
 | 
|---|
| 448 |         int pthread_mutex_trylock(pthread_mutex_t *_mutex) libcfa_public __THROW {
 | 
|---|
| 449 |                 check_nonnull(_mutex);
 | 
|---|
| 450 |                 simple_owner_lock * _lock = get(_mutex);
 | 
|---|
| 451 |                 if (_lock->owner != active_thread() && _lock->owner != NULL) {
 | 
|---|
| 452 |                         return EBUSY;
 | 
|---|
| 453 |                 }   // if mutex is owned
 | 
|---|
| 454 |                 lock(*_lock);
 | 
|---|
| 455 |                 return 0;
 | 
|---|
| 456 |         }   //pthread_mutex_trylock_
 | 
|---|
| 457 | 
 | 
|---|
| 458 |         //######################### Conditional Variable #########################
 | 
|---|
| 459 | 
 | 
|---|
| 460 |         /* conditional variable routines */
 | 
|---|
| 461 |         int pthread_cond_init(pthread_cond_t * cond, const pthread_condattr_t * attr) libcfa_public __THROW {
 | 
|---|
| 462 |                 check_nonnull(cond);
 | 
|---|
| 463 |                 init(cond);
 | 
|---|
| 464 |                 return 0;
 | 
|---|
| 465 |         }  //pthread_cond_init
 | 
|---|
| 466 | 
 | 
|---|
| 467 |         int pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t *_mutex) libcfa_public __THROW {
 | 
|---|
| 468 |                 check_nonnull(_mutex);
 | 
|---|
| 469 |                 check_nonnull(cond);
 | 
|---|
| 470 |                 wait(*get(cond), *get(_mutex));
 | 
|---|
| 471 |                 return 0;
 | 
|---|
| 472 |         } // pthread_cond_wait
 | 
|---|
| 473 | 
 | 
|---|
| 474 |         int pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * _mutex, const struct timespec * abstime) libcfa_public __THROW {
 | 
|---|
| 475 |                 check_nonnull(_mutex);
 | 
|---|
| 476 |                 check_nonnull(cond);
 | 
|---|
| 477 |                 wait(*get(cond), *get(_mutex), *abstime);
 | 
|---|
| 478 |                 return 0;
 | 
|---|
| 479 |         } // pthread_cond_timedwait
 | 
|---|
| 480 | 
 | 
|---|
| 481 |         int pthread_cond_signal(pthread_cond_t * cond) libcfa_public __THROW {
 | 
|---|
| 482 |                 check_nonnull(cond);
 | 
|---|
| 483 |                 return notify_one(*get(cond));
 | 
|---|
| 484 |         } // pthread_cond_signal
 | 
|---|
| 485 | 
 | 
|---|
| 486 |         int pthread_cond_broadcast(pthread_cond_t * cond) libcfa_public __THROW {
 | 
|---|
| 487 |                 check_nonnull(cond);
 | 
|---|
| 488 |                 return notify_all(*get(cond));
 | 
|---|
| 489 |         } // pthread_cond_broadcast
 | 
|---|
| 490 | 
 | 
|---|
| 491 |         int pthread_cond_destroy(pthread_cond_t * cond) libcfa_public __THROW {
 | 
|---|
| 492 |                 check_nonnull(cond);
 | 
|---|
| 493 |                 destroy(cond);
 | 
|---|
| 494 |                 return 0;
 | 
|---|
| 495 |         } // pthread_cond_destroy
 | 
|---|
| 496 | 
 | 
|---|
| 497 | 
 | 
|---|
| 498 | 
 | 
|---|
| 499 |         //######################### Local storage #########################
 | 
|---|
| 500 | 
 | 
|---|
| 501 |         int pthread_once(pthread_once_t * once_control, void (* init_routine)(void)) libcfa_public __THROW {
 | 
|---|
| 502 |                 static_assert(sizeof(pthread_once_t) >= sizeof(int),"sizeof(pthread_once_t) < sizeof(int)");
 | 
|---|
| 503 |                 check_nonnull(once_control);
 | 
|---|
| 504 |                 check_nonnull(init_routine);
 | 
|---|
| 505 |                 lock(once_lock);
 | 
|---|
| 506 |                 if ( *((int *)once_control) == 0 ) {
 | 
|---|
| 507 |                         init_routine();
 | 
|---|
| 508 |                         *((int *)once_control) = 1;
 | 
|---|
| 509 |                 } // if
 | 
|---|
| 510 |                 unlock(once_lock);
 | 
|---|
| 511 |                 return 0;
 | 
|---|
| 512 |         } // pthread_once
 | 
|---|
| 513 | 
 | 
|---|
| 514 |         int pthread_key_create( pthread_key_t * key, void (* destructor)( void * ) ) libcfa_public __THROW {
 | 
|---|
| 515 |                 lock(key_lock);
 | 
|---|
| 516 |                 for ( int i = 0; i < PTHREAD_KEYS_MAX; i += 1 ) {
 | 
|---|
| 517 |                         if ( ! cfa_pthread_keys[i].in_use ) {
 | 
|---|
| 518 |                                 cfa_pthread_keys[i].in_use = true;
 | 
|---|
| 519 |                                 cfa_pthread_keys[i].destructor = destructor;
 | 
|---|
| 520 |                                 unlock( key_lock );
 | 
|---|
| 521 |                                 *key = i;
 | 
|---|
| 522 |                                 return 0;
 | 
|---|
| 523 |                         } // if
 | 
|---|
| 524 |                 } // for
 | 
|---|
| 525 |                 unlock(key_lock);
 | 
|---|
| 526 |                 return EAGAIN;
 | 
|---|
| 527 |         }   // pthread_key_create
 | 
|---|
| 528 | 
 | 
|---|
| 529 |         int pthread_key_delete( pthread_key_t key ) libcfa_public __THROW {
 | 
|---|
| 530 |                 lock(key_lock);
 | 
|---|
| 531 |                 if ( key >= PTHREAD_KEYS_MAX || ! cfa_pthread_keys[key].in_use ) {
 | 
|---|
| 532 |                         unlock( key_lock );
 | 
|---|
| 533 |                         return EINVAL;
 | 
|---|
| 534 |                 } // if
 | 
|---|
| 535 |                 cfa_pthread_keys[key].in_use = false;
 | 
|---|
| 536 |                 cfa_pthread_keys[key].destructor = NULL;
 | 
|---|
| 537 | 
 | 
|---|
| 538 |                 // Remove key from all threads with a value.
 | 
|---|
| 539 |                 
 | 
|---|
| 540 |                 // Sequence(pthread_values)& head = cfa_pthread_keys[key].threads;
 | 
|---|
| 541 |                 // for ( SeqIter(pthread_values) iter = { head }; iter | p; ) {
 | 
|---|
| 542 |                 //      remove(head, p);
 | 
|---|
| 543 |                 //      p.in_use = false;
 | 
|---|
| 544 |                 // }
 | 
|---|
| 545 |                 for ( pthread_values * p = &remove_first( cfa_pthread_keys[key].threads ); p; p = &remove_first( cfa_pthread_keys[key].threads ) ) {
 | 
|---|
| 546 |                         p->in_use = false;
 | 
|---|
| 547 |                 }
 | 
|---|
| 548 |                 unlock(key_lock);
 | 
|---|
| 549 |                 return 0;
 | 
|---|
| 550 |         }   // pthread_key_delete
 | 
|---|
| 551 | 
 | 
|---|
| 552 |         int pthread_setspecific( pthread_key_t key, const void * value ) libcfa_public __THROW {
 | 
|---|
| 553 |                 // get current thread
 | 
|---|
| 554 |                 cfaPthread * t = lookup(pthread_self());
 | 
|---|
| 555 |                 // if current thread's pthreadData is NULL; initialize it
 | 
|---|
| 556 |                 pthread_values * values;
 | 
|---|
| 557 |                 if (t->pthreadData == NULL) {
 | 
|---|
| 558 |                         values = anew( PTHREAD_KEYS_MAX);
 | 
|---|
| 559 |                         t->pthreadData = values;
 | 
|---|
| 560 |                         for ( int i = 0;i < PTHREAD_KEYS_MAX; i++ ) {
 | 
|---|
| 561 |                                 t->pthreadData[i].in_use = false;
 | 
|---|
| 562 |                         }   // for
 | 
|---|
| 563 |                 }   else {
 | 
|---|
| 564 |                         values = t->pthreadData;
 | 
|---|
| 565 |                 }   // if
 | 
|---|
| 566 |                 // find corresponding key and set value
 | 
|---|
| 567 |                 lock(key_lock);
 | 
|---|
| 568 |                 // if invalid key
 | 
|---|
| 569 |                 if ( key >= PTHREAD_KEYS_MAX || ! cfa_pthread_keys[key].in_use ) {
 | 
|---|
| 570 |                         unlock( key_lock );
 | 
|---|
| 571 |                         return EINVAL;
 | 
|---|
| 572 |                 } // if
 | 
|---|
| 573 |                 pthread_values &entry = values[key];
 | 
|---|
| 574 |                 if ( ! entry.in_use ) {
 | 
|---|
| 575 |                         entry.in_use = true;
 | 
|---|
| 576 |                         insert_last(cfa_pthread_keys[key].threads, entry);
 | 
|---|
| 577 |                 } // if
 | 
|---|
| 578 |                 entry.value = (void *)value;
 | 
|---|
| 579 |                 unlock(key_lock);
 | 
|---|
| 580 |                 return 0;
 | 
|---|
| 581 |         } //pthread_setspecific
 | 
|---|
| 582 | 
 | 
|---|
| 583 |         void * pthread_getspecific(pthread_key_t key) libcfa_public __THROW {
 | 
|---|
| 584 |                 if (key >= PTHREAD_KEYS_MAX || ! cfa_pthread_keys[key].in_use) return NULL;
 | 
|---|
| 585 | 
 | 
|---|
| 586 |                 // get current thread
 | 
|---|
| 587 |                 cfaPthread * t = lookup(pthread_self());
 | 
|---|
| 588 |                 if (t->pthreadData == NULL) return NULL;
 | 
|---|
| 589 |                 lock(key_lock);
 | 
|---|
| 590 |                 pthread_values & entry = ((pthread_values *)t->pthreadData)[key];
 | 
|---|
| 591 |                 if ( ! entry.in_use ) {
 | 
|---|
| 592 |                         unlock( key_lock );
 | 
|---|
| 593 |                         return NULL;
 | 
|---|
| 594 |                 } // if
 | 
|---|
| 595 |                 void * value = entry.value;
 | 
|---|
| 596 |                 unlock(key_lock);
 | 
|---|
| 597 | 
 | 
|---|
| 598 |                 return value;
 | 
|---|
| 599 |         }   //pthread_get_specific
 | 
|---|
| 600 | 
 | 
|---|
| 601 |         //######################### Parallelism #########################
 | 
|---|
| 602 |         void pthread_delete_kernel_threads_() __THROW { // see uMain::~uMain
 | 
|---|
| 603 |                 
 | 
|---|
| 604 |                 for ( Pthread_kernel_threads * p = &remove_first(cfa_pthreads_kernel_threads); p; p = &remove_first(cfa_pthreads_kernel_threads) ) {
 | 
|---|
| 605 |                         delete(p);
 | 
|---|
| 606 |                 } // for
 | 
|---|
| 607 |         } // pthread_delete_kernel_threads_
 | 
|---|
| 608 | 
 | 
|---|
| 609 |         int pthread_getconcurrency( void ) __THROW {    // XOPEN extension
 | 
|---|
| 610 |                 return cfa_pthreads_kernel_threads_zero ? 0 : cfa_pthreads_no_kernel_threads;
 | 
|---|
| 611 |         } // pthread_getconcurrency
 | 
|---|
| 612 | 
 | 
|---|
| 613 |         int pthread_setconcurrency( int new_level ) libcfa_public __THROW { // XOPEN extension
 | 
|---|
| 614 |                 if ( new_level < 0 ) return EINVAL;
 | 
|---|
| 615 |                 if ( new_level == 0 ) {
 | 
|---|
| 616 |                         cfa_pthreads_kernel_threads_zero = true;        // remember set to zero, but ignore
 | 
|---|
| 617 |                         return 0;                                       // do not do kernel thread management
 | 
|---|
| 618 |                 } // exit
 | 
|---|
| 619 |                 cfa_pthreads_kernel_threads_zero = false;
 | 
|---|
| 620 |                 lock( concurrency_lock );
 | 
|---|
| 621 |                 for ( ; new_level > cfa_pthreads_no_kernel_threads; cfa_pthreads_no_kernel_threads += 1 ) { // add processors ?
 | 
|---|
| 622 |                         insert_last(cfa_pthreads_kernel_threads, *new() );
 | 
|---|
| 623 |                 } // for
 | 
|---|
| 624 |                 for ( ; new_level < cfa_pthreads_no_kernel_threads; cfa_pthreads_no_kernel_threads -= 1 ) { // remove processors ?
 | 
|---|
| 625 |                         delete(&remove_first(cfa_pthreads_kernel_threads));
 | 
|---|
| 626 |                 } // for
 | 
|---|
| 627 |                 unlock( concurrency_lock );
 | 
|---|
| 628 |                 return 0;
 | 
|---|
| 629 |         } // pthread_setconcurrency
 | 
|---|
| 630 | 
 | 
|---|
| 631 |         //######################### Signal #########################
 | 
|---|
| 632 | 
 | 
|---|
| 633 | 
 | 
|---|
| 634 |          int pthread_sigmask( int /* how */, const sigset_t * /* set */, sigset_t * /* oset */ ) libcfa_public __THROW {
 | 
|---|
| 635 |                 abort( "pthread_sigmask : not implemented" );
 | 
|---|
| 636 |                 return 0;
 | 
|---|
| 637 |          } // pthread_sigmask
 | 
|---|
| 638 | 
 | 
|---|
| 639 |         int pthread_kill( pthread_t _thread __attribute__(( unused )), int sig ) libcfa_public __THROW {
 | 
|---|
| 640 |                 if ( sig == 0 ) {
 | 
|---|
| 641 |                         return 0;
 | 
|---|
| 642 |                 } else {
 | 
|---|
| 643 |                         abort( "pthread_kill : not implemented" );
 | 
|---|
| 644 |                 } // if
 | 
|---|
| 645 |                 return 0;
 | 
|---|
| 646 |         } // pthread_kill
 | 
|---|
| 647 | 
 | 
|---|
| 648 |         int pthread_sigqueue(pthread_t , int sig, const union sigval) libcfa_public __THROW {
 | 
|---|
| 649 |                 abort( "pthread_sigqueue : not implemented" );
 | 
|---|
| 650 |                 return 0;
 | 
|---|
| 651 |         } // pthread_sigqueue
 | 
|---|
| 652 | 
 | 
|---|
| 653 |         //######################### Scheduling #########################
 | 
|---|
| 654 |         int pthread_detach( pthread_t threadID ) __THROW {
 | 
|---|
| 655 |                 abort( "pthread_detach : not implemented" );
 | 
|---|
| 656 |                 return 0;
 | 
|---|
| 657 |         } // pthread_detach
 | 
|---|
| 658 | 
 | 
|---|
| 659 |         int pthread_setschedparam( pthread_t /* thread */, int /* policy */, const struct sched_param * /* param */ ) libcfa_public __THROW {
 | 
|---|
| 660 |                 abort( "pthread_setschedparam : not implemented" );
 | 
|---|
| 661 |                 return 0;
 | 
|---|
| 662 |         } // pthread_setschedparam
 | 
|---|
| 663 | 
 | 
|---|
| 664 |         int pthread_getschedparam( pthread_t /* thread */, int */* policy */, struct sched_param * /* param */ ) libcfa_public __THROW {
 | 
|---|
| 665 |                 abort( "pthread_getschedparam : not implemented" );
 | 
|---|
| 666 |                 return 0;
 | 
|---|
| 667 |         } // pthread_getschedparam
 | 
|---|
| 668 | 
 | 
|---|
| 669 |          //######################### Mutex Attr #########################
 | 
|---|
| 670 | 
 | 
|---|
| 671 |         int pthread_mutexattr_init( pthread_mutexattr_t * /* attr */ ) libcfa_public __THROW {
 | 
|---|
| 672 |                 return 0;
 | 
|---|
| 673 |         } // pthread_mutexattr_init
 | 
|---|
| 674 | 
 | 
|---|
| 675 |         int pthread_mutexattr_destroy( pthread_mutexattr_t * /* attr */ ) libcfa_public __THROW {
 | 
|---|
| 676 |                 return 0;
 | 
|---|
| 677 |         } // pthread_mutexattr_destroy
 | 
|---|
| 678 | 
 | 
|---|
| 679 |         int pthread_mutexattr_setpshared( pthread_mutexattr_t * /* attr */, int /* pshared */ ) libcfa_public __THROW {
 | 
|---|
| 680 |                 return 0;
 | 
|---|
| 681 |         } // pthread_mutexattr_setpshared
 | 
|---|
| 682 | 
 | 
|---|
| 683 |         int pthread_mutexattr_getpshared( const pthread_mutexattr_t * /* attr */, int * /* pshared */ ) libcfa_public __THROW {
 | 
|---|
| 684 |                 return 0;
 | 
|---|
| 685 |         } // pthread_mutexattr_getpshared
 | 
|---|
| 686 | 
 | 
|---|
| 687 |         int pthread_mutexattr_setprotocol( pthread_mutexattr_t * /* attr */, int /* protocol */ ) libcfa_public __THROW {
 | 
|---|
| 688 |                 return 0;
 | 
|---|
| 689 |         } // pthread_mutexattr_setprotocol
 | 
|---|
| 690 | 
 | 
|---|
| 691 |         int pthread_mutexattr_getprotocol( const pthread_mutexattr_t * /* attr */, int * /* protocol */ ) libcfa_public __THROW {
 | 
|---|
| 692 |                 return 0;
 | 
|---|
| 693 |         } // pthread_mutexattr_getprotocol
 | 
|---|
| 694 | 
 | 
|---|
| 695 |         int pthread_mutexattr_setprioceiling( pthread_mutexattr_t * /* attr */, int /* prioceiling */ ) libcfa_public __THROW {
 | 
|---|
| 696 |                 return 0;
 | 
|---|
| 697 |         } // pthread_mutexattr_setprioceiling
 | 
|---|
| 698 | 
 | 
|---|
| 699 |         int pthread_mutexattr_getprioceiling( const pthread_mutexattr_t * /* attr */, int * /* ceiling */ ) libcfa_public __THROW {
 | 
|---|
| 700 |                 return 0;
 | 
|---|
| 701 |         } // pthread_mutexattr_getprioceiling
 | 
|---|
| 702 | 
 | 
|---|
| 703 |         int pthread_mutex_setprioceiling( pthread_mutex_t * /* mutex */, int /* prioceiling */, int * /* old_ceiling */ ) libcfa_public __THROW {
 | 
|---|
| 704 |                 return 0;
 | 
|---|
| 705 |         } // pthread_mutex_setprioceiling
 | 
|---|
| 706 | 
 | 
|---|
| 707 |         int pthread_mutex_getprioceiling( const pthread_mutex_t * /* mutex */, int * /* ceiling */ ) libcfa_public __THROW {
 | 
|---|
| 708 |                 return 0;
 | 
|---|
| 709 |         } // pthread_mutex_getprioceiling
 | 
|---|
| 710 | 
 | 
|---|
| 711 |         int pthread_mutexattr_gettype( __const pthread_mutexattr_t * __restrict /* __attr */, int * __restrict /* __kind */ ) libcfa_public __THROW {
 | 
|---|
| 712 |                 return 0;
 | 
|---|
| 713 |         } // pthread_mutexattr_gettype
 | 
|---|
| 714 | 
 | 
|---|
| 715 |         int pthread_mutexattr_settype( pthread_mutexattr_t * /* __attr */, int /* __kind */ ) libcfa_public __THROW {
 | 
|---|
| 716 |                 return 0;
 | 
|---|
| 717 |         } // pthread_mutexattr_settype
 | 
|---|
| 718 | 
 | 
|---|
| 719 |         //######################### Mutex #########################
 | 
|---|
| 720 | 
 | 
|---|
| 721 |         int pthread_mutex_timedlock( pthread_mutex_t *__restrict /* __mutex */, __const struct timespec *__restrict /* __abstime */ ) libcfa_public __THROW {
 | 
|---|
| 722 |                 abort( "pthread_mutex_timedlock" );
 | 
|---|
| 723 |         } // pthread_mutex_timedlock
 | 
|---|
| 724 | 
 | 
|---|
| 725 |         //######################### Condition #########################
 | 
|---|
| 726 | 
 | 
|---|
| 727 |         int pthread_condattr_getclock( __const pthread_condattr_t * __restrict /* __attr */, __clockid_t *__restrict /* __clock_id */ ) libcfa_public __THROW {
 | 
|---|
| 728 |                 abort( "pthread_condattr_getclock" );
 | 
|---|
| 729 |         } // pthread_condattr_getclock
 | 
|---|
| 730 | 
 | 
|---|
| 731 |         int pthread_condattr_setclock( pthread_condattr_t * /* __attr */, __clockid_t /* __clock_id */ ) libcfa_public __THROW {
 | 
|---|
| 732 |                 abort( "pthread_condattr_setclock" );
 | 
|---|
| 733 |         } // pthread_condattr_setclock
 | 
|---|
| 734 | 
 | 
|---|
| 735 |         //######################### Spinlock #########################
 | 
|---|
| 736 | 
 | 
|---|
| 737 |         int pthread_spin_init( pthread_spinlock_t * /* __lock */, int /*__pshared */ ) libcfa_public __THROW {
 | 
|---|
| 738 |                 abort( "pthread_spin_init" );
 | 
|---|
| 739 |         } // pthread_spin_init
 | 
|---|
| 740 | 
 | 
|---|
| 741 |         int pthread_spin_destroy( pthread_spinlock_t * /* __lock */ ) libcfa_public __THROW {
 | 
|---|
| 742 |                 abort( "pthread_spin_destroy" );
 | 
|---|
| 743 |         } // pthread_spin_destroy
 | 
|---|
| 744 | 
 | 
|---|
| 745 |         int pthread_spin_lock( pthread_spinlock_t * /* __lock */ ) libcfa_public __THROW {
 | 
|---|
| 746 |                 abort( "pthread_spin_lock" );
 | 
|---|
| 747 |         } // pthread_spin_lock
 | 
|---|
| 748 | 
 | 
|---|
| 749 |         int pthread_spin_trylock( pthread_spinlock_t * /* __lock */ ) libcfa_public __THROW {
 | 
|---|
| 750 |                 abort( "pthread_spin_trylock" );
 | 
|---|
| 751 |         } // pthread_spin_trylock
 | 
|---|
| 752 | 
 | 
|---|
| 753 |         int pthread_spin_unlock( pthread_spinlock_t * /* __lock */ ) libcfa_public __THROW {
 | 
|---|
| 754 |                 abort( "pthread_spin_unlock" );
 | 
|---|
| 755 |         } // pthread_spin_unlock
 | 
|---|
| 756 | 
 | 
|---|
| 757 |         //######################### Barrier #########################
 | 
|---|
| 758 | 
 | 
|---|
| 759 |         int pthread_barrier_init( pthread_barrier_t *__restrict /* __barrier */, __const pthread_barrierattr_t *__restrict /* __attr */, unsigned int /* __count */ ) libcfa_public __THROW {
 | 
|---|
| 760 |                 abort( "pthread_barrier_init" );
 | 
|---|
| 761 |         } // pthread_barrier_init
 | 
|---|
| 762 | 
 | 
|---|
| 763 |         int pthread_barrier_destroy( pthread_barrier_t * /* __barrier */ ) libcfa_public  __THROW {
 | 
|---|
| 764 |                 abort( "pthread_barrier_destroy" );
 | 
|---|
| 765 |         } // pthread_barrier_destroy
 | 
|---|
| 766 | 
 | 
|---|
| 767 |         int pthread_barrier_wait( pthread_barrier_t * /* __barrier */ ) libcfa_public __THROW {
 | 
|---|
| 768 |                 abort( "pthread_barrier_wait" );
 | 
|---|
| 769 |         } // pthread_barrier_wait
 | 
|---|
| 770 | 
 | 
|---|
| 771 |         int pthread_barrierattr_init( pthread_barrierattr_t * /* __attr */ ) libcfa_public __THROW {
 | 
|---|
| 772 |                 abort( "pthread_barrierattr_init" );
 | 
|---|
| 773 |         } // pthread_barrierattr_init
 | 
|---|
| 774 | 
 | 
|---|
| 775 |         int pthread_barrierattr_destroy( pthread_barrierattr_t * /* __attr */ ) libcfa_public __THROW {
 | 
|---|
| 776 |                 abort( "pthread_barrierattr_destroy" );
 | 
|---|
| 777 |         } // pthread_barrierattr_destroy
 | 
|---|
| 778 | 
 | 
|---|
| 779 |         int pthread_barrierattr_getpshared( __const pthread_barrierattr_t * __restrict /* __attr */, int *__restrict /* __pshared */ ) libcfa_public __THROW {
 | 
|---|
| 780 |                 abort( "pthread_barrierattr_getpshared" );
 | 
|---|
| 781 |         } // pthread_barrierattr_getpshared
 | 
|---|
| 782 | 
 | 
|---|
| 783 |         int pthread_barrierattr_setpshared( pthread_barrierattr_t * /* __attr */, int /* __pshared */ ) libcfa_public __THROW {
 | 
|---|
| 784 |                 abort( "pthread_barrierattr_setpshared" );
 | 
|---|
| 785 |         } // pthread_barrierattr_setpshared
 | 
|---|
| 786 | 
 | 
|---|
| 787 |         //######################### Clock #########################
 | 
|---|
| 788 | 
 | 
|---|
| 789 |         int pthread_getcpuclockid( pthread_t /* __thread_id */, __clockid_t * /* __clock_id */ ) libcfa_public __THROW {
 | 
|---|
| 790 |                 abort( "pthread_getcpuclockid" );
 | 
|---|
| 791 |         } // pthread_getcpuclockid
 | 
|---|
| 792 | 
 | 
|---|
| 793 |         // pthread_atfork()
 | 
|---|
| 794 | 
 | 
|---|
| 795 | // UNIX98
 | 
|---|
| 796 | 
 | 
|---|
| 797 |         //######################### Read/Write #########################
 | 
|---|
| 798 | 
 | 
|---|
| 799 |         int pthread_rwlock_init( pthread_rwlock_t *__restrict /* __rwlock */, __const pthread_rwlockattr_t *__restrict /* __attr */ ) libcfa_public __THROW {
 | 
|---|
| 800 |                 abort( "pthread_rwlock_init" );
 | 
|---|
| 801 |         } // pthread_rwlock_init
 | 
|---|
| 802 | 
 | 
|---|
| 803 |         int pthread_rwlock_destroy( pthread_rwlock_t * /* __rwlock */ ) libcfa_public __THROW {
 | 
|---|
| 804 |                 abort( "pthread_rwlock_destroy" );
 | 
|---|
| 805 |         } // pthread_rwlock_destroy
 | 
|---|
| 806 | 
 | 
|---|
| 807 |         int pthread_rwlock_rdlock( pthread_rwlock_t * /* __rwlock */ ) libcfa_public __THROW {
 | 
|---|
| 808 |                 abort( "pthread_rwlock_rdlock" );
 | 
|---|
| 809 |         } // pthread_rwlock_rdlock
 | 
|---|
| 810 | 
 | 
|---|
| 811 |         int pthread_rwlock_tryrdlock( pthread_rwlock_t * /* __rwlock */ ) libcfa_public __THROW {
 | 
|---|
| 812 |                 abort( "pthread_rwlock_tryrdlock" );
 | 
|---|
| 813 |         } // pthread_rwlock_tryrdlock
 | 
|---|
| 814 | 
 | 
|---|
| 815 |         int pthread_rwlock_wrlock( pthread_rwlock_t * /* __rwlock */ ) libcfa_public __THROW {
 | 
|---|
| 816 |                 abort( "pthread_rwlock_wrlock" );
 | 
|---|
| 817 |         } // pthread_rwlock_wrlock
 | 
|---|
| 818 | 
 | 
|---|
| 819 |         int pthread_rwlock_trywrlock( pthread_rwlock_t * /* __rwlock */ ) libcfa_public __THROW {
 | 
|---|
| 820 |                 abort( "pthread_rwlock_trywrlock" );
 | 
|---|
| 821 |         } // pthread_rwlock_trywrlock
 | 
|---|
| 822 | 
 | 
|---|
| 823 |         int pthread_rwlock_unlock( pthread_rwlock_t * /* __rwlock */ ) libcfa_public __THROW {
 | 
|---|
| 824 |                 abort( "pthread_rwlock_unlock" );
 | 
|---|
| 825 |         } // pthread_rwlock_unlock
 | 
|---|
| 826 | 
 | 
|---|
| 827 |         int pthread_rwlockattr_init( pthread_rwlockattr_t * /* __attr */ ) libcfa_public __THROW {
 | 
|---|
| 828 |                 abort( "pthread_rwlockattr_init" );
 | 
|---|
| 829 |         } // pthread_rwlockattr_init
 | 
|---|
| 830 | 
 | 
|---|
| 831 |         int pthread_rwlockattr_destroy( pthread_rwlockattr_t * /*__attr */ ) libcfa_public __THROW {
 | 
|---|
| 832 |                 abort( "pthread_rwlockattr_destroy" );
 | 
|---|
| 833 |         } // pthread_rwlockattr_destroy
 | 
|---|
| 834 | 
 | 
|---|
| 835 |         int pthread_rwlockattr_getpshared( __const pthread_rwlockattr_t * __restrict /* __attr */, int *__restrict /* __pshared */ ) libcfa_public __THROW {
 | 
|---|
| 836 |                 abort( "pthread_rwlockattr_getpshared" );
 | 
|---|
| 837 |         } // pthread_rwlockattr_getpshared
 | 
|---|
| 838 | 
 | 
|---|
| 839 |         int pthread_rwlockattr_setpshared( pthread_rwlockattr_t * /* __attr */, int /* __pshared */ ) libcfa_public __THROW {
 | 
|---|
| 840 |                 abort( "pthread_rwlockattr_setpshared" );
 | 
|---|
| 841 |         } // pthread_rwlockattr_setpshared
 | 
|---|
| 842 | 
 | 
|---|
| 843 |         int pthread_rwlockattr_getkind_np( __const pthread_rwlockattr_t * /* __attr */, int * /* __pref */ ) libcfa_public __THROW {
 | 
|---|
| 844 |                 abort( "pthread_rwlockattr_getkind_np" );
 | 
|---|
| 845 |         } // pthread_rwlockattr_getkind_np
 | 
|---|
| 846 | 
 | 
|---|
| 847 |         int pthread_rwlockattr_setkind_np( pthread_rwlockattr_t * /* __attr */, int /* __pref */ ) libcfa_public __THROW {
 | 
|---|
| 848 |                 abort( "pthread_rwlockattr_setkind_np" );
 | 
|---|
| 849 |         } // pthread_rwlockattr_setkind_np
 | 
|---|
| 850 | 
 | 
|---|
| 851 | // UNIX98 + XOPEN
 | 
|---|
| 852 | 
 | 
|---|
| 853 |         int pthread_rwlock_timedrdlock( pthread_rwlock_t *__restrict  /* __rwlock */, __const struct timespec *__restrict /* __abstime */ ) libcfa_public __THROW {
 | 
|---|
| 854 |                 abort( "pthread_rwlock_timedrdlock" );
 | 
|---|
| 855 |         } // pthread_rwlock_timedrdlock
 | 
|---|
| 856 | 
 | 
|---|
| 857 |         int pthread_rwlock_timedwrlock( pthread_rwlock_t *__restrict  /* __rwlock */, __const struct timespec *__restrict /* __abstime */ ) libcfa_public __THROW {
 | 
|---|
| 858 |                 abort( "pthread_rwlock_timedwrlock" );
 | 
|---|
| 859 |         } // pthread_rwlock_timedwrlock
 | 
|---|
| 860 | 
 | 
|---|
| 861 | // GNU
 | 
|---|
| 862 | 
 | 
|---|
| 863 |         //######################### Parallelism #########################
 | 
|---|
| 864 | 
 | 
|---|
| 865 |         // int pthread_setaffinity_np( pthread_t /* __th */, size_t /* __cpusetsize */, __const cpu_set_t * /* __cpuset */ ) libcfa_public __THROW {
 | 
|---|
| 866 |         //      abort( "pthread_setaffinity_np" );
 | 
|---|
| 867 |         // } // pthread_setaffinity_np
 | 
|---|
| 868 | 
 | 
|---|
| 869 |         // int pthread_getaffinity_np( pthread_t /* __th */, size_t /* __cpusetsize */, cpu_set_t * /* __cpuset */ ) libcfa_public __THROW {
 | 
|---|
| 870 |         //      abort( "pthread_getaffinity_np" );
 | 
|---|
| 871 |         // } // pthread_getaffinity_np
 | 
|---|
| 872 | 
 | 
|---|
| 873 |         // int pthread_attr_setaffinity_np( pthread_attr_t * /* __attr */, size_t /* __cpusetsize */, __const cpu_set_t * /* __cpuset */ ) libcfa_public __THROW {
 | 
|---|
| 874 |         //      abort( "pthread_attr_setaffinity_np" );
 | 
|---|
| 875 |         // } // pthread_attr_setaffinity_np
 | 
|---|
| 876 | 
 | 
|---|
| 877 |         // int pthread_attr_getaffinity_np( __const pthread_attr_t * /* __attr */, size_t /* __cpusetsize */, cpu_set_t * /* __cpuset */ ) libcfa_public __THROW {
 | 
|---|
| 878 |         //      abort( "pthread_attr_getaffinity_np" );
 | 
|---|
| 879 |         // } // pthread_attr_getaffinity_np
 | 
|---|
| 880 | 
 | 
|---|
| 881 |         //######################### Cancellation #########################
 | 
|---|
| 882 | 
 | 
|---|
| 883 |         void _pthread_cleanup_push_defer( struct _pthread_cleanup_buffer * /* __buffer */, void( * /* __routine */ )( void * ), void * /* __arg */ ) libcfa_public __THROW {
 | 
|---|
| 884 |                 abort( "_pthread_cleanup_push_defer" );
 | 
|---|
| 885 |         } // _pthread_cleanup_push_defer
 | 
|---|
| 886 | 
 | 
|---|
| 887 |         void _pthread_cleanup_pop_restore( struct _pthread_cleanup_buffer * /* __buffer */, int /* __execute */ ) libcfa_public __THROW {
 | 
|---|
| 888 |                 abort( "_pthread_cleanup_pop_restore" );
 | 
|---|
| 889 |         } // _pthread_cleanup_pop_res
 | 
|---|
| 890 | 
 | 
|---|
| 891 |         int pthread_cancel( pthread_t threadID ) libcfa_public __THROW {
 | 
|---|
| 892 |                 abort("pthread cancel not implemented");
 | 
|---|
| 893 |                 return 0;
 | 
|---|
| 894 |         } // pthread_cancel
 | 
|---|
| 895 | 
 | 
|---|
| 896 |         int pthread_setcancelstate( int state, int * oldstate ) libcfa_public __THROW {
 | 
|---|
| 897 |                 abort("pthread_setcancelstate not implemented");
 | 
|---|
| 898 |                 return 0;
 | 
|---|
| 899 |         } // pthread_setcancelstate
 | 
|---|
| 900 | 
 | 
|---|
| 901 |         int pthread_setcanceltype( int type, int * oldtype ) libcfa_public __THROW {
 | 
|---|
| 902 |                 abort("pthread_setcanceltype not implemented");
 | 
|---|
| 903 |                 return 0;
 | 
|---|
| 904 |         } // pthread_setcanceltype
 | 
|---|
| 905 | } // extern "C"
 | 
|---|
| 906 | 
 | 
|---|
| 907 | #pragma GCC diagnostic pop
 | 
|---|