WPILibC++  2019.2.1-25-g182758c
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
pthread-barrier.h
1 /*
2 Copyright (c) 2016, Kari Tristan Helgason <kthelgason@gmail.com>
3 
4 Permission to use, copy, modify, and/or distribute this software for any
5 purpose with or without fee is hereby granted, provided that the above
6 copyright notice and this permission notice appear in all copies.
7 
8 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16 
17 #ifndef _UV_PTHREAD_BARRIER_
18 #define _UV_PTHREAD_BARRIER_
19 #include <errno.h>
20 #include <pthread.h>
21 #if !defined(__MVS__)
22 #include <semaphore.h> /* sem_t */
23 #endif
24 
25 #define PTHREAD_BARRIER_SERIAL_THREAD 0x12345
26 #define UV__PTHREAD_BARRIER_FALLBACK 1
27 
28 /*
29  * To maintain ABI compatibility with
30  * libuv v1.x struct is padded according
31  * to target platform
32  */
33 #if defined(__ANDROID__)
34 # define UV_BARRIER_STRUCT_PADDING \
35  sizeof(pthread_mutex_t) + \
36  sizeof(pthread_cond_t) + \
37  sizeof(unsigned int) - \
38  sizeof(void *)
39 #elif defined(__APPLE__)
40 # define UV_BARRIER_STRUCT_PADDING \
41  sizeof(pthread_mutex_t) + \
42  2 * sizeof(sem_t) + \
43  2 * sizeof(unsigned int) - \
44  sizeof(void *)
45 #else
46 # define UV_BARRIER_STRUCT_PADDING 0
47 #endif
48 
49 typedef struct {
50  pthread_mutex_t mutex;
51  pthread_cond_t cond;
52  unsigned threshold;
53  unsigned in;
54  unsigned out;
55 } _uv_barrier;
56 
57 typedef struct {
58  _uv_barrier* b;
59  char _pad[UV_BARRIER_STRUCT_PADDING];
61 
62 int pthread_barrier_init(pthread_barrier_t* barrier,
63  const void* barrier_attr,
64  unsigned count);
65 
66 int pthread_barrier_wait(pthread_barrier_t* barrier);
67 int pthread_barrier_destroy(pthread_barrier_t *barrier);
68 
69 #endif /* _UV_PTHREAD_BARRIER_ */
Definition: pthread-barrier.h:49
Definition: pthread-barrier.h:57