cu
sync.h
Go to the documentation of this file.
1 #ifndef CU_SYNC
2 #define CU_SYNC
3 #include<pthread.h>
4 
16 typedef struct {
17  pthread_mutex_t mutex;
18  void *inner;
19 } mutex_t;
20 
21 
35 extern mutex_t cu_mutex_new(void *inner);
36 
37 
42 extern void cu_mutex_del(mutex_t *mutex, void (*del)(void *));
43 
49 extern void *cu_lock(mutex_t *mutex);
50 
51 
56 extern void cu_unlock(mutex_t *mutex);
57 
58 
59 typedef struct {
60  pthread_t thread;
61  pthread_attr_t attr;
62  void *(*handle)();
63  void *args;
64 } thread_t;
65 
66 
73 extern thread_t cu_thread_new(void *(*handle)(), void *args);
74 
75 
80 extern void cu_spawn(thread_t *thread);
81 
82 
88 extern void *cu_join(thread_t *thread);
89 
95 extern void mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr);
96 
97 
102 extern void mutex_lock(pthread_mutex_t *mutex);
103 
104 
109 extern void mutex_unlock(pthread_mutex_t *mutex);
110 
111 
116 extern void mutex_destroy(pthread_mutex_t *mutex);
117 
118 
126 extern void thread_new(pthread_t *thread, const pthread_attr_t *attr, void *(*handle)(void *), void *arg);
127 
128 
133 extern void thread_exit(void *retval);
134 
135 
141 extern void thread_join(pthread_t thread, void **retval);
142 
143 
148 extern void thread_cancel(pthread_t thread);
149 
150 
151 extern void attr_init(pthread_attr_t *attr);
152 extern void attr_destory(pthread_attr_t *attr);
153 
154 #endif /* ifndef CU_SYNC */
Definition: sync.h:59
void * cu_join(thread_t *thread)
Join a thread.
void thread_exit(void *retval)
Wrapper around pthread_exit()
void mutex_unlock(pthread_mutex_t *mutex)
Wrapper around pthread_mutex_unlock() with error handling.
thread_t cu_thread_new(void *(*handle)(), void *args)
Create a thread_t structur.
void mutex_destroy(pthread_mutex_t *mutex)
Wrapper around pthread_mutex_destroy() with error handling.
void mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr)
Wrapper around pthread_mutex_init() with error handling.
void thread_join(pthread_t thread, void **retval)
Wrapper around pthread_join() with error handling.
void mutex_lock(pthread_mutex_t *mutex)
Wrapper around pthread_mutex_lock() with error handling.
void * cu_lock(mutex_t *mutex)
lock the mutex and get access to the data
void thread_new(pthread_t *thread, const pthread_attr_t *attr, void *(*handle)(void *), void *arg)
Wrapper around pthread_thread_create() with error handling.
Definition: sync.h:16
mutex_t cu_mutex_new(void *inner)
Initialize a CU mutex.
void cu_unlock(mutex_t *mutex)
Unlock a mutex_t object.
void thread_cancel(pthread_t thread)
Wrapper around pthread_cancel() with error handling.
void cu_mutex_del(mutex_t *mutex, void(*del)(void *))
Destroy a cu mutex_t object and the data.
void cu_spawn(thread_t *thread)
Spawn a new thread.