GRPC Core  0.10.0.0
 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 
40 
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 */
56  int counter;
60  void (*shutdown_done_cb)(void *arg);
62  union {
63  int fd;
64  void *ptr;
65  } data;
66 } grpc_pollset;
67 
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. */
94 /* Returns the fd to listen on for kicks */
96 /* Call after polling has been kicked to leave the kicked state */
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 */
107 
108 /* turn a pollset into a multipoller: platform specific */
110  struct grpc_fd **fds,
111  size_t fd_count);
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_type grpc_platform_become_multipoller
void(* destroy)(grpc_pollset *pollset)
Definition: pollset_posix.h:77
int fd
Definition: fd_posix.h:53
void * ptr
Definition: pollset_posix.h:64
void(* del_fd)(grpc_pollset *pollset, struct grpc_fd *fd, int and_unlock_pollset)
Definition: pollset_posix.h:71
void(* grpc_platform_become_multipoller_type)(grpc_pollset *pollset, struct grpc_fd **fds, size_t fd_count)
Definition: pollset_posix.h:109
union grpc_pollset::@13 data
void * shutdown_done_arg
Definition: pollset_posix.h:61
Definition: pollset_posix.h:68
int fd
Definition: pollset_posix.h:63
gpr_mu mu
Definition: pollset_posix.h:54
Definition: pollset_posix.h:48
struct grpc_pollset grpc_pollset
void(* finish_shutdown)(grpc_pollset *pollset)
Definition: pollset_posix.h:76
void grpc_pollset_force_kick(grpc_pollset *pollset)
Definition: sync_win32.h:39
void(* maybe_work)(grpc_pollset *pollset, gpr_timespec deadline, gpr_timespec now, int allow_synchronous_callback)
Definition: pollset_posix.h:73
int counter
Definition: pollset_posix.h:56
int grpc_kick_read_fd(grpc_pollset *p)
struct arg arg
void grpc_poll_become_multipoller(grpc_pollset *pollset, struct grpc_fd **fds, size_t fd_count)
grpc_pollset_kick_state kick_state
Definition: pollset_posix.h:55
void grpc_pollset_add_fd(grpc_pollset *pollset, struct grpc_fd *fd)
Definition: pollset_kick_posix.h:53
int shutting_down
Definition: pollset_posix.h:58
Definition: time.h:60
void(* shutdown_done_cb)(void *arg)
Definition: pollset_posix.h:60
int grpc_poll_deadline_to_millis_timeout(gpr_timespec deadline, gpr_timespec now)
int in_flight_cbs
Definition: pollset_posix.h:57
void(* add_fd)(grpc_pollset *pollset, struct grpc_fd *fd, int and_unlock_pollset)
Definition: pollset_posix.h:69
void grpc_pollset_del_fd(grpc_pollset *pollset, struct grpc_fd *fd)
const grpc_pollset_vtable * vtable
Definition: pollset_posix.h:53
int called_shutdown
Definition: pollset_posix.h:59
void grpc_kick_drain(grpc_pollset *p)
Definition: fd_posix.h:52
void(* kick)(grpc_pollset *pollset)
Definition: pollset_posix.h:75