19 #ifndef GRPC_CORE_LIB_GPRPP_THD_H 20 #define GRPC_CORE_LIB_GPRPP_THD_H 40 virtual void Start() = 0;
41 virtual void Join() = 0;
50 Options() : joinable_(true), tracked_(true), stack_size_(0) {}
81 Thread() : state_(FAKE), impl_(nullptr) {}
89 Thread(
const char* thd_name,
void (*thd_body)(
void* arg),
void* arg,
90 bool* success =
nullptr,
const Options& options = Options());
95 : state_(other.state_), impl_(other.impl_), options_(other.options_) {
97 other.impl_ =
nullptr;
105 if (
this != &other) {
111 state_ = other.state_;
113 options_ = other.options_;
114 other.state_ = MOVED;
115 other.impl_ =
nullptr;
129 if (impl_ !=
nullptr) {
145 if (impl_ !=
nullptr) {
166 enum ThreadState { FAKE, ALIVE, STARTED, DONE, FAILED, MOVED };
168 internal::ThreadInternalsInterface* impl_;
Thread(Thread &&other)
Move constructor for thread.
Definition: thd.h:94
Definition: executor.h:30
Thread()
Default constructor only to allow use in structs that lack constructors Does not produce a validly-co...
Definition: thd.h:81
Thread & operator=(Thread &&other)
Move assignment operator for thread.
Definition: thd.h:104
size_t stack_size() const
Definition: thd.h:71
void Join()
Definition: thd.h:144
Internal thread interface.
Definition: backoff.h:26
virtual ~ThreadInternalsInterface()
Definition: thd.h:39
~Thread()
The destructor is strictly optional; either the thread never came to life and the constructor itself ...
Definition: thd.h:126
Options()
Definition: thd.h:50
bool tracked() const
Definition: thd.h:63
#define GPR_ASSERT(x)
abort() the process if x is zero, having written a line to the log.
Definition: log.h:94
Base class for platform-specific thread-state.
Definition: thd.h:37
Options & set_tracked(bool tracked)
Set whether the thread is tracked for fork support.
Definition: thd.h:59
bool joinable() const
Definition: thd.h:56
Options & set_joinable(bool joinable)
Set whether the thread is joinable or detached.
Definition: thd.h:52
void Start()
Definition: thd.h:128
Options & set_stack_size(size_t bytes)
Sets thread stack size (in bytes).
Definition: thd.h:67