ARGOBOTS
rwlock.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_rwlock *p_newrwlock;
30 
31  p_newrwlock = (ABTI_rwlock *)ABTU_malloc(sizeof(ABTI_rwlock));
32  if (p_newrwlock == NULL) {
33  abt_errno = ABT_ERR_MEM;
34  } else {
35  ABTI_rwlock_init(p_newrwlock);
36  }
37 
38  /* Return value */
39  *newrwlock = ABTI_rwlock_get_handle(p_newrwlock);
40 
41  return abt_errno;
42 }
43 
60 {
61  int abt_errno = ABT_SUCCESS;
62  ABT_rwlock h_rwlock = *rwlock;
63  ABTI_rwlock *p_rwlock = ABTI_rwlock_get_ptr(h_rwlock);
64  ABTI_CHECK_NULL_RWLOCK_PTR(p_rwlock);
65 
66  ABTI_rwlock_fini(p_rwlock);
67  ABTU_free(p_rwlock);
68 
69  /* Return value */
70  *rwlock = ABT_RWLOCK_NULL;
71 
72 fn_exit:
73  return abt_errno;
74 
75 fn_fail:
76  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
77  goto fn_exit;
78 }
79 
99 {
100  int abt_errno = ABT_SUCCESS;
101  ABTI_local *p_local = ABTI_local_get_local();
102  ABTI_rwlock *p_rwlock = ABTI_rwlock_get_ptr(rwlock);
103  ABTI_CHECK_NULL_RWLOCK_PTR(p_rwlock);
104 
105  ABTI_rwlock_rdlock(&p_local, p_rwlock);
106 
107 fn_exit:
108  return abt_errno;
109 
110 fn_fail:
111  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
112  goto fn_exit;
113 }
114 
133 {
134  int abt_errno = ABT_SUCCESS;
135  ABTI_local *p_local = ABTI_local_get_local();
136  ABTI_rwlock *p_rwlock = ABTI_rwlock_get_ptr(rwlock);
137  ABTI_CHECK_NULL_RWLOCK_PTR(p_rwlock);
138 
139  ABTI_rwlock_wrlock(&p_local, p_rwlock);
140 
141 fn_exit:
142  return abt_errno;
143 
144 fn_fail:
145  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
146  goto fn_exit;
147 }
148 
163 {
164  int abt_errno = ABT_SUCCESS;
165  ABTI_local *p_local = ABTI_local_get_local();
166  ABTI_rwlock *p_rwlock = ABTI_rwlock_get_ptr(rwlock);
167  ABTI_CHECK_NULL_RWLOCK_PTR(p_rwlock);
168 
169  ABTI_rwlock_unlock(&p_local, p_rwlock);
170 
171 fn_exit:
172  return abt_errno;
173 
174 fn_fail:
175  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
176  goto fn_exit;
177 }
int ABT_rwlock_create(ABT_rwlock *newrwlock)
Create a new rwlock ABT_rwlock_create creates a new rwlock object and returns its handle through newr...
Definition: rwlock.c:26
static void * ABTU_malloc(size_t size)
Definition: abtu.h:39
int ABT_rwlock_unlock(ABT_rwlock rwlock)
Unlock the rwlock.
Definition: rwlock.c:162
struct ABT_rwlock_opaque * ABT_rwlock
Definition: abt.h:299
int ABT_rwlock_free(ABT_rwlock *rwlock)
Free the rwlock object.
Definition: rwlock.c:59
#define HANDLE_ERROR_FUNC_WITH_CODE(n)
Definition: abti_error.h:241
int ABT_rwlock_wrlock(ABT_rwlock rwlock)
Lock the rwlock as a writer.
Definition: rwlock.c:132
#define ABT_ERR_MEM
Definition: abt.h:66
#define ABT_SUCCESS
Definition: abt.h:64
#define ABT_RWLOCK_NULL
Definition: abt.h:351
int ABT_rwlock_rdlock(ABT_rwlock rwlock)
Lock the rwlock as a reader.
Definition: rwlock.c:98
static void ABTU_free(void *ptr)
Definition: abtu.h:32