GRPC Core 0.10.0.0

- Main Page
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pollset_posix.h
Go to the documentation of this file.
1 /*
2 *
3 * Copyright 2015, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34 #ifndef GRPC_INTERNAL_CORE_IOMGR_POLLSET_POSIX_H
35 #define GRPC_INTERNAL_CORE_IOMGR_POLLSET_POSIX_H
36
37 #include <grpc/support/sync.h>
38
39 #include "src/core/iomgr/pollset_kick_posix.h"
40
41 typedef struct grpc_pollset_vtable grpc_pollset_vtable;
42
43 /* forward declare only in this file to avoid leaking impl details via
44 pollset.h; real users of grpc_fd should always include 'fd_posix.h' and not
45 use the struct tag */
46 struct grpc_fd;
47
48 typedef struct grpc_pollset {
49 /* pollsets under posix can mutate representation as fds are added and
50 removed.
51 For example, we may choose a poll() based implementation on linux for
52 few fds, and an epoll() based implementation for many fds */
53 const grpc_pollset_vtable *vtable;
54 gpr_mu mu;
55 grpc_pollset_kick_state kick_state;
56 int counter;
57 int in_flight_cbs;
58 int shutting_down;
59 int called_shutdown;
60 void (*shutdown_done_cb)(void *arg);
61 void *shutdown_done_arg;
62 union {
63 int fd;
64 void *ptr;
65 } data;
66 } grpc_pollset;
67
68 struct grpc_pollset_vtable {
69 void (*add_fd)(grpc_pollset *pollset, struct grpc_fd *fd,
70 int and_unlock_pollset);
71 void (*del_fd)(grpc_pollset *pollset, struct grpc_fd *fd,
72 int and_unlock_pollset);
73 void (*maybe_work)(grpc_pollset *pollset, gpr_timespec deadline,
74 gpr_timespec now, int allow_synchronous_callback);
75 void (*kick)(grpc_pollset *pollset);
76 void (*finish_shutdown)(grpc_pollset *pollset);
77 void (*destroy)(grpc_pollset *pollset);
78 };
79
80 #define GRPC_POLLSET_MU(pollset) (&(pollset)->mu)
81
82 /* Add an fd to a pollset */
83 void grpc_pollset_add_fd(grpc_pollset *pollset, struct grpc_fd *fd);
84 /* Force remove an fd from a pollset (normally they are removed on the next
85 poll after an fd is orphaned) */
86 void grpc_pollset_del_fd(grpc_pollset *pollset, struct grpc_fd *fd);
87
88 /* Force any current pollers to break polling: it's the callers responsibility
89 to ensure that the pollset indeed needs to be kicked - no verification that
90 the pollset is actually performing polling work is done. At worst this will
91 result in spurious wakeups if performed at the wrong moment.
92 Does not touch pollset->mu. */
93 void grpc_pollset_force_kick(grpc_pollset *pollset);
94 /* Returns the fd to listen on for kicks */
95 int grpc_kick_read_fd(grpc_pollset *p);
96 /* Call after polling has been kicked to leave the kicked state */
97 void grpc_kick_drain(grpc_pollset *p);
98
99 /* Convert a timespec to milliseconds:
100 - very small or negative poll times are clamped to zero to do a
101 non-blocking poll (which becomes spin polling)
102 - other small values are rounded up to one millisecond
103 - longer than a millisecond polls are rounded up to the next nearest
104 millisecond to avoid spinning
105 - infinite timeouts are converted to -1 */
106 int grpc_poll_deadline_to_millis_timeout(gpr_timespec deadline, gpr_timespec now);
107
108 /* turn a pollset into a multipoller: platform specific */
109 typedef void (*grpc_platform_become_multipoller_type)(grpc_pollset *pollset,
110 struct grpc_fd **fds,
111 size_t fd_count);
112 extern grpc_platform_become_multipoller_type grpc_platform_become_multipoller;
113
114 void grpc_poll_become_multipoller(grpc_pollset *pollset, struct grpc_fd **fds,
115 size_t fd_count);
116
117 #endif /* GRPC_INTERNAL_CORE_IOMGR_POLLSET_POSIX_H */
grpc_platform_become_multipoller
grpc_platform_become_multipoller_type grpc_platform_become_multipoller
grpc_pollset_vtable::destroy
void(* destroy)(grpc_pollset *pollset)
Definition: pollset_posix.h:77
grpc_fd::fd
int fd
Definition: fd_posix.h:53
grpc_pollset::ptr
void * ptr
Definition: pollset_posix.h:64
grpc_pollset_vtable::del_fd
void(* del_fd)(grpc_pollset *pollset, struct grpc_fd *fd, int and_unlock_pollset)
Definition: pollset_posix.h:71
grpc_platform_become_multipoller_type
void(* grpc_platform_become_multipoller_type)(grpc_pollset *pollset, struct grpc_fd **fds, size_t fd_count)
Definition: pollset_posix.h:109
grpc_pollset::data
union grpc_pollset::@13 data
grpc_pollset::shutdown_done_arg
void * shutdown_done_arg
Definition: pollset_posix.h:61
grpc_pollset_vtable
Definition: pollset_posix.h:68
grpc_pollset::fd
int fd
Definition: pollset_posix.h:63
grpc_pollset::mu
gpr_mu mu
Definition: pollset_posix.h:54
grpc_pollset
Definition: pollset_posix.h:48
grpc_pollset
struct grpc_pollset grpc_pollset
grpc_pollset_vtable::finish_shutdown
void(* finish_shutdown)(grpc_pollset *pollset)
Definition: pollset_posix.h:76
grpc_pollset_force_kick
void grpc_pollset_force_kick(grpc_pollset *pollset)
pollset_kick_posix.h
gpr_mu
Definition: sync_win32.h:39
grpc_pollset_vtable::maybe_work
void(* maybe_work)(grpc_pollset *pollset, gpr_timespec deadline, gpr_timespec now, int allow_synchronous_callback)
Definition: pollset_posix.h:73
grpc_pollset::counter
int counter
Definition: pollset_posix.h:56
grpc_kick_read_fd
int grpc_kick_read_fd(grpc_pollset *p)
arg
struct arg arg
sync.h
grpc_poll_become_multipoller
void grpc_poll_become_multipoller(grpc_pollset *pollset, struct grpc_fd **fds, size_t fd_count)
grpc_pollset::kick_state
grpc_pollset_kick_state kick_state
Definition: pollset_posix.h:55
grpc_pollset_add_fd
void grpc_pollset_add_fd(grpc_pollset *pollset, struct grpc_fd *fd)
grpc_pollset_kick_state
Definition: pollset_kick_posix.h:53
grpc_pollset::shutting_down
int shutting_down
Definition: pollset_posix.h:58
gpr_timespec
Definition: time.h:60
grpc_pollset::shutdown_done_cb
void(* shutdown_done_cb)(void *arg)
Definition: pollset_posix.h:60
grpc_poll_deadline_to_millis_timeout
int grpc_poll_deadline_to_millis_timeout(gpr_timespec deadline, gpr_timespec now)
grpc_pollset::in_flight_cbs
int in_flight_cbs
Definition: pollset_posix.h:57
grpc_pollset_vtable::add_fd
void(* add_fd)(grpc_pollset *pollset, struct grpc_fd *fd, int and_unlock_pollset)
Definition: pollset_posix.h:69
grpc_pollset_del_fd
void grpc_pollset_del_fd(grpc_pollset *pollset, struct grpc_fd *fd)
grpc_pollset::vtable
const grpc_pollset_vtable * vtable
Definition: pollset_posix.h:53
grpc_pollset::called_shutdown
int called_shutdown
Definition: pollset_posix.h:59
grpc_kick_drain
void grpc_kick_drain(grpc_pollset *p)
grpc_fd
Definition: fd_posix.h:52
grpc_pollset_vtable::kick
void(* kick)(grpc_pollset *pollset)
Definition: pollset_posix.h:75