pollset.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_CORE_LIB_IOMGR_POLLSET_H
20 #define GRPC_CORE_LIB_IOMGR_POLLSET_H
21 
23 
24 #include <grpc/support/sync.h>
25 #include <grpc/support/time.h>
26 
28 
30 
31 /* A grpc_pollset is a set of file descriptors that a higher level item is
32  interested in. For example:
33  - a server will typically keep a pollset containing all connected channels,
34  so that it can find new calls to service
35  - a completion queue might keep a pollset with an entry for each transport
36  that is servicing a call that it's tracking */
37 
38 typedef struct grpc_pollset grpc_pollset;
40 
41 typedef struct grpc_pollset_vtable {
42  void (*global_init)(void);
43  void (*global_shutdown)(void);
44  void (*init)(grpc_pollset* pollset, gpr_mu** mu);
46  void (*destroy)(grpc_pollset* pollset);
48  grpc_core::Timestamp deadline);
50  grpc_pollset_worker* specific_worker);
51  size_t (*pollset_size)(void);
53 
55 
56 void grpc_pollset_global_init(void);
58 
59 size_t grpc_pollset_size(void);
60 /* Initialize a pollset: assumes *pollset contains all zeros */
61 void grpc_pollset_init(grpc_pollset* pollset, gpr_mu** mu);
62 /* Begin shutting down the pollset, and call closure when done.
63  * pollset's mutex must be held */
65 void grpc_pollset_destroy(grpc_pollset* pollset);
66 
67 /* Do some work on a pollset.
68  May involve invoking asynchronous callbacks, or actually polling file
69  descriptors.
70  Requires pollset's mutex locked.
71  May unlock its mutex during its execution.
72 
73  worker is a (platform-specific) handle that can be used to wake up
74  from grpc_pollset_work before any events are received and before the timeout
75  has expired. It is both initialized and destroyed by grpc_pollset_work.
76  Initialization of worker is guaranteed to occur BEFORE the
77  pollset's mutex is released for the first time by grpc_pollset_work
78  and it is guaranteed that it will not be released by grpc_pollset_work
79  AFTER worker has been destroyed.
80 
81  It's legal for worker to be NULL: in that case, this specific thread can not
82  be directly woken with a kick, but maybe be indirectly (with a kick against
83  the pollset as a whole).
84 
85  Tries not to block past deadline.
86  May call grpc_closure_list_run on grpc_closure_list, without holding the
87  pollset
88  lock */
92 
93 /* Break one polling thread out of polling work for this pollset.
94  If specific_worker is non-NULL, then kick that worker. */
96  grpc_pollset_worker* specific_worker)
98 
99 #endif /* GRPC_CORE_LIB_IOMGR_POLLSET_H */
grpc_pollset_worker
struct grpc_pollset_worker grpc_pollset_worker
Definition: pollset.h:39
grpc_pollset_vtable
Definition: pollset.h:41
vtable
static const grpc_transport_vtable vtable
Definition: binder_transport.cc:680
grpc_trace_fd_refcount
grpc_core::DebugOnlyTraceFlag grpc_trace_fd_refcount
worker
static void worker(void *arg)
Definition: threadpool.c:57
grpc_core::Timestamp
Definition: src/core/lib/gprpp/time.h:62
time.h
grpc_pollset_vtable::init
void(* init)(grpc_pollset *pollset, gpr_mu **mu)
Definition: pollset.h:44
grpc_pollset_shutdown
void grpc_pollset_shutdown(grpc_pollset *pollset, grpc_closure *closure)
Definition: pollset.cc:37
mu
Mutex mu
Definition: server_config_selector_filter.cc:74
worker
Definition: worker.py:1
grpc_pollset_vtable::pollset_size
size_t(* pollset_size)(void)
Definition: pollset.h:51
closure
grpc_closure closure
Definition: src/core/lib/surface/server.cc:466
grpc_error_handle
grpc_error * grpc_error_handle
Definition: error.h:50
grpc_pollset_vtable::destroy
void(* destroy)(grpc_pollset *pollset)
Definition: pollset.h:46
grpc_pollset_destroy
void grpc_pollset_destroy(grpc_pollset *pollset)
Definition: pollset.cc:41
grpc_pollset_vtable
struct grpc_pollset_vtable grpc_pollset_vtable
grpc_set_pollset_vtable
void grpc_set_pollset_vtable(grpc_pollset_vtable *vtable)
Definition: pollset.cc:25
grpc_pollset_work
grpc_error_handle grpc_pollset_work(grpc_pollset *pollset, grpc_pollset_worker **worker, grpc_core::Timestamp deadline) GRPC_MUST_USE_RESULT
Definition: pollset.cc:45
grpc_pollset_global_init
void grpc_pollset_global_init(void)
Definition: pollset.cc:29
grpc_pollset_vtable::global_shutdown
void(* global_shutdown)(void)
Definition: pollset.h:43
grpc_pollset_vtable::global_init
void(* global_init)(void)
Definition: pollset.h:42
grpc_core::TraceFlag
Definition: debug/trace.h:63
grpc_pollset_global_shutdown
void grpc_pollset_global_shutdown(void)
Definition: pollset.cc:31
GRPC_MUST_USE_RESULT
#define GRPC_MUST_USE_RESULT
Definition: impl/codegen/port_platform.h:584
gpr_mu
pthread_mutex_t gpr_mu
Definition: impl/codegen/sync_posix.h:47
grpc_pollset_vtable::kick
grpc_error_handle(* kick)(grpc_pollset *pollset, grpc_pollset_worker *specific_worker)
Definition: pollset.h:49
exec_ctx.h
grpc_pollset_vtable::shutdown
void(* shutdown)(grpc_pollset *pollset, grpc_closure *closure)
Definition: pollset.h:45
closure
Definition: proxy.cc:59
grpc_pollset_size
size_t grpc_pollset_size(void)
Definition: pollset.cc:56
grpc_error
Definition: error_internal.h:42
grpc_pollset_init
void grpc_pollset_init(grpc_pollset *pollset, gpr_mu **mu)
Definition: pollset.cc:33
grpc_pollset
Definition: bm_cq_multiple_threads.cc:37
sync.h
grpc_closure
Definition: closure.h:56
grpc_pollset_kick
grpc_error_handle grpc_pollset_kick(grpc_pollset *pollset, grpc_pollset_worker *specific_worker) GRPC_MUST_USE_RESULT
Definition: pollset.cc:51
grpc_pollset_vtable::work
grpc_error_handle(* work)(grpc_pollset *pollset, grpc_pollset_worker **worker, grpc_core::Timestamp deadline)
Definition: pollset.h:47
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:53