GRPC C++
1.26.0
src
core
lib
iomgr
lockfree_event.h
Go to the documentation of this file.
1
/*
2
*
3
* Copyright 2017 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_LOCKFREE_EVENT_H
20
#define GRPC_CORE_LIB_IOMGR_LOCKFREE_EVENT_H
21
22
/* Lock free event notification for file descriptors */
23
24
#include <
grpc/support/port_platform.h
>
25
26
#include <
grpc/support/atm.h
>
27
28
#include "
src/core/lib/iomgr/closure.h
"
29
30
namespace
grpc_core
{
31
32
class
LockfreeEvent
{
33
public
:
34
LockfreeEvent
();
35
36
LockfreeEvent
(
const
LockfreeEvent
&) =
delete
;
37
LockfreeEvent
&
operator=
(
const
LockfreeEvent
&) =
delete
;
38
39
// These methods are used to initialize and destroy the internal state. These
40
// cannot be done in constructor and destructor because SetReady may be called
41
// when the event is destroyed and put in a freelist.
42
void
InitEvent
();
43
void
DestroyEvent
();
44
45
// Returns true if fd has been shutdown, false otherwise.
46
bool
IsShutdown
()
const
{
47
return
(
gpr_atm_no_barrier_load
(&state_) & kShutdownBit) != 0;
48
}
49
50
// Schedules \a closure when the event is received (see SetReady()) or the
51
// shutdown state has been set. Note that the event may have already been
52
// received, in which case the closure would be scheduled immediately.
53
// If the shutdown state has already been set, then \a closure is scheduled
54
// with the shutdown error.
55
void
NotifyOn
(
grpc_closure
* closure);
56
57
// Sets the shutdown state. If a closure had been provided by NotifyOn and has
58
// not yet been scheduled, it will be scheduled with \a error.
59
bool
SetShutdown
(
grpc_error
* error);
60
61
// Signals that the event has been received.
62
void
SetReady
();
63
64
private
:
65
enum
State { kClosureNotReady = 0, kClosureReady = 2, kShutdownBit = 1 };
66
67
gpr_atm
state_;
68
};
69
70
}
// namespace grpc_core
71
72
#endif
/* GRPC_CORE_LIB_IOMGR_LOCKFREE_EVENT_H */
grpc_core::LockfreeEvent::SetShutdown
bool SetShutdown(grpc_error *error)
gpr_atm_no_barrier_load
#define gpr_atm_no_barrier_load(p)
Definition:
atm_gcc_atomic.h:51
grpc_core::LockfreeEvent::LockfreeEvent
LockfreeEvent()
grpc_core::LockfreeEvent::operator=
LockfreeEvent & operator=(const LockfreeEvent &)=delete
grpc_core
Internal thread interface.
Definition:
backoff.h:26
grpc_core::LockfreeEvent::IsShutdown
bool IsShutdown() const
Definition:
lockfree_event.h:46
closure.h
grpc_core::LockfreeEvent::NotifyOn
void NotifyOn(grpc_closure *closure)
grpc_core::LockfreeEvent::DestroyEvent
void DestroyEvent()
grpc_core::LockfreeEvent::SetReady
void SetReady()
gpr_atm
intptr_t gpr_atm
Definition:
atm_gcc_atomic.h:30
grpc_core::LockfreeEvent::InitEvent
void InitEvent()
grpc_core::LockfreeEvent
Definition:
lockfree_event.h:32
atm.h
grpc_error
Definition:
error_internal.h:39
grpc_closure
A closure over a grpc_iomgr_cb_func.
Definition:
closure.h:56
grpc_core::LockfreeEvent::LockfreeEvent
LockfreeEvent(const LockfreeEvent &)=delete
port_platform.h
Generated on Wed Sep 13 2023 00:00:00 for GRPC C++ by
1.8.20