ARGOBOTS  1227c643f7a7f974f1f1778a9ffebd29d7dafecf
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
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 
26 int ABT_xstream_barrier_create(uint32_t num_waiters,
27  ABT_xstream_barrier *newbarrier)
28 {
29 #ifdef HAVE_PTHREAD_BARRIER_INIT
30  int abt_errno = ABT_SUCCESS;
31  ABTI_xstream_barrier *p_newbarrier;
32 
33  abt_errno =
34  ABTU_malloc(sizeof(ABTI_xstream_barrier), (void **)&p_newbarrier);
35  ABTI_CHECK_ERROR(abt_errno);
36 
37  p_newbarrier->num_waiters = num_waiters;
38  abt_errno = ABTD_xstream_barrier_init(num_waiters, &p_newbarrier->bar);
39  if (ABTI_IS_ERROR_CHECK_ENABLED && abt_errno != ABT_SUCCESS) {
40  ABTU_free(p_newbarrier);
41  goto fn_fail;
42  }
43 
44  /* Return value */
45  *newbarrier = ABTI_xstream_barrier_get_handle(p_newbarrier);
46 
47 fn_exit:
48  return abt_errno;
49 
50 fn_fail:
51  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
52  goto fn_exit;
53 #else
55 #endif
56 }
57 
71 {
72 #ifdef HAVE_PTHREAD_BARRIER_INIT
73  int abt_errno = ABT_SUCCESS;
74  ABT_xstream_barrier h_barrier = *barrier;
75  ABTI_xstream_barrier *p_barrier = ABTI_xstream_barrier_get_ptr(h_barrier);
77 
78  ABTD_xstream_barrier_destroy(&p_barrier->bar);
79  ABTU_free(p_barrier);
80 
81  /* Return value */
82  *barrier = ABT_XSTREAM_BARRIER_NULL;
83 
84 fn_exit:
85  return abt_errno;
86 
87 fn_fail:
88  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
89  goto fn_exit;
90 #else
92 #endif
93 }
94 
107 {
108 #ifdef HAVE_PTHREAD_BARRIER_INIT
109  int abt_errno = ABT_SUCCESS;
110  ABTI_xstream_barrier *p_barrier = ABTI_xstream_barrier_get_ptr(barrier);
112 
113  if (p_barrier->num_waiters > 1) {
114  ABTD_xstream_barrier_wait(&p_barrier->bar);
115  }
116 
117 fn_exit:
118  return abt_errno;
119 
120 fn_fail:
121  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
122  goto fn_exit;
123 #else
125 #endif
126 }
ABTD_xstream_barrier bar
Definition: abti.h:420
int ABT_xstream_barrier_create(uint32_t num_waiters, ABT_xstream_barrier *newbarrier) ABT_API_PUBLIC
Create a new ES barrier.
uint32_t num_waiters
Definition: abti.h:419
static ABTU_ret_err int ABTU_malloc(size_t size, void **p_ptr)
Definition: abtu.h:142
int ABT_xstream_barrier_wait(ABT_xstream_barrier barrier) ABT_API_PUBLIC
Wait on the barrier.
#define HANDLE_ERROR_FUNC_WITH_CODE(n)
Definition: abti_error.h:353
#define ABT_SUCCESS
Definition: abt.h:64
struct ABT_xstream_barrier_opaque * ABT_xstream_barrier
Definition: abt.h:317
#define ABTI_CHECK_NULL_XSTREAM_BARRIER_PTR(p)
Definition: abti_error.h:299
#define HANDLE_ERROR_FUNC_WITH_CODE_RET(n)
Definition: abti_error.h:361
#define ABT_ERR_FEATURE_NA
Definition: abt.h:116
#define ABTI_CHECK_ERROR(abt_errno)
Definition: abti_error.h:86
int ABT_xstream_barrier_free(ABT_xstream_barrier *barrier) ABT_API_PUBLIC
Free the ES barrier.
#define ABT_XSTREAM_BARRIER_NULL
Definition: abt.h:410
#define ABTI_IS_ERROR_CHECK_ENABLED
Definition: abti.h:20
static void ABTU_free(void *ptr)
Definition: abtu.h:135