Added non-preemptive pthreads support.
[akaros.git] / user / parlib / pthread / include / pthread.h
1 #ifndef _PTHREAD_H
2 #define _PTHREAD_H
3
4 #include <hart.h>
5
6 #ifdef __cplusplus
7   extern "C" {
8 #endif
9
10 struct pthread_wqt
11 {
12   void* (*start_routine)(void*);
13   void* arg;
14   int finished;
15   int detached;
16   struct pthread_wqt* next;
17 };
18
19 typedef struct
20 {
21   int* local_sense;
22   volatile int sense;
23   int count;
24   int nprocs;
25   hart_lock_t lock;
26 } pthread_barrier_t;
27
28 typedef struct
29 {
30   int type;
31 } pthread_mutexattr_t;
32
33 typedef struct
34 {
35   const pthread_mutexattr_t* attr;
36   size_t lock;
37 } pthread_mutex_t;
38
39 typedef struct
40 {
41   int pshared;
42 } pthread_condattr_t;
43
44 typedef struct
45 {
46   const pthread_condattr_t* attr;
47   int waiters[HART_MAX_MAX_HARTS];
48 } pthread_cond_t;
49
50 typedef struct pthread_wqt work_queue_t;
51 typedef work_queue_t* pthread_t;
52 typedef int pthread_attr_t;
53 typedef int pthread_barrierattr_t;
54 typedef size_t pthread_once_t;
55 typedef void** pthread_key_t;
56
57 #define PTHREAD_ONCE_INIT 0
58 #define PTHREAD_BARRIER_SERIAL_THREAD 12345
59 #define PTHREAD_MUTEX_INITIALIZER {0}
60 #define PTHREAD_MUTEX_NORMAL 0
61 #define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL
62 #define PTHREAD_COND_INITIALIZER {0}
63 #define PTHREAD_PROCESS_PRIVATE 0
64
65 int pthread_attr_init(pthread_attr_t *);
66 int pthread_attr_destroy(pthread_attr_t *);
67 int pthread_create(pthread_t *, const pthread_attr_t *,
68                    void *(*)(void *), void *);
69 int pthread_join(pthread_t, void **);
70
71 int pthread_mutex_destroy(pthread_mutex_t *);
72 int pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *);
73 int pthread_mutex_lock(pthread_mutex_t *);
74 int pthread_mutex_trylock(pthread_mutex_t *);
75 int pthread_mutex_unlock(pthread_mutex_t *);
76 int pthread_mutex_destroy(pthread_mutex_t *);
77
78 int pthread_mutexattr_init(pthread_mutexattr_t *);
79 int pthread_mutexattr_destroy(pthread_mutexattr_t *);
80 int pthread_mutexattr_gettype(const pthread_mutexattr_t *, int *);
81 int pthread_mutexattr_settype(pthread_mutexattr_t *, int);
82
83 int pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *);
84 int pthread_cond_destroy(pthread_cond_t *);
85 int pthread_cond_broadcast(pthread_cond_t *);
86 int pthread_cond_signal(pthread_cond_t *);
87 int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *);
88
89 int pthread_condattr_init(pthread_condattr_t *);
90 int pthread_condattr_destroy(pthread_condattr_t *);
91 int pthread_condattr_setpshared(pthread_condattr_t *, int);
92 int pthread_condattr_getpshared(pthread_condattr_t *, int *);
93
94 #define pthread_rwlock_t pthread_mutex_t
95 #define pthread_rwlockattr_t pthread_mutexattr_t
96 #define pthread_rwlock_destroy pthread_mutex_destroy
97 #define pthread_rwlock_init pthread_mutex_init
98 #define pthread_rwlock_unlock pthread_mutex_unlock
99 #define pthread_rwlock_rdlock pthread_mutex_lock
100 #define pthread_rwlock_wrlock pthread_mutex_lock
101 #define pthread_rwlock_tryrdlock pthread_mutex_trylock
102 #define pthread_rwlock_trywrlock pthread_mutex_trylock
103
104 pthread_t pthread_self();
105 int pthread_equal(pthread_t t1, pthread_t t2);
106 void pthread_exit(void* ret);
107 int pthread_once(pthread_once_t* once_control, void (*init_routine)(void));
108
109 int pthread_barrier_init(pthread_barrier_t* b, const pthread_barrierattr_t* a, int count);
110 int pthread_barrier_wait(pthread_barrier_t* b);
111 int pthread_barrier_destroy(pthread_barrier_t* b);
112
113 #ifdef __cplusplus
114   }
115 #endif
116
117 #endif