• 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 #if defined(__APPLE__) || (defined(__ANDROID_API__) && __ANDROID_API__ < 24)
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #if !defined(PTHREAD_BARRIER_SERIAL_THREAD)
41 # define PTHREAD_BARRIER_SERIAL_THREAD  (1)
42 #endif
43 
44 #if !defined(PTHREAD_PROCESS_PRIVATE)
45 # define PTHREAD_PROCESS_PRIVATE  (42)
46 #endif
47 #if !defined(PTHREAD_PROCESS_SHARED)
48 # define PTHREAD_PROCESS_SHARED   (43)
49 #endif
50 
51 typedef struct {
52   char noop;
53 } pthread_barrierattr_t;
54 
55 typedef struct {
56   pthread_mutex_t mutex;
57   pthread_cond_t cond;
58   unsigned int limit;
59   unsigned int count;
60   unsigned int phase;
61 } pthread_barrier_t;
62 
63 IW_EXPORT int pthread_barrierattr_init(pthread_barrierattr_t *attr);
64 IW_EXPORT int pthread_barrierattr_destroy(pthread_barrierattr_t *attr);
65 
66 IW_EXPORT int pthread_barrierattr_getpshared(const pthread_barrierattr_t *restrict attr,
67                                              int *restrict pshared);
68 IW_EXPORT int pthread_barrierattr_setpshared(pthread_barrierattr_t *attr,
69                                              int pshared);
70 
71 IW_EXPORT int pthread_barrier_init(pthread_barrier_t *restrict barrier,
72                                    const pthread_barrierattr_t *restrict attr,
73                                    unsigned int count);
74 IW_EXPORT int pthread_barrier_destroy(pthread_barrier_t *barrier);
75 
76 IW_EXPORT int pthread_barrier_wait(pthread_barrier_t *barrier);
77 
78 #ifdef  __cplusplus
79 }
80 #endif
81 
82 #endif /* __APPLE__ */
83 
84 #endif
85