ARGOBOTS  66b1c39742507d8df30e8d28c54839b961a14814
 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 */
35  *newattr = ABTI_thread_attr_get_handle(p_newattr);
36  return ABT_SUCCESS;
37 }
38 
52 {
53  ABT_thread_attr h_attr = *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 {
89 
90  ABTI_thread_type new_thread_type;
91  if (stackaddr != NULL) {
92  if (((uintptr_t)stackaddr & 0x7) != 0) {
94  }
95  new_thread_type = ABTI_THREAD_TYPE_MEM_MEMPOOL_DESC;
96  } else {
97  if (stacksize == gp_ABTI_global->thread_stacksize) {
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. */
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 {
133 
134  *stackaddr = p_attr->p_stack;
135  *stacksize = p_attr->stacksize;
136  return ABT_SUCCESS;
137 }
138 
152 {
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. */
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 {
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
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
219 #endif
220 }
221 
239 {
240 #ifndef ABT_CONFIG_DISABLE_MIGRATION
243 
244  /* Set the value */
245  p_attr->migratable = flag;
246  return ABT_SUCCESS;
247 #else
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  char *stacktype;
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 &
268  stacktype = "MEMPOOL_DESC_STACK";
269  } else if (p_attr->thread_type &
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 
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 }
static void ABTI_thread_attr_init(ABTI_thread_attr *p_attr, void *p_stack, size_t stacksize, ABTI_thread_type thread_type, ABT_bool migratable)
struct ABT_thread_attr_opaque * ABT_thread_attr
Definition: abt.h:345
#define ABTI_THREAD_TYPE_MEM_MEMPOOL_DESC_STACK
Definition: abti.h:83
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
void * p_cb_arg
Definition: abti.h:336
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
void ABTI_thread_attr_print(ABTI_thread_attr *p_attr, FILE *p_os, int indent)
Definition: thread_attr.c:256
int ABT_bool
Definition: abt.h:373
#define ABTI_THREAD_TYPES_MEM
Definition: abti.h:86
#define ABT_ERR_OTHER
Definition: abt.h:67
void * p_stack
Definition: abti.h:330
#define ABTI_CHECK_NULL_THREAD_ATTR_PTR(p)
Definition: abti_error.h:211
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
uint32_t ABTI_thread_type
Definition: abti.h:115
ABT_bool migratable
Definition: abti.h:334
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
static ABT_thread_attr ABTI_thread_attr_get_handle(ABTI_thread_attr *p_attr)
static ABTI_thread_attr * ABTI_thread_attr_get_ptr(ABT_thread_attr attr)
int ABT_thread_attr_free(ABT_thread_attr *attr) ABT_API_PUBLIC
Free the ULT attribute object.
Definition: thread_attr.c:51
void(* f_cb)(ABT_thread, void *)
Definition: abti.h:335
ABTU_ret_err int ABTI_thread_attr_dup(const ABTI_thread_attr *p_attr, ABTI_thread_attr **pp_dup_attr) ABTU_ret_err
Definition: thread_attr.c:300
#define ABTI_THREAD_TYPE_MEM_MALLOC_DESC_STACK
Definition: abti.h:84
#define ABT_ERR_FEATURE_NA
Definition: abt.h:116
size_t stacksize
Definition: abti.h:331
#define ABTI_THREAD_TYPE_MEM_MALLOC_DESC
Definition: abti.h:82
#define ABTI_CHECK_ERROR(abt_errno)
Definition: abti_error.h:127
#define ABTI_THREAD_TYPE_MEM_MEMPOOL_DESC
Definition: abti.h:81
ABTI_thread_type thread_type
Definition: abti.h:332
static void ABTU_free(void *ptr)
Definition: abtu.h:135
#define ABTU_ret_err
Definition: abtu.h:49
size_t thread_stacksize
Definition: abti.h:182
#define ABTI_HANDLE_ERROR(n)
Definition: abti_error.h:121