Main Page
Related Pages
Modules
Namespaces
Namespace List
Namespace Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
y
z
Enumerations
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
r
s
t
u
v
w
Enumerator
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
z
Classes
Class List
Class Hierarchy
Class Members
All
:
[
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
[
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
y
Enumerations
a
b
c
d
e
f
h
i
k
l
m
n
o
p
r
s
t
u
v
w
Enumerator
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
z
Properties
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
Related Functions
:
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
q
r
s
t
u
v
w
z
Files
File List
File Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Enumerations
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
t
u
v
w
x
Enumerator
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
Macros
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
grpc
src
core
lib
gprpp
thd.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_GPRPP_THD_H
20
#define GRPC_CORE_LIB_GPRPP_THD_H
21
24
#include <
grpc/support/port_platform.h
>
25
26
#include <stddef.h>
27
28
#include <
grpc/support/log.h
>
29
30
namespace
grpc_core
{
31
namespace
internal
{
32
34
class
ThreadInternalsInterface
{
35
public
:
36
virtual
~ThreadInternalsInterface
() {}
37
virtual
void
Start
() = 0;
38
virtual
void
Join
() = 0;
39
};
40
41
}
// namespace internal
42
43
class
Thread
{
44
public
:
45
class
Options
{
46
public
:
47
Options
() :
joinable_
(
true
),
tracked_
(
true
),
stack_size_
(0) {}
49
Options
&
set_joinable
(
bool
joinable
) {
50
joinable_
=
joinable
;
51
return
*
this
;
52
}
53
bool
joinable
()
const
{
return
joinable_
; }
54
56
Options
&
set_tracked
(
bool
tracked
) {
57
tracked_
=
tracked
;
58
return
*
this
;
59
}
60
bool
tracked
()
const
{
return
tracked_
; }
61
64
Options
&
set_stack_size
(
size_t
bytes
) {
65
stack_size_
=
bytes
;
66
return
*
this
;
67
}
68
size_t
stack_size
()
const
{
return
stack_size_
; }
69
70
private
:
71
bool
joinable_
;
72
bool
tracked_
;
73
size_t
stack_size_
;
74
};
78
Thread
() :
state_
(
FAKE
),
impl_
(nullptr) {}
79
86
Thread
(
const
char
* thd_name,
void
(*thd_body)(
void
*
arg
),
void
*
arg
,
87
bool
* success =
nullptr
,
const
Options&
options
= Options());
88
91
Thread
(
Thread
&& other) noexcept
92
:
state_
(other.state_),
impl_
(other.impl_),
options_
(other.options_) {
93
other.state_ =
MOVED
;
94
other.impl_ =
nullptr
;
95
other.options_ =
Options
();
96
}
97
101
Thread
&
operator=
(
Thread
&& other) noexcept {
102
if
(
this
!= &other) {
103
// TODO(vjpai): if we can be sure that all Thread's are actually
104
// constructed, then we should assert GPR_ASSERT(impl_ == nullptr) here.
105
// However, as long as threads come in structures that are
106
// allocated via gpr_malloc, this will not be the case, so we cannot
107
// assert it for the time being.
108
state_
= other.state_;
109
impl_
= other.impl_;
110
options_
= other.options_;
111
other.state_ =
MOVED
;
112
other.impl_ =
nullptr
;
113
other.options_ =
Options
();
114
}
115
return
*
this
;
116
}
117
123
~Thread
() {
GPR_ASSERT
(!
options_
.
joinable
() ||
impl_
==
nullptr
); }
124
125
void
Start
() {
126
if
(
impl_
!=
nullptr
) {
127
GPR_ASSERT
(
state_
==
ALIVE
);
128
state_
=
STARTED
;
129
impl_
->
Start
();
130
// If the Thread is not joinable, then the impl_ will cause the deletion
131
// of this Thread object when the thread function completes. Since no
132
// other operation is allowed to a detached thread after Start, there is
133
// no need to change the value of the impl_ or state_ . The next operation
134
// on this object will be the deletion, which will trigger the destructor.
135
}
else
{
136
GPR_ASSERT
(
state_
==
FAILED
);
137
}
138
}
139
140
// It is only legal to call Join if the Thread is created as joinable.
141
void
Join
() {
142
if
(
impl_
!=
nullptr
) {
143
impl_
->
Join
();
144
delete
impl_
;
145
state_
=
DONE
;
146
impl_
=
nullptr
;
147
}
else
{
148
GPR_ASSERT
(
state_
==
FAILED
);
149
}
150
}
151
152
private
:
153
Thread
(
const
Thread
&) =
delete
;
154
Thread
&
operator=
(
const
Thread
&) =
delete
;
155
163
enum
ThreadState
{
FAKE
,
ALIVE
,
STARTED
,
DONE
,
FAILED
,
MOVED
};
164
ThreadState
state_
;
165
internal::ThreadInternalsInterface
*
impl_
;
166
Options
options_
;
167
};
168
169
}
// namespace grpc_core
170
171
#endif
/* GRPC_CORE_LIB_GPRPP_THD_H */
grpc_core::Thread::FAILED
@ FAILED
Definition:
thd.h:163
log.h
grpc_core::Thread::ThreadState
ThreadState
Definition:
thd.h:163
grpc_core::Thread::operator=
Thread & operator=(Thread &&other) noexcept
Definition:
thd.h:101
grpc_core::Thread::options_
Options options_
Definition:
thd.h:166
grpc_core::Thread::state_
ThreadState state_
Definition:
thd.h:164
grpc_core
Definition:
call_metric_recorder.h:31
options
double_dict options[]
Definition:
capstone_test.c:55
grpc_core::internal::ThreadInternalsInterface
Base class for platform-specific thread-state.
Definition:
thd.h:34
grpc_core::Thread::Options::tracked_
bool tracked_
Definition:
thd.h:72
grpc_core::Thread::Thread
Thread(Thread &&other) noexcept
Definition:
thd.h:91
grpc_core::Thread::Options::joinable
bool joinable() const
Definition:
thd.h:53
grpc_core::Thread::Options::Options
Options()
Definition:
thd.h:47
true
#define true
Definition:
setup_once.h:324
grpc_core::Thread::Options::tracked
bool tracked() const
Definition:
thd.h:60
GPR_ASSERT
#define GPR_ASSERT(x)
Definition:
include/grpc/impl/codegen/log.h:94
grpc_core::Thread::~Thread
~Thread()
Definition:
thd.h:123
grpc_core::Thread::DONE
@ DONE
Definition:
thd.h:163
arg
Definition:
cmdline.cc:40
grpc_core::Thread::Thread
Thread()
Definition:
thd.h:78
grpc_core::Thread::Join
void Join()
Definition:
thd.h:141
grpc_core::Thread::Options::set_stack_size
Options & set_stack_size(size_t bytes)
Definition:
thd.h:64
grpc_core::Thread::ALIVE
@ ALIVE
Definition:
thd.h:163
grpc_core::Thread::Options::stack_size
size_t stack_size() const
Definition:
thd.h:68
grpc_core::Thread::Options
Definition:
thd.h:45
grpc_core::Thread::Start
void Start()
Definition:
thd.h:125
grpc_core::Thread::FAKE
@ FAKE
Definition:
thd.h:163
grpc_core::internal::ThreadInternalsInterface::Start
virtual void Start()=0
grpc_core::Thread::Options::set_joinable
Options & set_joinable(bool joinable)
Set whether the thread is joinable or detached.
Definition:
thd.h:49
grpc_core::Thread::MOVED
@ MOVED
Definition:
thd.h:163
grpc_core::Thread::impl_
internal::ThreadInternalsInterface * impl_
Definition:
thd.h:165
grpc_core::internal::ThreadInternalsInterface::~ThreadInternalsInterface
virtual ~ThreadInternalsInterface()
Definition:
thd.h:36
bytes
uint8 bytes[10]
Definition:
bloaty/third_party/protobuf/src/google/protobuf/io/coded_stream_unittest.cc:153
grpc_core::Thread::Options::stack_size_
size_t stack_size_
Definition:
thd.h:73
grpc_core::Thread
Definition:
thd.h:43
grpc_core::Thread::STARTED
@ STARTED
Definition:
thd.h:163
grpc_core::Thread::Options::set_tracked
Options & set_tracked(bool tracked)
Set whether the thread is tracked for fork support.
Definition:
thd.h:56
internal
Definition:
benchmark/test/output_test_helper.cc:20
grpc_core::internal::ThreadInternalsInterface::Join
virtual void Join()=0
grpc_core::Thread::Options::joinable_
bool joinable_
Definition:
thd.h:71
port_platform.h
grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:36