GRPC C++  1.26.0
combiner.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2016 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_COMBINER_H
20 #define GRPC_CORE_LIB_IOMGR_COMBINER_H
21 
23 
24 #include <stddef.h>
25 
26 #include <grpc/support/atm.h>
29 
30 namespace grpc_core {
31 // TODO(yashkt) : Remove this class and replace it with a class that does not
32 // use ExecCtx
33 class Combiner {
34  public:
35  void Run(grpc_closure* closure, grpc_error* error);
36  // TODO(yashkt) : Remove this method
37  void FinallyRun(grpc_closure* closure, grpc_error* error);
40  // either:
41  // a pointer to the initiating exec ctx if that is the only exec_ctx that has
42  // ever queued to this combiner, or NULL. If this is non-null, it's not
43  // dereferencable (since the initiating exec_ctx may have gone out of scope)
45  // state is:
46  // lower bit - zero if orphaned (STATE_UNORPHANED)
47  // other bits - number of items queued on the lock (STATE_ELEM_COUNT_LOW_BIT)
53 };
54 } // namespace grpc_core
55 
56 // Provides serialized access to some resource.
57 // Each action queued on a combiner is executed serially in a borrowed thread.
58 // The actual thread executing actions may change over time (but there will only
59 // ever be one at a time).
60 
61 // Initialize the lock, with an optional workqueue to shift load to when
62 // necessary
64 
65 #ifndef NDEBUG
66 #define GRPC_COMBINER_DEBUG_ARGS \
67  , const char *file, int line, const char *reason
68 #define GRPC_COMBINER_REF(combiner, reason) \
69  grpc_combiner_ref((combiner), __FILE__, __LINE__, (reason))
70 #define GRPC_COMBINER_UNREF(combiner, reason) \
71  grpc_combiner_unref((combiner), __FILE__, __LINE__, (reason))
72 #else
73 #define GRPC_COMBINER_DEBUG_ARGS
74 #define GRPC_COMBINER_REF(combiner, reason) grpc_combiner_ref((combiner))
75 #define GRPC_COMBINER_UNREF(combiner, reason) grpc_combiner_unref((combiner))
76 #endif
77 
78 // Ref/unref the lock, for when we're sharing the lock ownership
79 // Prefer to use the macros above
83 
85 
87 
88 #endif /* GRPC_CORE_LIB_IOMGR_COMBINER_H */
grpc_closure_list final_list
Definition: combiner.h:50
Definition: sync_generic.h:36
grpc_closure offload
Definition: combiner.h:51
Definition: error_internal.h:39
bool grpc_combiner_continue_exec_ctx()
Definition: closure.h:41
Internal thread interface.
Definition: backoff.h:26
#define GRPC_COMBINER_DEBUG_ARGS
Definition: combiner.h:66
Definition: trace.h:61
grpc_core::DebugOnlyTraceFlag grpc_combiner_trace
bool time_to_execute_final_list
Definition: combiner.h:49
gpr_atm state
Definition: combiner.h:48
gpr_atm initiating_exec_ctx_or_null
Definition: combiner.h:44
Definition: combiner.h:33
void grpc_combiner_unref(grpc_core::Combiner *lock, const char *file, int line, const char *reason)
MultiProducerSingleConsumerQueue queue
Definition: combiner.h:39
intptr_t gpr_atm
Definition: atm_gcc_atomic.h:30
grpc_core::Combiner * grpc_combiner_ref(grpc_core::Combiner *lock, const char *file, int line, const char *reason)
A closure over a grpc_iomgr_cb_func.
Definition: closure.h:56
void FinallyRun(grpc_closure *closure, grpc_error *error)
void Run(grpc_closure *closure, grpc_error *error)
grpc_core::Combiner * grpc_combiner_create(void)
gpr_refcount refs
Definition: combiner.h:52
Combiner * next_combiner_on_this_exec_ctx
Definition: combiner.h:38