ARGOBOTS  fe9704776da8f6f84e7a743897757aecc2686685
 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  ABTI_thread_attr *p_newattr;
29  int abt_errno = ABTU_malloc(sizeof(ABTI_thread_attr), (void **)&p_newattr);
30  ABTI_CHECK_ERROR(abt_errno);
31 
32  /* Default values */
33  ABTI_thread_attr_init(p_newattr, NULL, gp_ABTI_global->thread_stacksize,
34  ABTI_THREAD_TYPE_MEM_MEMPOOL_DESC_STACK, ABT_TRUE);
35  *newattr = ABTI_thread_attr_get_handle(p_newattr);
36  return ABT_SUCCESS;
37 }
38 
52 {
53  ABT_thread_attr h_attr = *attr;
54  ABTI_thread_attr *p_attr = ABTI_thread_attr_get_ptr(h_attr);
55  ABTI_CHECK_NULL_THREAD_ATTR_PTR(p_attr);
56 
57  /* Free the memory */
58  ABTU_free(p_attr);
59  *attr = ABT_THREAD_ATTR_NULL;
60  return ABT_SUCCESS;
61 }
62 
84 int ABT_thread_attr_set_stack(ABT_thread_attr attr, void *stackaddr,
85  size_t stacksize)
86 {
87  ABTI_thread_attr *p_attr = ABTI_thread_attr_get_ptr(attr);
88  ABTI_CHECK_NULL_THREAD_ATTR_PTR(p_attr);
89 
90  ABTI_thread_type new_thread_type;
91  if (stackaddr != NULL) {
92  if (((uintptr_t)stackaddr & 0x7) != 0) {
93  ABTI_HANDLE_ERROR(ABT_ERR_OTHER);
94  }
95  new_thread_type = ABTI_THREAD_TYPE_MEM_MEMPOOL_DESC;
96  } else {
97  if (stacksize == gp_ABTI_global->thread_stacksize) {
98  new_thread_type = ABTI_THREAD_TYPE_MEM_MEMPOOL_DESC_STACK;
99  } else {
100  new_thread_type = ABTI_THREAD_TYPE_MEM_MALLOC_DESC_STACK;
101  }
102  }
103  /* Unset the stack type and set new_thread_type. */
104  p_attr->thread_type &= ~ABTI_THREAD_TYPES_MEM;
105  p_attr->thread_type |= new_thread_type;
106 
107  p_attr->p_stack = stackaddr;
108  p_attr->stacksize = stacksize;
109  return ABT_SUCCESS;
110 }
111 
128 int ABT_thread_attr_get_stack(ABT_thread_attr attr, void **stackaddr,
129  size_t *stacksize)
130 {
131  ABTI_thread_attr *p_attr = ABTI_thread_attr_get_ptr(attr);
132  ABTI_CHECK_NULL_THREAD_ATTR_PTR(p_attr);
133 
134  *stackaddr = p_attr->p_stack;
135  *stacksize = p_attr->stacksize;
136  return ABT_SUCCESS;
137 }
138 
152 {
153  ABTI_thread_attr *p_attr = ABTI_thread_attr_get_ptr(attr);
154  ABTI_CHECK_NULL_THREAD_ATTR_PTR(p_attr);
155 
156  /* Set the value */
157  p_attr->stacksize = stacksize;
158  ABTI_thread_type new_thread_type;
159  if (stacksize == gp_ABTI_global->thread_stacksize) {
160  new_thread_type = ABTI_THREAD_TYPE_MEM_MEMPOOL_DESC_STACK;
161  } else {
162  new_thread_type = ABTI_THREAD_TYPE_MEM_MEMPOOL_DESC_STACK;
163  }
164  /* Unset the stack type and set new_thread_type. */
165  p_attr->thread_type &= ~ABTI_THREAD_TYPES_MEM;
166  p_attr->thread_type |= new_thread_type;
167  return ABT_SUCCESS;
168 }
169 
182 int ABT_thread_attr_get_stacksize(ABT_thread_attr attr, size_t *stacksize)
183 {
184  ABTI_thread_attr *p_attr = ABTI_thread_attr_get_ptr(attr);
185  ABTI_CHECK_NULL_THREAD_ATTR_PTR(p_attr);
186 
187  *stacksize = p_attr->stacksize;
188  return ABT_SUCCESS;
189 }
190 
205  void (*cb_func)(ABT_thread thread,
206  void *cb_arg),
207  void *cb_arg)
208 {
209 #ifndef ABT_CONFIG_DISABLE_MIGRATION
210  ABTI_thread_attr *p_attr = ABTI_thread_attr_get_ptr(attr);
211  ABTI_CHECK_NULL_THREAD_ATTR_PTR(p_attr);
212 
213  /* Set the value */
214  p_attr->f_cb = cb_func;
215  p_attr->p_cb_arg = cb_arg;
216  return ABT_SUCCESS;
217 #else
218  ABTI_HANDLE_ERROR(ABT_ERR_FEATURE_NA);
219 #endif
220 }
221 
239 {
240 #ifndef ABT_CONFIG_DISABLE_MIGRATION
241  ABTI_thread_attr *p_attr = ABTI_thread_attr_get_ptr(attr);
242  ABTI_CHECK_NULL_THREAD_ATTR_PTR(p_attr);
243 
244  /* Set the value */
245  p_attr->migratable = flag;
246  return ABT_SUCCESS;
247 #else
248  ABTI_HANDLE_ERROR(ABT_ERR_FEATURE_NA);
249 #endif
250 }
251 
252 /*****************************************************************************/
253 /* Private APIs */
254 /*****************************************************************************/
255 
256 void ABTI_thread_attr_print(ABTI_thread_attr *p_attr, FILE *p_os, int indent)
257 {
258  if (p_attr == NULL) {
259  fprintf(p_os, "%*sULT attr: [NULL ATTR]\n", indent, "");
260  } else {
261  const char *stacktype;
262  if (p_attr->thread_type & ABTI_THREAD_TYPE_MEM_MEMPOOL_DESC) {
263  stacktype = "MEMPOOL_DESC";
264  } else if (p_attr->thread_type & ABTI_THREAD_TYPE_MEM_MALLOC_DESC) {
265  stacktype = "MALLOC_DESC";
266  } else if (p_attr->thread_type &
267  ABTI_THREAD_TYPE_MEM_MEMPOOL_DESC_STACK) {
268  stacktype = "MEMPOOL_DESC_STACK";
269  } else if (p_attr->thread_type &
270  ABTI_THREAD_TYPE_MEM_MALLOC_DESC_STACK) {
271  stacktype = "MALLOC_DESC_STACK";
272  } else {
273  stacktype = "UNKNOWN";
274  }
275 #ifndef ABT_CONFIG_DISABLE_MIGRATION
276  fprintf(p_os,
277  "%*sULT attr: ["
278  "stack:%p "
279  "stacksize:%zu "
280  "stacktype:%s "
281  "migratable:%s "
282  "cb_arg:%p"
283  "]\n",
284  indent, "", p_attr->p_stack, p_attr->stacksize, stacktype,
285  (p_attr->migratable == ABT_TRUE ? "TRUE" : "FALSE"),
286  p_attr->p_cb_arg);
287 #else
288  fprintf(p_os,
289  "%*sULT attr: ["
290  "stack:%p "
291  "stacksize:%zu "
292  "stacktype:%s "
293  "]\n",
294  indent, "", p_attr->p_stack, p_attr->stacksize, stacktype);
295 #endif
296  }
297  fflush(p_os);
298 }
299 
300 ABTU_ret_err int ABTI_thread_attr_dup(const ABTI_thread_attr *p_attr,
301  ABTI_thread_attr **pp_dup_attr)
302 {
303  ABTI_thread_attr *p_dup_attr;
304  int abt_errno = ABTU_malloc(sizeof(ABTI_thread_attr), (void **)&p_dup_attr);
305  ABTI_CHECK_ERROR(abt_errno);
306 
307  memcpy(p_dup_attr, p_attr, sizeof(ABTI_thread_attr));
308  *pp_dup_attr = p_dup_attr;
309  return ABT_SUCCESS;
310 }
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:151
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:84
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:238
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:182
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:204
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:218
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
ABTI_global * gp_ABTI_global
Definition: global.c:18
#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:128
int ABT_thread_attr_free(ABT_thread_attr *attr) ABT_API_PUBLIC
Free the ULT attribute object.
Definition: thread_attr.c:51
#define ABT_ERR_FEATURE_NA
Definition: abt.h:117
static void ABTU_free(void *ptr)
Definition: abtu.h:211
#define ABTU_ret_err
Definition: abtu.h:138