-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmingw_threads.h
More file actions
67 lines (55 loc) · 1.36 KB
/
Copy pathmingw_threads.h
File metadata and controls
67 lines (55 loc) · 1.36 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
Copyright (C) 2020- TheTrustedComputer
A compatibility layer that maps the C11 thread functions to POSIX threads for use with MinGW.
We will only implement a subset of the functions we need; support for others is not provided.
*/
#ifndef MINGW_THREADS_H
#define MINGW_THREADS_H
#include <sched.h>
#include <errno.h>
#include <pthread.h>
// Aliases
typedef pthread_t thrd_t;
typedef pthread_mutex_t mtx_t;
typedef pthread_cond_t cnd_t;
typedef int(thrd_start_t)(void*);
// Mutex types
enum
{
mtx_plain = 1,
mtx_timed = 2,
mtx_recursive = 4
};
// Thread error status
enum
{
thrd_success,
thrd_error,
thrd_nomem,
};
// Structure to pass arguments expected by C11 threads
typedef struct
{
thrd_start_t *func;
void *arg;
}
thrd_start_wrapper_arg_t;
// Thread functions
int thrd_create(thrd_t*, thrd_start_t*, void*);
int thrd_join(thrd_t, int*);
int thrd_sleep(const struct timespec*, struct timespec*);
void thrd_yield(void);
// Wrapper function; C11 threads return an int instead of a void pointer
void *thrd_start_wrapper(void*);
// Mutual exclusion
int mtx_init(mtx_t*, int);
void mtx_destroy(mtx_t*);
int mtx_lock(mtx_t*);
int mtx_unlock(mtx_t*);
// Condition variables
int cnd_init(cnd_t*);
void cnd_destroy(cnd_t*);
int cnd_signal(cnd_t*);
int cnd_broadcast(cnd_t*);
int cnd_wait(cnd_t*, mtx_t*);
#endif /* MINGW_THREADS_H */