]>
Commit | Line | Data |
---|---|---|
064af421 | 1 | /* |
e0ad6e5d | 2 | * Copyright (c) 2008, 2009, 2010, 2011, 2013, 2017 Nicira, Inc. |
064af421 | 3 | * |
a14bc59f BP |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at: | |
064af421 | 7 | * |
a14bc59f BP |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
064af421 BP |
15 | */ |
16 | ||
17 | /* High-level wrapper around the "poll" system call. | |
18 | * | |
2c06a966 | 19 | * The intended usage is for each thread's main loop to go about its business |
064af421 BP |
20 | * servicing whatever events it needs to. Then, when it runs out of immediate |
21 | * tasks, it calls each subordinate module's "wait" function, which in turn | |
22 | * calls one (or more) of the functions poll_fd_wait(), poll_immediate_wake(), | |
23 | * and poll_timer_wait() to register to be awakened when the appropriate event | |
24 | * occurs. Then the main loop calls poll_block(), which blocks until one of | |
2c06a966 BP |
25 | * the registered events happens. |
26 | * | |
27 | * | |
28 | * Thread-safety | |
29 | * ============= | |
30 | * | |
31 | * The poll set is per-thread, so all functions in this module are thread-safe. | |
32 | */ | |
064af421 BP |
33 | #ifndef POLL_LOOP_H |
34 | #define POLL_LOOP_H 1 | |
35 | ||
36 | #include <poll.h> | |
f89ffb0e | 37 | #include "util.h" |
064af421 | 38 | |
03292c46 JG |
39 | #ifdef __cplusplus |
40 | extern "C" { | |
41 | #endif | |
42 | ||
064af421 | 43 | |
f89ffb0e BP |
44 | /* Schedule events to wake up the following poll_block(). |
45 | * | |
46 | * The poll_loop logs the 'where' argument to each function at "debug" level | |
5453ae20 BP |
47 | * when an event causes a wakeup. Each of these ways to schedule an event has |
48 | * a function and a macro wrapper. The macro version automatically supplies | |
49 | * the source code location of the caller. The function version allows the | |
50 | * caller to supply a location explicitly, which is useful if the caller's own | |
51 | * caller would be more useful in log output. See timer_wait_at() for an | |
52 | * example. */ | |
1ca3348e | 53 | void poll_fd_wait_at(int fd, short int events, const char *where); |
8f3676cf | 54 | #define poll_fd_wait(fd, events) poll_fd_wait_at(fd, events, OVS_SOURCE_LOCATOR) |
1ca3348e GS |
55 | |
56 | #ifdef _WIN32 | |
e0ad6e5d | 57 | void poll_wevent_wait_at(HANDLE wevent, const char *where); |
8f3676cf | 58 | #define poll_wevent_wait(wevent) poll_wevent_wait_at(wevent, OVS_SOURCE_LOCATOR) |
1ca3348e | 59 | #endif /* _WIN32 */ |
f89ffb0e | 60 | |
5453ae20 | 61 | void poll_timer_wait_at(long long int msec, const char *where); |
8f3676cf | 62 | #define poll_timer_wait(msec) poll_timer_wait_at(msec, OVS_SOURCE_LOCATOR) |
f89ffb0e | 63 | |
5453ae20 BP |
64 | void poll_timer_wait_until_at(long long int msec, const char *where); |
65 | #define poll_timer_wait_until(msec) \ | |
8f3676cf | 66 | poll_timer_wait_until_at(msec, OVS_SOURCE_LOCATOR) |
f89ffb0e | 67 | |
5453ae20 | 68 | void poll_immediate_wake_at(const char *where); |
8f3676cf | 69 | #define poll_immediate_wake() poll_immediate_wake_at(OVS_SOURCE_LOCATOR) |
064af421 BP |
70 | |
71 | /* Wait until an event occurs. */ | |
72 | void poll_block(void); | |
73 | ||
03292c46 JG |
74 | #ifdef __cplusplus |
75 | } | |
76 | #endif | |
77 | ||
064af421 | 78 | #endif /* poll-loop.h */ |