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