ARGOBOTS
stream_barrier.c
Go to the documentation of this file.
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  * See COPYRIGHT in top-level directory.
4  */
5 
6 #include "abti.h"
7 
12 typedef struct {
13  uint32_t num_waiters;
14  ABTD_xstream_barrier bar;
15 } ABTI_xstream_barrier;
16 
17 #ifdef HAVE_PTHREAD_BARRIER_INIT
18 static inline ABTI_xstream_barrier *
19 ABTI_xstream_barrier_get_ptr(ABT_xstream_barrier barrier)
20 {
21 #ifndef ABT_CONFIG_DISABLE_ERROR_CHECK
22  ABTI_xstream_barrier *p_barrier;
23  if (barrier == ABT_XSTREAM_BARRIER_NULL) {
24  p_barrier = NULL;
25  } else {
26  p_barrier = (ABTI_xstream_barrier *)barrier;
27  }
28  return p_barrier;
29 #else
30  return (ABTI_xstream_barrier *)barrier;
31 #endif
32 }
33 
34 static inline ABT_xstream_barrier
35 ABTI_xstream_barrier_get_handle(ABTI_xstream_barrier *p_barrier)
36 {
37 #ifndef ABT_CONFIG_DISABLE_ERROR_CHECK
38  ABT_xstream_barrier h_barrier;
39  if (p_barrier == NULL) {
40  h_barrier = ABT_XSTREAM_BARRIER_NULL;
41  } else {
42  h_barrier = (ABT_xstream_barrier)p_barrier;
43  }
44  return h_barrier;
45 #else
46  return (ABT_xstream_barrier)p_barrier;
47 #endif
48 }
49 #endif
50 
65 int ABT_xstream_barrier_create(uint32_t num_waiters,
66  ABT_xstream_barrier *newbarrier)
67 {
68 #ifdef HAVE_PTHREAD_BARRIER_INIT
69  int abt_errno = ABT_SUCCESS;
70  ABTI_xstream_barrier *p_newbarrier;
71 
72  p_newbarrier =
73  (ABTI_xstream_barrier *)ABTU_malloc(sizeof(ABTI_xstream_barrier));
74 
75  p_newbarrier->num_waiters = num_waiters;
76  abt_errno = ABTD_xstream_barrier_init(num_waiters, &p_newbarrier->bar);
77  ABTI_CHECK_ERROR(abt_errno);
78 
79  /* Return value */
80  *newbarrier = ABTI_xstream_barrier_get_handle(p_newbarrier);
81 
82 fn_exit:
83  return abt_errno;
84 
85 fn_fail:
86  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
87  goto fn_exit;
88 #else
89  return ABT_ERR_FEATURE_NA;
90 #endif
91 }
92 
106 {
107 #ifdef HAVE_PTHREAD_BARRIER_INIT
108  int abt_errno = ABT_SUCCESS;
109  ABT_xstream_barrier h_barrier = *barrier;
110  ABTI_xstream_barrier *p_barrier = ABTI_xstream_barrier_get_ptr(h_barrier);
111  ABTI_CHECK_NULL_XSTREAM_BARRIER_PTR(p_barrier);
112 
113  abt_errno = ABTD_xstream_barrier_destroy(&p_barrier->bar);
114  ABTI_CHECK_ERROR(abt_errno);
115 
116  ABTU_free(p_barrier);
117 
118  /* Return value */
119  *barrier = ABT_XSTREAM_BARRIER_NULL;
120 
121 fn_exit:
122  return abt_errno;
123 
124 fn_fail:
125  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
126  goto fn_exit;
127 #else
128  return ABT_ERR_FEATURE_NA;
129 #endif
130 }
131 
144 {
145 #ifdef HAVE_PTHREAD_BARRIER_INIT
146  int abt_errno = ABT_SUCCESS;
147  ABTI_xstream_barrier *p_barrier = ABTI_xstream_barrier_get_ptr(barrier);
148  ABTI_CHECK_NULL_XSTREAM_BARRIER_PTR(p_barrier);
149 
150  if (p_barrier->num_waiters > 1) {
151  ABTD_xstream_barrier_wait(&p_barrier->bar);
152  }
153 
154 fn_exit:
155  return abt_errno;
156 
157 fn_fail:
158  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
159  goto fn_exit;
160 #else
161  return ABT_ERR_FEATURE_NA;
162 #endif
163 }
int ABT_xstream_barrier_create(uint32_t num_waiters, ABT_xstream_barrier *newbarrier)
Create a new ES barrier.
static void * ABTU_malloc(size_t size)
Definition: abtu.h:39
int ABT_xstream_barrier_wait(ABT_xstream_barrier barrier)
Wait on the barrier.
#define HANDLE_ERROR_FUNC_WITH_CODE(n)
Definition: abti_error.h:241
#define ABT_SUCCESS
Definition: abt.h:64
struct ABT_xstream_barrier_opaque * ABT_xstream_barrier
Definition: abt.h:255
#define ABT_ERR_FEATURE_NA
Definition: abt.h:115
int ABT_xstream_barrier_free(ABT_xstream_barrier *barrier)
Free the ES barrier.
#define ABT_XSTREAM_BARRIER_NULL
Definition: abt.h:338
static void ABTU_free(void *ptr)
Definition: abtu.h:32