ARGOBOTS  be4fa269aff5d27d176eaaf43a9acaa10a66c79d
abtd.h
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 #ifndef ABTD_H_INCLUDED
7 #define ABTD_H_INCLUDED
8 
9 #define __USE_GNU 1
10 #include <pthread.h>
11 #include "abtd_atomic.h"
12 #include "abtd_context.h"
13 #include "abtd_spinlock.h"
14 #include "abtd_futex.h"
15 
16 /* Data Types */
17 typedef enum {
18  ABTD_XSTREAM_CONTEXT_STATE_RUNNING,
19  ABTD_XSTREAM_CONTEXT_STATE_WAITING,
20  ABTD_XSTREAM_CONTEXT_STATE_REQ_JOIN,
21  ABTD_XSTREAM_CONTEXT_STATE_REQ_TERMINATE,
22  ABTD_XSTREAM_CONTEXT_STATE_UNINIT,
23 } ABTD_xstream_context_state;
24 typedef struct ABTD_xstream_context {
25  pthread_t native_thread;
26  void *(*thread_f)(void *);
27  void *p_arg;
28  ABTD_xstream_context_state state;
29  pthread_mutex_t state_lock;
30  pthread_cond_t state_cond;
31 } ABTD_xstream_context;
32 typedef pthread_mutex_t ABTD_xstream_mutex;
33 #ifdef HAVE_PTHREAD_BARRIER_INIT
34 typedef pthread_barrier_t ABTD_xstream_barrier;
35 #else
36 typedef void *ABTD_xstream_barrier;
37 #endif
38 typedef struct ABTD_affinity_cpuset {
39  size_t num_cpuids;
40  int *cpuids;
41 } ABTD_affinity_cpuset;
42 
43 /* ES Storage Qualifier */
44 #define ABTD_XSTREAM_LOCAL __thread
45 
46 /* Environment */
47 void ABTD_env_init(ABTI_global *p_global);
48 
49 /* ES Context */
50 ABTU_ret_err int ABTD_xstream_context_create(void *(*f_xstream)(void *),
51  void *p_arg,
52  ABTD_xstream_context *p_ctx);
53 void ABTD_xstream_context_free(ABTD_xstream_context *p_ctx);
54 void ABTD_xstream_context_join(ABTD_xstream_context *p_ctx);
55 void ABTD_xstream_context_revive(ABTD_xstream_context *p_ctx);
56 void ABTD_xstream_context_set_self(ABTD_xstream_context *p_ctx);
57 void ABTD_xstream_context_print(ABTD_xstream_context *p_ctx, FILE *p_os,
58  int indent);
59 
60 /* ES Affinity */
61 void ABTD_affinity_init(ABTI_global *p_global, const char *affinity_str);
62 void ABTD_affinity_finalize(ABTI_global *p_global);
63 ABTU_ret_err int ABTD_affinity_cpuset_read(ABTD_xstream_context *p_ctx,
64  int max_cpuids, int *cpuids,
65  int *p_num_cpuids);
66 ABTU_ret_err int
67 ABTD_affinity_cpuset_apply(ABTD_xstream_context *p_ctx,
68  const ABTD_affinity_cpuset *p_cpuset);
69 int ABTD_affinity_cpuset_apply_default(ABTD_xstream_context *p_ctx, int rank);
70 void ABTD_affinity_cpuset_destroy(ABTD_affinity_cpuset *p_cpuset);
71 
72 /* ES Affinity Parser */
73 typedef struct ABTD_affinity_id_list {
74  uint32_t num;
75  int *ids; /* id here can be negative. */
76 } ABTD_affinity_id_list;
77 typedef struct ABTD_affinity_list {
78  uint32_t num;
79  ABTD_affinity_id_list **p_id_lists;
80  void *p_mem_head; /* List to free all the allocated memory easily */
81 } ABTD_affinity_list;
82 ABTU_ret_err int
83 ABTD_affinity_list_create(const char *affinity_str,
84  ABTD_affinity_list **pp_affinity_list);
85 void ABTD_affinity_list_free(ABTD_affinity_list *p_list);
86 
87 #include "abtd_stream.h"
88 
89 /* ULT Context */
90 #include "abtd_ythread.h"
91 void ABTD_ythread_exit(ABTI_xstream *p_local_xstream, ABTI_ythread *p_ythread);
92 void ABTD_ythread_cancel(ABTI_xstream *p_local_xstream,
93  ABTI_ythread *p_ythread);
94 
95 #if defined(ABT_CONFIG_USE_CLOCK_GETTIME)
96 #include <time.h>
97 typedef struct timespec ABTD_time;
98 
99 #elif defined(ABT_CONFIG_USE_MACH_ABSOLUTE_TIME)
100 #include <mach/mach_time.h>
101 typedef uint64_t ABTD_time;
102 
103 #elif defined(ABT_CONFIG_USE_GETTIMEOFDAY)
104 #include <sys/time.h>
105 typedef struct timeval ABTD_time;
106 
107 #endif
108 
109 void ABTD_time_init(void);
110 void ABTD_time_get(ABTD_time *p_time);
111 double ABTD_time_read_sec(ABTD_time *p_time);
112 
113 #endif /* ABTD_H_INCLUDED */
abtd_context.h
ABTU_ret_err
#define ABTU_ret_err
Definition: abtu.h:144
abtd_spinlock.h
abtd_stream.h
abtd_futex.h
abtd_atomic.h
abtd_ythread.h