blob: 897a333573e88263b6ba58ec3d31031304c50e54 [file] [log] [blame]
Austin Schuh3333ec72022-12-29 16:21:06 -08001/**
2Copyright John Schember <john@nachtimwald.com>
3
4Permission is hereby granted, free of charge, to any person obtaining a copy of
5this software and associated documentation files (the "Software"), to deal in
6the Software without restriction, including without limitation the rights to
7use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8of the Software, and to permit persons to whom the Software is furnished to do
9so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in all
12copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20SOFTWARE.
21*/
22
23#ifndef __CPTHREAD_H__
24#define __CPTHREAD_H__
25
26#ifdef _WIN32
27#include <stdbool.h>
28#include <windows.h>
29#else
30#include <pthread.h>
31#include <sched.h>
32#endif
33
34#ifdef _WIN32
35
36typedef CRITICAL_SECTION pthread_mutex_t;
37typedef void pthread_mutexattr_t;
38typedef void pthread_attr_t;
39typedef void pthread_condattr_t;
40typedef void pthread_rwlockattr_t;
41typedef HANDLE pthread_t;
42typedef CONDITION_VARIABLE pthread_cond_t;
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47int pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *), void *arg);
48int pthread_join(pthread_t thread, void **value_ptr);
49int pthread_detach(pthread_t);
50
51int pthread_mutex_init(pthread_mutex_t *mutex, pthread_mutexattr_t *attr);
52int pthread_mutex_destroy(pthread_mutex_t *mutex);
53int pthread_mutex_lock(pthread_mutex_t *mutex);
54int pthread_mutex_unlock(pthread_mutex_t *mutex);
55
56int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *attr);
57int pthread_cond_destroy(pthread_cond_t *cond);
58int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
59int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime);
60int pthread_cond_signal(pthread_cond_t *cond);
61int pthread_cond_broadcast(pthread_cond_t *cond);
62
63int sched_yield(void);
64#ifdef __cplusplus
65}
66#endif
67#endif
68
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73unsigned int pcthread_get_num_procs();
74
75void ms_to_timespec(struct timespec *ts, unsigned int ms);
76unsigned int timespec_to_ms(const struct timespec *abstime);
77#ifdef __cplusplus
78}
79#endif
80
81#endif /* __CPTHREAD_H__ */