1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 #ifndef ORTE_WAIT_H
31 #define ORTE_WAIT_H
32
33 #include "orte_config.h"
34
35 #ifdef HAVE_SYS_TYPES_H
36 #include <sys/types.h>
37 #endif
38 #include <time.h>
39 #if HAVE_SYS_TIME_H
40 #include <sys/time.h>
41 #endif
42
43 #include "opal/dss/dss.h"
44 #include "opal/util/output.h"
45 #include "opal/sys/atomic.h"
46 #include "opal/mca/event/event.h"
47
48 #include "orte/types.h"
49 #include "orte/mca/rml/rml_types.h"
50 #include "orte/runtime/orte_globals.h"
51 #include "orte/util/threads.h"
52
53 BEGIN_C_DECLS
54
55
56 typedef void (*orte_wait_cbfunc_t)(int fd, short args, void* cb);
57
58
59 typedef struct {
60 opal_list_item_t super;
61 opal_event_t ev;
62 opal_event_base_t *evb;
63 orte_proc_t *child;
64 orte_wait_cbfunc_t cbfunc;
65 void *cbdata;
66 } orte_wait_tracker_t;
67 OBJ_CLASS_DECLARATION(orte_wait_tracker_t);
68
69
70
71
72
73
74
75 ORTE_DECLSPEC void orte_wait_enable(void);
76 ORTE_DECLSPEC void orte_wait_disable(void);
77
78
79
80
81
82
83
84
85 ORTE_DECLSPEC void orte_wait_cb(orte_proc_t *proc, orte_wait_cbfunc_t callback,
86 opal_event_base_t *evb, void *data);
87
88 ORTE_DECLSPEC void orte_wait_cb_cancel(orte_proc_t *proc);
89
90
91
92
93
94
95
96
97
98 #define ORTE_WAIT_FOR_COMPLETION(flg) \
99 do { \
100 opal_output_verbose(1, orte_progress_thread_debug, \
101 "%s waiting on progress thread at %s:%d", \
102 ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), \
103 __FILE__, __LINE__); \
104 while ((flg)) { \
105
106
107 \
108 struct timespec tp = {0, 100000}; \
109 nanosleep(&tp, NULL); \
110 } \
111 ORTE_ACQUIRE_OBJECT(flg); \
112 }while(0);
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133 #define ORTE_DETECT_TIMEOUT(n, deltat, maxwait, cbfunc, cbd) \
134 do { \
135 orte_timer_t *tmp; \
136 int timeout; \
137 tmp = OBJ_NEW(orte_timer_t); \
138 tmp->payload = (cbd); \
139 opal_event_evtimer_set(orte_event_base, \
140 tmp->ev, (cbfunc), tmp); \
141 opal_event_set_priority(tmp->ev, ORTE_ERROR_PRI); \
142 timeout = (deltat) * (n); \
143 if ((maxwait) > 0 && timeout > (maxwait)) { \
144 timeout = (maxwait); \
145 } \
146 tmp->tv.tv_sec = timeout/1000000; \
147 tmp->tv.tv_usec = timeout%1000000; \
148 OPAL_OUTPUT_VERBOSE((1, orte_debug_output, \
149 "defining timeout: %ld sec %ld usec at %s:%d", \
150 (long)tmp->tv.tv_sec, (long)tmp->tv.tv_usec, \
151 __FILE__, __LINE__)); \
152 ORTE_POST_OBJECT(tmp); \
153 opal_event_evtimer_add(tmp->ev, &tmp->tv); \
154 }while(0); \
155
156
157
158
159
160
161
162
163
164
165
166 #define ORTE_TIMER_EVENT(sec, usec, cbfunc, pri) \
167 do { \
168 orte_timer_t *tm; \
169 tm = OBJ_NEW(orte_timer_t); \
170 opal_event_evtimer_set(orte_event_base, \
171 tm->ev, (cbfunc), tm); \
172 opal_event_set_priority(tm->ev, (pri)); \
173 tm->tv.tv_sec = (sec) + (usec)/1000000; \
174 tm->tv.tv_usec = (usec) % 1000000; \
175 OPAL_OUTPUT_VERBOSE((1, orte_debug_output, \
176 "defining timer event: %ld sec %ld usec at %s:%d", \
177 (long)tm->tv.tv_sec, (long)tm->tv.tv_usec, \
178 __FILE__, __LINE__)); \
179 ORTE_POST_OBJECT(tm); \
180 opal_event_evtimer_add(tm->ev, &tm->tv); \
181 }while(0); \
182
183
184
185
186
187
188
189 ORTE_DECLSPEC int orte_wait_init(void);
190
191
192
193
194
195
196 ORTE_DECLSPEC int orte_wait_finalize(void);
197
198 END_C_DECLS
199
200 #endif