ARGOBOTS  7496202f85916e93d6d143320764c2aba5026d93
 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;
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  ABTI_HANDLE_ERROR(abt_errno);
42  }
43 
44  /* Return value */
45  *newbarrier = ABTI_xstream_barrier_get_handle(p_newbarrier);
46  return ABT_SUCCESS;
47 #else
48  ABTI_HANDLE_ERROR(ABT_ERR_FEATURE_NA);
49 #endif
50 }
51 
65 {
66 #ifdef HAVE_PTHREAD_BARRIER_INIT
67  ABT_xstream_barrier h_barrier = *barrier;
68  ABTI_xstream_barrier *p_barrier = ABTI_xstream_barrier_get_ptr(h_barrier);
69  ABTI_CHECK_NULL_XSTREAM_BARRIER_PTR(p_barrier);
70 
71  ABTD_xstream_barrier_destroy(&p_barrier->bar);
72  ABTU_free(p_barrier);
73 
74  /* Return value */
75  *barrier = ABT_XSTREAM_BARRIER_NULL;
76  return ABT_SUCCESS;
77 #else
78  ABTI_HANDLE_ERROR(ABT_ERR_FEATURE_NA);
79 #endif
80 }
81 
94 {
95 #ifdef HAVE_PTHREAD_BARRIER_INIT
96  ABTI_xstream_barrier *p_barrier = ABTI_xstream_barrier_get_ptr(barrier);
97  ABTI_CHECK_NULL_XSTREAM_BARRIER_PTR(p_barrier);
98 
99  if (p_barrier->num_waiters > 1) {
100  ABTD_xstream_barrier_wait(&p_barrier->bar);
101  }
102  return ABT_SUCCESS;
103 #else
104  ABTI_HANDLE_ERROR(ABT_ERR_FEATURE_NA);
105 #endif
106 }
int ABT_xstream_barrier_create(uint32_t num_waiters, ABT_xstream_barrier *newbarrier) ABT_API_PUBLIC
Create a new ES barrier.
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 ABT_SUCCESS
Definition: abt.h:64
struct ABT_xstream_barrier_opaque * ABT_xstream_barrier
Definition: abt.h:317
#define ABT_ERR_FEATURE_NA
Definition: abt.h:116
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
static void ABTU_free(void *ptr)
Definition: abtu.h:135