3 * - By John Hodge (thePowersGang)
6 * - Core POSIX threads header
8 #ifndef _LIBPTHREAT_PTHREAD_H_
9 #define _LIBPTHREAT_PTHREAD_H_
11 // XXX: Hack - libgcc doesn't seem to be auto-detecting the presence of this header
14 //! \name pthread core
16 typedef struct pthread_attr_s pthread_attr_t;
21 unsigned int kernel_handle;
23 typedef struct pthread_s pthread_t;
25 extern int pthread_create(pthread_t *threadptr, const pthread_attr_t * attrs, void* (*fcn)(void*), void* arg);
26 extern int pthread_detach(pthread_t thread);
27 extern int pthread_join(pthread_t thread, void **retvalptr);
28 extern int pthread_cancel(pthread_t thread);
29 extern int pthread_equal(pthread_t t1, pthread_t t2);
30 extern pthread_t pthread_self(void);
31 extern void pthread_exit(void* retval);
35 //! \name pthread_once
41 #define PTHREAD_ONCE_INIT ((struct pthread_once_s){.flag=0})
42 typedef struct pthread_once_s pthread_once_t;
43 extern int pthread_once(pthread_once_t *once_contol, void (*init_routine)(void));
46 //! \name pthread mutexes
48 #define PTHREAD_MUTEX_NORMAL 0
49 #define PTHREAD_MUTEX_RECURSIVE 1
50 struct pthread_mutexattr_s
54 typedef struct pthread_mutexattr_s pthread_mutexattr_t;
55 extern int pthread_mutexattr_init(pthread_mutexattr_t *attrs);
56 extern int pthread_mutexattr_settype(pthread_mutexattr_t *attrs, int type);
57 extern int pthread_mutexattr_destroy(pthread_mutexattr_t *attrs);
59 struct pthread_mutex_s
63 #define PTHREAD_MUTEX_INITIALIZER ((struct pthread_mutex_s){0})
64 typedef struct pthread_mutex_s pthread_mutex_t;
65 extern int pthread_mutex_init(pthread_mutex_t * mutex, const pthread_mutexattr_t *attrs);
66 extern int pthread_mutex_lock(pthread_mutex_t *lock);
67 extern int pthread_mutex_trylock(pthread_mutex_t *lock);
68 extern int pthread_mutex_unlock(pthread_mutex_t *lock);
69 extern int pthread_mutex_destroy(pthread_mutex_t *lock);
72 //! \name pthread TLS keys
74 //typedef struct pthread_key_s pthread_key_t;
75 typedef unsigned int pthread_key_t;
76 extern int pthread_key_create(pthread_key_t *keyptr, void (*fcn)(void*));
77 extern int pthread_key_delete(pthread_key_t key);
78 extern int pthread_setspecific(pthread_key_t key, const void* data);
79 extern void* pthread_getspecific(pthread_key_t key);
82 //! \name pthread condvars
84 typedef struct pthread_cond_s pthread_cond_t;
85 typedef struct pthread_condattr_s pthread_condattr_t;
86 extern int pthread_cond_init(pthread_cond_t *condptr, const pthread_condattr_t* attrs);
87 extern int pthread_cond_wait(pthread_cond_t *condptr, pthread_mutex_t *mutex);
88 extern int pthread_cond_timedwait(pthread_cond_t *condptr, pthread_mutex_t *mutex, const struct timespec *timeout);
89 extern int pthread_cond_signal(pthread_cond_t *condptr);
90 extern int pthread_cond_broadcast(pthread_cond_t *condptr);
91 extern int pthread_cond_destroy(pthread_cond_t *condptr);