-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththread.h
45 lines (31 loc) · 871 Bytes
/
thread.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#pragma once
#define attr __attribute__
#include <stdbool.h>
#include <pthread.h>
typedef pthread_mutex_t Mutex;
typedef void *(*ThreadCB)(void *const);
struct thread {
pthread_t thread;
Mutex cancel_mutex;
bool thread_valid;
bool cancel;
ThreadCB func;
void *arg;
} attr((designated_init));
typedef struct thread Thread;
#define AutoThread \
attr((cleanup(thread_cancelp))) Thread
void mutex_destroy(Mutex *const mutex)
attr((nonnull));
bool thread_init(Thread *const self,
ThreadCB func,
void *const arg)
attr((warn_unused_result, nonnull(1,2)));
void thread_cancel(Thread *const self)
attr((nonnull));
void thread_cancelp(Thread **const self)
attr((nonnull));
void thread_waitout(Thread *const self)
attr((nonnull));
void *thread_result(Thread *const self)
attr((warn_unused_result, nonnull));