ARGOBOTS
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 
27 {
28  int abt_errno = ABT_SUCCESS;
29  ABTI_mutex_attr *p_newattr;
30 
31  p_newattr = (ABTI_mutex_attr *)ABTU_malloc(sizeof(ABTI_mutex_attr));
32 
33  /* Default values */
34  p_newattr->attrs = ABTI_MUTEX_ATTR_NONE;
35  p_newattr->nesting_cnt = 0;
36  p_newattr->owner_id = 0;
37  p_newattr->max_handovers = ABTI_global_get_mutex_max_handovers();
38  p_newattr->max_wakeups = ABTI_global_get_mutex_max_wakeups();
39 
40  /* Return value */
41  *newattr = ABTI_mutex_attr_get_handle(p_newattr);
42 
43  return abt_errno;
44 }
45 
59 {
60  int abt_errno = ABT_SUCCESS;
61  ABT_mutex_attr h_attr = *attr;
62  ABTI_mutex_attr *p_attr = ABTI_mutex_attr_get_ptr(h_attr);
63  ABTI_CHECK_NULL_MUTEX_ATTR_PTR(p_attr);
64 
65  /* Free the memory */
66  ABTU_free(p_attr);
67 
68  /* Return value */
69  *attr = ABT_MUTEX_ATTR_NULL;
70 
71 fn_exit:
72  return abt_errno;
73 
74 fn_fail:
75  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
76  goto fn_exit;
77 }
78 
93 {
94  int abt_errno = ABT_SUCCESS;
95  ABTI_mutex_attr *p_attr = ABTI_mutex_attr_get_ptr(attr);
96  ABTI_CHECK_NULL_MUTEX_ATTR_PTR(p_attr);
97 
98  /* Set the value */
99  if (recursive == ABT_TRUE) {
100  p_attr->attrs |= ABTI_MUTEX_ATTR_RECURSIVE;
101  } else {
102  p_attr->attrs &= ~ABTI_MUTEX_ATTR_RECURSIVE;
103  }
104 
105 fn_exit:
106  return abt_errno;
107 
108 fn_fail:
109  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
110  goto fn_exit;
111 }
112 
113 /*****************************************************************************/
114 /* Private APIs */
115 /*****************************************************************************/
116 
117 void ABTI_mutex_attr_print(ABTI_mutex_attr *p_attr, FILE *p_os, int indent)
118 {
119  char *prefix = ABTU_get_indent_str(indent);
120  char attr[100];
121 
122  ABTI_mutex_attr_get_str(p_attr, attr);
123  fprintf(p_os, "%smutex attr: %s\n", prefix, attr);
124  fflush(p_os);
125  ABTU_free(prefix);
126 }
127 
128 void ABTI_mutex_attr_get_str(ABTI_mutex_attr *p_attr, char *p_buf)
129 {
130  if (p_attr == NULL) {
131  sprintf(p_buf, "[NULL ATTR]");
132  return;
133  }
134 
135  sprintf(p_buf,
136  "["
137  "attrs:%x "
138  "nesting_cnt:%u "
139  "owner_id:%p "
140  "]",
141  p_attr->attrs, p_attr->nesting_cnt, (void *)p_attr->owner_id);
142 }
#define ABT_MUTEX_ATTR_NULL
Definition: abt.h:349
struct ABT_mutex_attr_opaque * ABT_mutex_attr
Definition: abt.h:295
char * ABTU_get_indent_str(int indent)
Definition: util.c:12
static void * ABTU_malloc(size_t size)
Definition: abtu.h:39
int ABT_bool
Definition: abt.h:309
#define HANDLE_ERROR_FUNC_WITH_CODE(n)
Definition: abti_error.h:241
#define ABT_SUCCESS
Definition: abt.h:64
#define ABT_TRUE
Definition: abt.h:223
int ABT_mutex_attr_set_recursive(ABT_mutex_attr attr, ABT_bool recursive)
Set the recursive property in the attribute object.
Definition: mutex_attr.c:92
int ABT_mutex_attr_free(ABT_mutex_attr *attr)
Free the mutex attribute object.
Definition: mutex_attr.c:58
int ABT_mutex_attr_create(ABT_mutex_attr *newattr)
Create a new mutex attribute object.
Definition: mutex_attr.c:26
static void ABTU_free(void *ptr)
Definition: abtu.h:32