Debian Codegraph @

src/core/lib/promise/intra_activity_waiter.h

raw
1 // Copyright 2021 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #ifndef GRPC_CORE_LIB_PROMISE_INTRA_ACTIVITY_WAITER_H
16 #define GRPC_CORE_LIB_PROMISE_INTRA_ACTIVITY_WAITER_H
17
18 #include <grpc/support/port_platform.h>
19
20 #include "src/core/lib/promise/activity.h"
21 #include "src/core/lib/promise/poll.h"
22
23 namespace grpc_core {
24
25 // Helper type to track wakeups between objects in the same activity.
26 // Can be fairly fast as no ref counting or locking needs to occur.
27 class IntraActivityWaiter {
28 public:
29 // Register for wakeup, return Pending(). If state is not ready to proceed,
30 // Promises should bottom out here.
31 Pending pending() {
32 waiting_ = true;
33 return Pending();
34 }
35 // Wake the activity
36 void Wake() {
37 if (waiting_) {
38 waiting_ = false;
39 Activity::current()->ForceImmediateRepoll();
40 }
41 }
42
43 private:
44 bool waiting_ = false;
45 };
46
47 } // namespace grpc_core
48
49 #endif // GRPC_CORE_LIB_PROMISE_INTRA_ACTIVITY_WAITER_H