ARGOBOTS  4dc37e16e1b227a480715ab67dae1dcfb4d2d4e0
mutex_attr.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 
40 {
41  ABTI_UB_ASSERT(ABTI_initialized());
42  ABTI_UB_ASSERT(newattr);
43 
44  ABTI_mutex_attr *p_newattr;
45 
46  int abt_errno = ABTU_malloc(sizeof(ABTI_mutex_attr), (void **)&p_newattr);
47  ABTI_CHECK_ERROR(abt_errno);
48 
49  /* Default values */
50  p_newattr->attrs = ABTI_MUTEX_ATTR_NONE;
51 
52  /* Return value */
53  *newattr = ABTI_mutex_attr_get_handle(p_newattr);
54  return ABT_SUCCESS;
55 }
56 
80 {
81  ABTI_UB_ASSERT(ABTI_initialized());
82  ABTI_UB_ASSERT(attr);
83 
84  ABT_mutex_attr h_attr = *attr;
85  ABTI_mutex_attr *p_attr = ABTI_mutex_attr_get_ptr(h_attr);
86  ABTI_CHECK_NULL_MUTEX_ATTR_PTR(p_attr);
87 
88  /* Free the memory */
89  ABTU_free(p_attr);
90  /* Return value */
91  *attr = ABT_MUTEX_ATTR_NULL;
92  return ABT_SUCCESS;
93 }
94 
121 {
122  ABTI_UB_ASSERT(ABTI_initialized());
123  ABTI_UB_ASSERT_BOOL(recursive);
124 
125  ABTI_mutex_attr *p_attr = ABTI_mutex_attr_get_ptr(attr);
126  ABTI_CHECK_NULL_MUTEX_ATTR_PTR(p_attr);
127 
128  /* Set the value */
129  if (recursive == ABT_TRUE) {
130  p_attr->attrs |= ABTI_MUTEX_ATTR_RECURSIVE;
131  } else {
132  p_attr->attrs &= ~ABTI_MUTEX_ATTR_RECURSIVE;
133  }
134  return ABT_SUCCESS;
135 }
136 
163 {
164  ABTI_UB_ASSERT(ABTI_initialized());
165  ABTI_UB_ASSERT(recursive);
166 
167  ABTI_mutex_attr *p_attr = ABTI_mutex_attr_get_ptr(attr);
168  ABTI_CHECK_NULL_MUTEX_ATTR_PTR(p_attr);
169 
170  /* Get the value */
171  if (p_attr->attrs & ABTI_MUTEX_ATTR_RECURSIVE) {
172  *recursive = ABT_TRUE;
173  } else {
174  *recursive = ABT_FALSE;
175  }
176  return ABT_SUCCESS;
177 }
ABT_bool
int ABT_bool
Boolean type.
Definition: abt.h:1043
abti.h
ABT_mutex_attr
struct ABT_mutex_attr_opaque * ABT_mutex_attr
Mutex attribute handle type.
Definition: abt.h:994
ABTU_malloc
static ABTU_ret_err int ABTU_malloc(size_t size, void **p_ptr)
Definition: abtu.h:235
ABT_mutex_attr_free
int ABT_mutex_attr_free(ABT_mutex_attr *attr)
Free a mutex attribute.
Definition: mutex_attr.c:79
ABT_mutex_attr_set_recursive
int ABT_mutex_attr_set_recursive(ABT_mutex_attr attr, ABT_bool recursive)
Set a recursive property in a mutex attribute.
Definition: mutex_attr.c:120
ABT_SUCCESS
#define ABT_SUCCESS
Error code: the routine returns successfully.
Definition: abt.h:92
ABT_mutex_attr_get_recursive
int ABT_mutex_attr_get_recursive(ABT_mutex_attr attr, ABT_bool *recursive)
Get a recursive property in a mutex attribute.
Definition: mutex_attr.c:162
ABT_TRUE
#define ABT_TRUE
True constant for ABT_bool.
Definition: abt.h:784
ABT_FALSE
#define ABT_FALSE
False constant for ABT_bool.
Definition: abt.h:786
ABTU_free
static void ABTU_free(void *ptr)
Definition: abtu.h:228
ABT_MUTEX_ATTR_NULL
#define ABT_MUTEX_ATTR_NULL
Definition: abt.h:1110
ABT_mutex_attr_create
int ABT_mutex_attr_create(ABT_mutex_attr *newattr)
Create a new mutex attribute.
Definition: mutex_attr.c:39