1/**
2 * hdr_thread.h
3 * Written by Philip Orwig and released to the public domain,
4 * as explained at http://creativecommons.org/publicdomain/zero/1.0/
5 */
6
7#ifndef HDR_THREAD_H__
8#define HDR_THREAD_H__
9
10#include <stdint.h>
11
12#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
13
14
15#define HDR_ALIGN_PREFIX(alignment) __declspec( align(alignment) )
16#define HDR_ALIGN_SUFFIX(alignment)
17
18typedef struct hdr_mutex
19{
20    uint8_t _critical_section[40];
21} hdr_mutex;
22
23#else
24
25#include <pthread.h>
26
27#define HDR_ALIGN_PREFIX(alignment)
28#define HDR_ALIGN_SUFFIX(alignment) __attribute__((aligned(alignment)))
29
30typedef struct hdr_mutex
31{
32    pthread_mutex_t _mutex;
33} hdr_mutex;
34#endif
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40struct hdr_mutex* hdr_mutex_alloc(void);
41void hdr_mutex_free(struct hdr_mutex*);
42
43int hdr_mutex_init(struct hdr_mutex* mutex);
44void hdr_mutex_destroy(struct hdr_mutex* mutex);
45
46void hdr_mutex_lock(struct hdr_mutex* mutex);
47void hdr_mutex_unlock(struct hdr_mutex* mutex);
48
49void hdr_yield();
50int hdr_usleep(unsigned int useconds);
51
52#ifdef __cplusplus
53}
54#endif
55#endif
56