ARGOBOTS  1227c643f7a7f974f1f1778a9ffebd29d7dafecf
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
thread_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_thread_attr *p_newattr;
30 
31  abt_errno = ABTU_malloc(sizeof(ABTI_thread_attr), (void **)&p_newattr);
32  ABTI_CHECK_ERROR(abt_errno);
33 
34  /* Default values */
35  ABTI_thread_attr_init(p_newattr, NULL, gp_ABTI_global->thread_stacksize,
36  ABTI_THREAD_TYPE_MEM_MEMPOOL_DESC_STACK, ABT_TRUE);
37 
38  /* Return value */
39  *newattr = ABTI_thread_attr_get_handle(p_newattr);
40 
41 fn_exit:
42  return abt_errno;
43 
44 fn_fail:
45  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
46  goto fn_exit;
47 }
48 
62 {
63  int abt_errno = ABT_SUCCESS;
64  ABT_thread_attr h_attr = *attr;
65  ABTI_thread_attr *p_attr = ABTI_thread_attr_get_ptr(h_attr);
66  ABTI_CHECK_NULL_THREAD_ATTR_PTR(p_attr);
67 
68  /* Free the memory */
69  ABTU_free(p_attr);
70 
71  /* Return value */
72  *attr = ABT_THREAD_ATTR_NULL;
73 
74 fn_exit:
75  return abt_errno;
76 
77 fn_fail:
78  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
79  goto fn_exit;
80 }
81 
103 int ABT_thread_attr_set_stack(ABT_thread_attr attr, void *stackaddr,
104  size_t stacksize)
105 {
106  int abt_errno = ABT_SUCCESS;
107  ABTI_thread_attr *p_attr = ABTI_thread_attr_get_ptr(attr);
108  ABTI_CHECK_NULL_THREAD_ATTR_PTR(p_attr);
109 
110  ABTI_thread_type new_thread_type;
111  if (stackaddr != NULL) {
112  if (((uintptr_t)stackaddr & 0x7) != 0) {
113  abt_errno = ABT_ERR_OTHER;
114  goto fn_fail;
115  }
116  new_thread_type = ABTI_THREAD_TYPE_MEM_MEMPOOL_DESC;
117  } else {
118  if (stacksize == gp_ABTI_global->thread_stacksize) {
119  new_thread_type = ABTI_THREAD_TYPE_MEM_MEMPOOL_DESC_STACK;
120  } else {
121  new_thread_type = ABTI_THREAD_TYPE_MEM_MALLOC_DESC_STACK;
122  }
123  }
124  /* Unset the stack type and set new_thread_type. */
125  p_attr->thread_type &= ~ABTI_THREAD_TYPES_MEM;
126  p_attr->thread_type |= new_thread_type;
127 
128  p_attr->p_stack = stackaddr;
129  p_attr->stacksize = stacksize;
130 
131 fn_exit:
132  return abt_errno;
133 
134 fn_fail:
135  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
136  goto fn_exit;
137 }
138 
155 int ABT_thread_attr_get_stack(ABT_thread_attr attr, void **stackaddr,
156  size_t *stacksize)
157 {
158  int abt_errno = ABT_SUCCESS;
159  ABTI_thread_attr *p_attr = ABTI_thread_attr_get_ptr(attr);
160  ABTI_CHECK_NULL_THREAD_ATTR_PTR(p_attr);
161 
162  *stackaddr = p_attr->p_stack;
163  *stacksize = p_attr->stacksize;
164 
165 fn_exit:
166  return abt_errno;
167 
168 fn_fail:
169  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
170  goto fn_exit;
171 }
172 
186 {
187  int abt_errno = ABT_SUCCESS;
188  ABTI_thread_attr *p_attr = ABTI_thread_attr_get_ptr(attr);
189  ABTI_CHECK_NULL_THREAD_ATTR_PTR(p_attr);
190 
191  /* Set the value */
192  p_attr->stacksize = stacksize;
193  ABTI_thread_type new_thread_type;
194  if (stacksize == gp_ABTI_global->thread_stacksize) {
195  new_thread_type = ABTI_THREAD_TYPE_MEM_MEMPOOL_DESC_STACK;
196  } else {
197  new_thread_type = ABTI_THREAD_TYPE_MEM_MEMPOOL_DESC_STACK;
198  }
199  /* Unset the stack type and set new_thread_type. */
200  p_attr->thread_type &= ~ABTI_THREAD_TYPES_MEM;
201  p_attr->thread_type |= new_thread_type;
202 
203 fn_exit:
204  return abt_errno;
205 
206 fn_fail:
207  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
208  goto fn_exit;
209 }
210 
223 int ABT_thread_attr_get_stacksize(ABT_thread_attr attr, size_t *stacksize)
224 {
225  int abt_errno = ABT_SUCCESS;
226  ABTI_thread_attr *p_attr = ABTI_thread_attr_get_ptr(attr);
227  ABTI_CHECK_NULL_THREAD_ATTR_PTR(p_attr);
228 
229  *stacksize = p_attr->stacksize;
230 
231 fn_exit:
232  return abt_errno;
233 
234 fn_fail:
235  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
236  goto fn_exit;
237 }
238 
253  void (*cb_func)(ABT_thread thread,
254  void *cb_arg),
255  void *cb_arg)
256 {
257 #ifndef ABT_CONFIG_DISABLE_MIGRATION
258  int abt_errno = ABT_SUCCESS;
259  ABTI_thread_attr *p_attr = ABTI_thread_attr_get_ptr(attr);
260  ABTI_CHECK_NULL_THREAD_ATTR_PTR(p_attr);
261 
262  /* Set the value */
263  p_attr->f_cb = cb_func;
264  p_attr->p_cb_arg = cb_arg;
265 
266 fn_exit:
267  return abt_errno;
268 
269 fn_fail:
270  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
271  goto fn_exit;
272 #else
274 #endif
275 }
276 
294 {
295 #ifndef ABT_CONFIG_DISABLE_MIGRATION
296  int abt_errno = ABT_SUCCESS;
297  ABTI_thread_attr *p_attr = ABTI_thread_attr_get_ptr(attr);
298  ABTI_CHECK_NULL_THREAD_ATTR_PTR(p_attr);
299 
300  /* Set the value */
301  p_attr->migratable = flag;
302 
303 fn_exit:
304  return abt_errno;
305 
306 fn_fail:
307  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
308  goto fn_exit;
309 #else
311 #endif
312 }
313 
314 /*****************************************************************************/
315 /* Private APIs */
316 /*****************************************************************************/
317 
318 void ABTI_thread_attr_print(ABTI_thread_attr *p_attr, FILE *p_os, int indent)
319 {
320  if (p_attr == NULL) {
321  fprintf(p_os, "%*sULT attr: [NULL ATTR]\n", indent, "");
322  } else {
323  char *stacktype;
324  if (p_attr->thread_type & ABTI_THREAD_TYPE_MEM_MEMPOOL_DESC) {
325  stacktype = "MEMPOOL_DESC";
326  } else if (p_attr->thread_type & ABTI_THREAD_TYPE_MEM_MALLOC_DESC) {
327  stacktype = "MALLOC_DESC";
328  } else if (p_attr->thread_type &
329  ABTI_THREAD_TYPE_MEM_MEMPOOL_DESC_STACK) {
330  stacktype = "MEMPOOL_DESC_STACK";
331  } else if (p_attr->thread_type &
332  ABTI_THREAD_TYPE_MEM_MALLOC_DESC_STACK) {
333  stacktype = "MALLOC_DESC_STACK";
334  } else {
335  stacktype = "UNKNOWN";
336  }
337 #ifndef ABT_CONFIG_DISABLE_MIGRATION
338  fprintf(p_os,
339  "%*sULT attr: ["
340  "stack:%p "
341  "stacksize:%zu "
342  "stacktype:%s "
343  "migratable:%s "
344  "cb_arg:%p"
345  "]\n",
346  indent, "", p_attr->p_stack, p_attr->stacksize, stacktype,
347  (p_attr->migratable == ABT_TRUE ? "TRUE" : "FALSE"),
348  p_attr->p_cb_arg);
349 #else
350  fprintf(p_os,
351  "%*sULT attr: ["
352  "stack:%p "
353  "stacksize:%zu "
354  "stacktype:%s "
355  "]\n",
356  indent, "", p_attr->p_stack, p_attr->stacksize, stacktype);
357 #endif
358  }
359  fflush(p_os);
360 }
361 
362 ABTU_ret_err int ABTI_thread_attr_dup(const ABTI_thread_attr *p_attr,
363  ABTI_thread_attr **pp_dup_attr)
364 {
365  ABTI_thread_attr *p_dup_attr;
366 
367  int abt_errno = ABTU_malloc(sizeof(ABTI_thread_attr), (void **)&p_dup_attr);
368  ABTI_CHECK_ERROR_RET(abt_errno);
369  memcpy(p_dup_attr, p_attr, sizeof(ABTI_thread_attr));
370  *pp_dup_attr = p_dup_attr;
371  return ABT_SUCCESS;
372 }
struct ABT_thread_attr_opaque * ABT_thread_attr
Definition: abt.h:345
int ABT_thread_attr_set_stacksize(ABT_thread_attr attr, size_t stacksize) ABT_API_PUBLIC
Set the stack size in the attribute object.
Definition: thread_attr.c:185
int ABT_thread_attr_set_stack(ABT_thread_attr attr, void *stackaddr, size_t stacksize) ABT_API_PUBLIC
Set stack attributes.
Definition: thread_attr.c:103
int ABT_thread_attr_set_migratable(ABT_thread_attr attr, ABT_bool flag) ABT_API_PUBLIC
Set the ULT's migratability in the attribute object.
Definition: thread_attr.c:293
int ABT_thread_attr_get_stacksize(ABT_thread_attr attr, size_t *stacksize) ABT_API_PUBLIC
Get the stack size from the attribute object.
Definition: thread_attr.c:223
int ABT_thread_attr_set_callback(ABT_thread_attr attr, void(*cb_func)(ABT_thread thread, void *cb_arg), void *cb_arg) ABT_API_PUBLIC
Set callback function and its argument in the attribute object.
Definition: thread_attr.c:252
int ABT_bool
Definition: abt.h:373
#define ABT_ERR_OTHER
Definition: abt.h:67
static ABTU_ret_err int ABTU_malloc(size_t size, void **p_ptr)
Definition: abtu.h:142
int ABT_thread_attr_create(ABT_thread_attr *newattr) ABT_API_PUBLIC
Create a new ULT attribute object.
Definition: thread_attr.c:26
struct ABT_thread_opaque * ABT_thread
Definition: abt.h:343
#define HANDLE_ERROR_FUNC_WITH_CODE(n)
Definition: abti_error.h:353
ABTI_global * gp_ABTI_global
Definition: global.c:14
#define ABT_SUCCESS
Definition: abt.h:64
#define ABT_TRUE
Definition: abt.h:284
#define ABT_THREAD_ATTR_NULL
Definition: abt.h:417
int ABT_thread_attr_get_stack(ABT_thread_attr attr, void **stackaddr, size_t *stacksize) ABT_API_PUBLIC
Get stack attributes.
Definition: thread_attr.c:155
int ABT_thread_attr_free(ABT_thread_attr *attr) ABT_API_PUBLIC
Free the ULT attribute object.
Definition: thread_attr.c:61
#define HANDLE_ERROR_FUNC_WITH_CODE_RET(n)
Definition: abti_error.h:361
#define ABT_ERR_FEATURE_NA
Definition: abt.h:116
static void ABTU_free(void *ptr)
Definition: abtu.h:135
#define ABTU_ret_err
Definition: abtu.h:49