OpenMPI 0.1.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

libevent2013.h
1 /*
2 * Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
4 *
5 * $COPYRIGHT$
6 *
7 * Additional copyrights may follow
8 *
9 * $HEADER$
10 *
11 * When this component is used, this file is included in the rest of
12 * the OPAL/ORTE/OMPI code base via opal/mca/event/event.h. As such,
13 * this header represents the public interface to this static component.
14 */
15
16 #ifndef MCA_OPAL_EVENT_LIBEVENT2013_H
17 #define MCA_OPAL_EVENT_LIBEVENT2013_H
18
19 #include "opal_config.h"
20
21 #ifdef HAVE_SYS_TYPES_H
22 #include <sys/types.h>
23 #endif
24
25 #ifdef WIN32
26 #define WIN32_LEAN_AND_MEAN
27 #include <windows.h>
28 #undef WIN32_LEAN_AND_MEAN
29 #endif
30 #ifdef HAVE_SYS_TIME_H
31 #include <sys/time.h>
32 #endif
33 #include <stdio.h>
34 #include <stdlib.h>
35 #ifndef WIN32
36 #ifdef HAVE_UNISTD_H
37 #include <unistd.h>
38 #endif
39 #endif
40 #include <errno.h>
41 #include <signal.h>
42 #include <string.h>
43 #include <assert.h>
44 #include <time.h>
45
46 #include "opal/class/opal_object.h"
47 #include "opal/threads/mutex.h"
48 #include "opal/threads/threads.h"
49 #include "opal/util/output.h"
50 #include "opal/constants.h"
51 #include "opal/util/argv.h"
52 #include "opal/mca/base/mca_base_param.h"
53 #include "opal/mca/event/base/base.h"
54
55 #include "libevent/event.h"
56 #include "libevent/include/event2/thread.h"
57
58 #include "opal/mca/event/event.h"
59
60 typedef struct event opal_event_t;
61 /*** Overload the event_base_t struct ***/
62 /* This may (hopefully) be a temporary change
63 * to deal with cross-base sync. Specifically,
64 * when an event in one base needs to release
65 * a condition_wait in another base, we need
66 * to "wakeup" the event base in the second base
67 * so the condition_wait can be checked
68 *
69 * On a more permanent level, use this to update
70 * the event base when it is being progressed in
71 * a separate thread.
72 */
73 typedef struct {
74 struct event_base *base;
75 opal_event_t update_event;
76 int update_pipe[2];
77 } opal_event_base_t;
78
79 typedef struct {
80 opal_event_t *ev;
81 uint8_t op;
82 } opal_event_update_t;
83
84 #define OPAL_EVENT_NOOP 0x00
85 #define OPAL_EVENT_ADD 0x01
86 #define OPAL_EVENT_DEL 0x02
87
88 #if OPAL_EVENT_HAVE_THREAD_SUPPORT
89 #define OPAL_UPDATE_EVBASE(b, evt, ad)
90 #else
91 #define OPAL_UPDATE_EVBASE(b, evt, ad) \
92 do { \
93 opal_event_update_t up; \
94 up.ev = (evt); \
95 up.op = (ad); \
96 opal_fd_write((b)->update_pipe[1], sizeof(opal_event_update_t), &up); \
97 } while(0);
98 #endif
99
100 BEGIN_C_DECLS
101
102 /* Temporary global - will be replaced by layer-specific event bases */
103 OPAL_DECLSPEC extern opal_event_base_t *opal_event_base;
104
105 #define OPAL_EV_TIMEOUT EV_TIMEOUT
106 #define OPAL_EV_READ EV_READ
107 #define OPAL_EV_WRITE EV_WRITE
108 #define OPAL_EV_SIGNAL EV_SIGNAL
109 /* Persistent event: won't get removed automatically when activated. */
110 #define OPAL_EV_PERSIST EV_PERSIST
111
112 #define OPAL_EVLOOP_ONCE EVLOOP_ONCE /**< Block at most once. */
113 #define OPAL_EVLOOP_NONBLOCK EVLOOP_NONBLOCK /**< Do not block. */
114
115 /* Global function to create and release an event base */
116 OPAL_DECLSPEC opal_event_base_t* opal_event_base_create(void);
117 OPAL_DECLSPEC void opal_event_base_finalize(opal_event_base_t *base);
118
119 OPAL_DECLSPEC int opal_event_init(void);
120
121 OPAL_DECLSPEC int opal_event_reinit(opal_event_base_t *base);
122
123 OPAL_DECLSPEC struct timeval *opal_event_base_init_common_timeout (opal_event_base_t *evbase,
124 struct timeval *tv_in);
125
126 /* thread support APIs */
127 #if OPAL_EVENT_HAVE_THREAD_SUPPORT
128 #ifdef WIN32
129 #define opal_event_use_threads(x) evthread_use_windows_threads(x)
130 #else
131 #define opal_event_use_threads(x) evthread_use_pthreads(x)
132 #endif
133 #else
134 #define opal_event_use_threads(x)
135 #endif
136
137 /* Basic event APIs */
138 #define opal_event_set_debug_output(x) event_set_debug_output((x))
139
140 #define opal_event_set(b, ev, fd, fg, cb, arg) event_assign((ev), (b)->base, (fd), (fg), (event_callback_fn) (cb), (arg))
141
142 #define opal_event_add(ev, tv) event_add((ev), (tv))
143
144 #define opal_event_del(ev) event_del((ev))
145
146 #define opal_event_active(x, y, z) event_active((x), (y), (z))
147
148 #define opal_event_new(b, fd, fg, cb, arg) event_new((b)->base, (fd), (fg), (event_callback_fn) (cb), (arg))
149
150 #define opal_event_free(x) event_free((x))
151
152 /* Timer APIs */
153 #define opal_event_evtimer_new(b, cb, arg) event_new((b)->base, -1, 0, (event_callback_fn) (cb), (arg))
154
155 #define opal_event_evtimer_add(ev, tv) event_add((ev), (tv))
156
157 #define opal_event_evtimer_set(b, ev, cb, arg) event_assign((ev), (b)->base, -1, 0, (event_callback_fn) (cb), (arg))
158
159 #define opal_event_evtimer_del(ev) event_del((ev))
160
161 #define opal_event_evtimer_pending(ev, tv) event_pending((ev), EV_TIMEOUT, (tv))
162
163 #define opal_event_evtimer_initialized(ev) event_initialized((ev))
164
165 /* Signal APIs */
166 #define opal_event_signal_add(ev, tv) event_add((ev), (tv))
167
168 #define opal_event_signal_set(b, ev, fd, cb, arg) event_assign((ev), (b)->base, (fd), EV_SIGNAL|EV_PERSIST, (event_callback_fn) (cb), (arg))
169
170 #define opal_event_signal_del(ev) event_del((ev))
171
172 #define opal_event_signal_pending(ev, tv) event_pending((ev), EV_SIGNAL, (tv))
173
174 #define opal_event_signal_initalized(ev) event_initialized((ev))
175
176 #define opal_event_get_signal(ev) event_get_signal((ev))
177
178 #define opal_event_loop(b, fg) event_base_loop((b->base), (fg))
179
180 #define opal_event_dispatch(b) event_base_loop((b)->base, 0)
181
182 END_C_DECLS
183
184 #endif /* MCA_OPAL_EVENT_LIBEVENT2013_H */
output.h
OPAL output stream facility.
mca_base_param.h
This file presents the MCA parameter interface.
event
Structure to represent a single event.
Definition: event_struct.h:87
opal_event_base_t
Definition: libevent2013.h:73
thread.h
Functions for multi-threaded applications using Libevent.
opal_event_update_t
Definition: libevent2013.h:79
argv.h
Generic routines for "argv"-like handling.
mutex.h
Mutual exclusion functions.
opal_object.h
A simple C-language object-oriented system with single inheritance and ownership-based memory managem...
event_base
Definition: event-internal.h:167