Style fix: f(x) is better than f((x))
[sliver-openvswitch.git] / lib / poll-loop.h
1 /* Copyright (c) 2008 The Board of Trustees of The Leland Stanford
2  * Junior University
3  * 
4  * We are making the OpenFlow specification and associated documentation
5  * (Software) available for public use and benefit with the expectation
6  * that others will use, modify and enhance the Software and contribute
7  * those enhancements back to the community. However, since we would
8  * like to make the Software available for broadest use, with as few
9  * restrictions as possible permission is hereby granted, free of
10  * charge, to any person obtaining a copy of this Software to deal in
11  * the Software under the copyrights without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  * 
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  * 
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27  * SOFTWARE.
28  * 
29  * The name and trademarks of copyright holder(s) may NOT be used in
30  * advertising or publicity pertaining to the Software or any
31  * derivatives without specific, written prior permission.
32  */
33
34 /* High-level wrapper around the "poll" system call.
35  *
36  * Intended usage is for the program's main loop to go about its business
37  * servicing whatever events it needs to.  Then, when it runs out of immediate
38  * tasks, it calls each subordinate module's "wait" function, which in turn
39  * calls one (or more) of the functions poll_fd_wait(), poll_immediate_wake(),
40  * and poll_timer_wait() to register to be awakened when the appropriate event
41  * occurs.  Then the main loop calls poll_block(), which blocks until one of
42  * the registered events happens.
43  *
44  * There is also some support for autonomous subroutines that are executed by
45  * poll_block() when a file descriptor becomes ready.  To prevent these
46  * routines from starving if events are continuously ready, the application
47  * should bound the amount of work it does between poll_block() calls. */
48
49 #ifndef POLL_LOOP_H
50 #define POLL_LOOP_H 1
51
52 #include <poll.h>
53
54 struct poll_waiter;
55
56 /* Schedule events to wake up the following poll_block(). */
57 struct poll_waiter *poll_fd_wait(int fd, short int events);
58 void poll_timer_wait(int msec);
59 void poll_immediate_wake(void);
60
61 /* Wait until an event occurs. */
62 void poll_block(void);
63
64 /* Autonomous function callbacks. */
65 typedef void poll_fd_func(int fd, short int revents, void *aux);
66 struct poll_waiter *poll_fd_callback(int fd, short int events,
67                                      poll_fd_func *, void *aux);
68
69 /* Cancel a file descriptor callback or event. */
70 void poll_cancel(struct poll_waiter *);
71
72 #endif /* poll-loop.h */