ARGOBOTS
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
10 #include <pthread.h>
11 #include "abtd_atomic.h"
12 #include "abtd_context.h"
13 
14 /* Data Types */
15 typedef enum {
16  ABTD_XSTREAM_CONTEXT_STATE_RUNNING,
17  ABTD_XSTREAM_CONTEXT_STATE_WAITING,
18  ABTD_XSTREAM_CONTEXT_STATE_REQ_JOIN,
19  ABTD_XSTREAM_CONTEXT_STATE_REQ_TERMINATE,
20 } ABTD_xstream_context_state;
21 typedef struct ABTD_xstream_context {
22  pthread_t native_thread;
23  void *(*thread_f)(void *);
24  void *p_arg;
25  ABTD_xstream_context_state state;
26  pthread_mutex_t state_lock;
27  pthread_cond_t state_cond;
28 } ABTD_xstream_context;
29 typedef pthread_mutex_t ABTD_xstream_mutex;
30 #ifdef HAVE_PTHREAD_BARRIER_INIT
31 typedef pthread_barrier_t ABTD_xstream_barrier;
32 #else
33 typedef void *ABTD_xstream_barrier;
34 #endif
35 
36 /* ES Storage Qualifier */
37 #define ABTD_XSTREAM_LOCAL __thread
38 
39 /* Environment */
40 void ABTD_env_init(ABTI_global *p_global);
41 
42 /* ES Context */
43 int ABTD_xstream_context_create(void *(*f_xstream)(void *), void *p_arg,
44  ABTD_xstream_context *p_ctx);
45 int ABTD_xstream_context_free(ABTD_xstream_context *p_ctx);
46 int ABTD_xstream_context_join(ABTD_xstream_context *p_ctx);
47 int ABTD_xstream_context_revive(ABTD_xstream_context *p_ctx);
48 int ABTD_xstream_context_set_self(ABTD_xstream_context *p_ctx);
49 
50 /* ES Affinity */
51 void ABTD_affinity_init(void);
52 void ABTD_affinity_finalize(void);
53 int ABTD_affinity_set(ABTD_xstream_context *p_ctx, int rank);
54 int ABTD_affinity_set_cpuset(ABTD_xstream_context *p_ctx, int cpuset_size,
55  int *p_cpuset);
56 int ABTD_affinity_get_cpuset(ABTD_xstream_context *p_ctx, int cpuset_size,
57  int *p_cpuset, int *p_num_cpus);
58 
59 #include "abtd_stream.h"
60 
61 /* ULT Context */
62 #include "abtd_thread.h"
63 void ABTD_thread_exit(ABTI_local *p_local, ABTI_thread *p_thread);
64 void ABTD_thread_cancel(ABTI_local *p_local, ABTI_thread *p_thread);
65 
66 #if defined(ABT_CONFIG_USE_CLOCK_GETTIME)
67 #include <time.h>
68 typedef struct timespec ABTD_time;
69 
70 #elif defined(ABT_CONFIG_USE_MACH_ABSOLUTE_TIME)
71 #include <mach/mach_time.h>
72 typedef uint64_t ABTD_time;
73 
74 #elif defined(ABT_CONFIG_USE_GETTIMEOFDAY)
75 #include <sys/time.h>
76 typedef struct timeval ABTD_time;
77 
78 #endif
79 
80 void ABTD_time_init(void);
81 int ABTD_time_get(ABTD_time *p_time);
82 double ABTD_time_read_sec(ABTD_time *p_time);
83 
84 #endif /* ABTD_H_INCLUDED */