This source file includes following definitions.
- pmix_hton64
- pmix_ntoh64
- pmix_ptr_ptol
- pmix_ptr_ltop
- pmix_swap_bytes2
- pmix_swap_bytes4
- pmix_swap_bytes8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 #ifndef PMIX_TYPES_H
25 #define PMIX_TYPES_H
26
27 #include <src/include/pmix_config.h>
28
29 #ifdef HAVE_STDINT_H
30 #include <stdint.h>
31 #endif
32 #ifdef HAVE_SYS_TYPES_H
33 #include <sys/types.h>
34 #endif
35 #ifdef HAVE_SYS_SOCKET_H
36 #include <sys/socket.h>
37 #endif
38 #ifdef HAVE_SYS_SELECT_H
39 #include <sys/select.h>
40 #endif
41 #ifdef HAVE_NETINET_IN_H
42 #include <netinet/in.h>
43 #endif
44 #ifdef HAVE_ARPA_INET_H
45 #include <arpa/inet.h>
46 #endif
47 #include PMIX_EVENT_HEADER
48 #if ! PMIX_HAVE_LIBEV
49 #include PMIX_EVENT2_THREAD_HEADER
50 #endif
51
52 #if PMIX_ENABLE_DEBUG
53 #include "src/util/output.h"
54 #endif
55
56 #include <pthread.h>
57
58
59
60
61
62
63 typedef union {
64 uint64_t lval;
65 uint32_t ival;
66 void* pval;
67 struct {
68 uint32_t uval;
69 uint32_t lval;
70 } sval;
71 } pmix_ptr_t;
72
73
74
75
76
77 #if defined(__APPLE__) || defined(__WINDOWS__)
78 typedef char* pmix_iov_base_ptr_t;
79 #define PMIX_IOVBASE char
80 #else
81 #define PMIX_IOVBASE void
82 typedef void* pmix_iov_base_ptr_t;
83 #endif
84
85
86
87
88
89 #if defined(HAVE_SOCKLEN_T)
90 typedef socklen_t pmix_socklen_t;
91 #else
92 typedef int pmix_socklen_t;
93 #endif
94
95
96 #define pmix_htons htons
97 #define pmix_ntohs ntohs
98
99
100
101
102
103 static inline uint64_t pmix_hton64(uint64_t val) __pmix_attribute_const__;
104 static inline uint64_t pmix_hton64(uint64_t val)
105 {
106 #ifdef HAVE_UNIX_BYTESWAP
107 union { uint64_t ll;
108 uint32_t l[2];
109 } w, r;
110
111
112 if(htonl(1) == 1L)
113 return val;
114 w.ll = val;
115 r.l[0] = htonl(w.l[1]);
116 r.l[1] = htonl(w.l[0]);
117 return r.ll;
118 #else
119 return val;
120 #endif
121 }
122
123
124
125
126
127 static inline uint64_t pmix_ntoh64(uint64_t val) __pmix_attribute_const__;
128 static inline uint64_t pmix_ntoh64(uint64_t val)
129 {
130 #ifdef HAVE_UNIX_BYTESWAP
131 union { uint64_t ll;
132 uint32_t l[2];
133 } w, r;
134
135
136 if(htonl(1) == 1L)
137 return val;
138 w.ll = val;
139 r.l[0] = ntohl(w.l[1]);
140 r.l[1] = ntohl(w.l[0]);
141 return r.ll;
142 #else
143 return val;
144 #endif
145 }
146
147
148
149
150
151 static inline uint64_t pmix_ptr_ptol( void* ptr ) __pmix_attribute_const__;
152 static inline uint64_t pmix_ptr_ptol( void* ptr )
153 {
154 return (uint64_t)(uintptr_t) ptr;
155 }
156
157 static inline void* pmix_ptr_ltop( uint64_t value ) __pmix_attribute_const__;
158 static inline void* pmix_ptr_ltop( uint64_t value )
159 {
160 #if SIZEOF_VOID_P == 4 && PMIX_ENABLE_DEBUG
161 if (value > ((1ULL << 32) - 1ULL)) {
162 pmix_output(0, "Warning: truncating value in pmix_ptr_ltop");
163 }
164 #endif
165 return (void*)(uintptr_t) value;
166 }
167
168 #if defined(WORDS_BIGENDIAN) || !defined(HAVE_UNIX_BYTESWAP)
169 static inline uint16_t pmix_swap_bytes2(uint16_t val) __pmix_attribute_const__;
170 static inline uint16_t pmix_swap_bytes2(uint16_t val)
171 {
172 union { uint16_t bigval;
173 uint8_t arrayval[2];
174 } w, r;
175
176 w.bigval = val;
177 r.arrayval[0] = w.arrayval[1];
178 r.arrayval[1] = w.arrayval[0];
179
180 return r.bigval;
181 }
182
183 static inline uint32_t pmix_swap_bytes4(uint32_t val) __pmix_attribute_const__;
184 static inline uint32_t pmix_swap_bytes4(uint32_t val)
185 {
186 union { uint32_t bigval;
187 uint8_t arrayval[4];
188 } w, r;
189
190 w.bigval = val;
191 r.arrayval[0] = w.arrayval[3];
192 r.arrayval[1] = w.arrayval[2];
193 r.arrayval[2] = w.arrayval[1];
194 r.arrayval[3] = w.arrayval[0];
195
196 return r.bigval;
197 }
198
199 static inline uint64_t pmix_swap_bytes8(uint64_t val) __pmix_attribute_const__;
200 static inline uint64_t pmix_swap_bytes8(uint64_t val)
201 {
202 union { uint64_t bigval;
203 uint8_t arrayval[8];
204 } w, r;
205
206 w.bigval = val;
207 r.arrayval[0] = w.arrayval[7];
208 r.arrayval[1] = w.arrayval[6];
209 r.arrayval[2] = w.arrayval[5];
210 r.arrayval[3] = w.arrayval[4];
211 r.arrayval[4] = w.arrayval[3];
212 r.arrayval[5] = w.arrayval[2];
213 r.arrayval[6] = w.arrayval[1];
214 r.arrayval[7] = w.arrayval[0];
215
216 return r.bigval;
217 }
218
219 #else
220 #define pmix_swap_bytes2 htons
221 #define pmix_swap_bytes4 htonl
222 #define pmix_swap_bytes8 hton64
223 #endif
224
225 #define PMIX_EV_TIMEOUT EV_TIMEOUT
226 #define PMIX_EV_READ EV_READ
227 #define PMIX_EV_WRITE EV_WRITE
228 #define PMIX_EV_SIGNAL EV_SIGNAL
229
230 #define PMIX_EV_PERSIST EV_PERSIST
231
232 #define PMIX_EVLOOP_ONCE EVLOOP_ONCE
233 #define PMIX_EVLOOP_NONBLOCK EVLOOP_NONBLOCK
234
235 typedef struct event_base pmix_event_base_t;
236 typedef struct event pmix_event_t;
237
238 #define pmix_event_base_create() event_base_new()
239
240 #define pmix_event_base_free(b) event_base_free(b)
241
242 #define pmix_event_base_loopexit(b) event_base_loopexit(b, NULL)
243
244 #if PMIX_HAVE_LIBEV
245 #define pmix_event_use_threads()
246 #define pmix_event_free(b) free(b)
247 #define pmix_event_get_signal(x) (x)->ev_fd
248 #else
249
250
251 #define pmix_event_use_threads() evthread_use_pthreads()
252 #define pmix_event_free(x) event_free(x)
253 #define pmix_event_get_signal(x) event_get_signal(x)
254 #endif
255
256
257 #define pmix_event_enable_debug_mode() event_enable_debug_mode()
258
259 PMIX_EXPORT int pmix_event_assign(struct event *ev, pmix_event_base_t *evbase,
260 int fd, short arg, event_callback_fn cbfn, void *cbd);
261
262 #define pmix_event_set(b, x, fd, fg, cb, arg) pmix_event_assign((x), (b), (fd), (fg), (event_callback_fn) (cb), (arg))
263
264 #if PMIX_HAVE_LIBEV
265 PMIX_EXPORT int pmix_event_add(struct event *ev, struct timeval *tv);
266 PMIX_EXPORT int pmix_event_del(struct event *ev);
267 PMIX_EXPORT void pmix_event_active (struct event *ev, int res, short ncalls);
268 PMIX_EXPORT void pmix_event_base_loopbreak (pmix_event_base_t *b);
269 #else
270 #define pmix_event_add(ev, tv) event_add((ev), (tv))
271 #define pmix_event_del(ev) event_del((ev))
272 #define pmix_event_active(x, y, z) event_active((x), (y), (z))
273 #define pmix_event_base_loopbreak(b) event_base_loopbreak(b)
274 #endif
275
276 PMIX_EXPORT pmix_event_t* pmix_event_new(pmix_event_base_t *b, int fd,
277 short fg, event_callback_fn cbfn, void *cbd);
278
279 #define pmix_event_loop(b, fg) event_base_loop((b), (fg))
280
281 #define pmix_event_evtimer_new(b, cb, arg) pmix_event_new((b), -1, 0, (cb), (arg))
282
283 #define pmix_event_evtimer_add(x, tv) pmix_event_add((x), (tv))
284
285 #define pmix_event_evtimer_set(b, x, cb, arg) pmix_event_assign((x), (b), -1, 0, (event_callback_fn) (cb), (arg))
286
287 #define pmix_event_evtimer_del(x) pmix_event_del((x))
288
289 #define pmix_event_signal_set(b, x, fd, cb, arg) pmix_event_assign((x), (b), (fd), EV_SIGNAL|EV_PERSIST, (event_callback_fn) (cb), (arg))
290
291 #endif