• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2015, Aleksey Demakov
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice, this
9  *   list of conditions and the following disclaimer.
10  *
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  *   this list of conditions and the following disclaimer in the documentation
13  *   and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #pragma once
28 #ifndef IWTH_H
29 #define IWTH_H
30 
31 #include "basedefs.h"
32 #include <pthread.h>
33 
34 IW_EXPORT iwrc iw_cond_timed_wait_ms(
35   pthread_cond_t  *cond,
36   pthread_mutex_t *mtx,
37   long             timeout_ms,
38   bool            *out_is_timeout);
39 
40 #if defined(__APPLE__) || (defined(__ANDROID_API__) && __ANDROID_API__ < 24)
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 #if !defined(PTHREAD_BARRIER_SERIAL_THREAD)
47 # define PTHREAD_BARRIER_SERIAL_THREAD (1)
48 #endif
49 
50 #if !defined(PTHREAD_PROCESS_PRIVATE)
51 # define PTHREAD_PROCESS_PRIVATE (42)
52 #endif
53 #if !defined(PTHREAD_PROCESS_SHARED)
54 # define PTHREAD_PROCESS_SHARED (43)
55 #endif
56 
57 typedef struct {
58   char noop;
59 } pthread_barrierattr_t;
60 
61 typedef struct {
62   pthread_mutex_t mutex;
63   pthread_cond_t  cond;
64   unsigned int    limit;
65   unsigned int    count;
66   unsigned int    phase;
67 } pthread_barrier_t;
68 
69 IW_EXPORT int pthread_barrierattr_init(pthread_barrierattr_t *attr);
70 IW_EXPORT int pthread_barrierattr_destroy(pthread_barrierattr_t *attr);
71 
72 IW_EXPORT int pthread_barrierattr_getpshared(
73   const pthread_barrierattr_t* restrict attr,
74   int* restrict                         pshared);
75 IW_EXPORT int pthread_barrierattr_setpshared(
76   pthread_barrierattr_t *attr,
77   int                    pshared);
78 
79 IW_EXPORT int pthread_barrier_init(
80   pthread_barrier_t* restrict           barrier,
81   const pthread_barrierattr_t* restrict attr,
82   unsigned int                          count);
83 IW_EXPORT int pthread_barrier_destroy(pthread_barrier_t *barrier);
84 
85 IW_EXPORT int pthread_barrier_wait(pthread_barrier_t *barrier);
86 
87 #ifdef  __cplusplus
88 }
89 #endif
90 
91 #endif /* __APPLE__ */
92 
93 #endif
94