34 #ifndef GRPCXX_IMPL_THD_NO_CXX11_H 35 #define GRPCXX_IMPL_THD_NO_CXX11_H 37 #include <grpc/support/thd.h> 45 func_ =
new thread_function<T>(fptr, obj);
49 template <
class T,
class U>
50 thread(
void (T::*fptr)(U arg), T *obj, U arg) {
51 func_ =
new thread_function_arg<T, U>(fptr, obj, arg);
56 if (!joined_) std::terminate();
60 : func_(other.func_), thd_(other.thd_), joined_(other.joined_) {
71 gpr_thd_options options = gpr_thd_options_default();
72 gpr_thd_options_set_joinable(&options);
73 gpr_thd_new(&thd_, thread_func, (
void *)func_, &options);
75 static void thread_func(
void *arg) {
76 thread_function_base *func = (thread_function_base *)arg;
79 class thread_function_base {
81 virtual ~thread_function_base() {}
82 virtual void call() = 0;
85 class thread_function :
public thread_function_base {
87 thread_function(
void (T::*fptr)(), T *obj) : fptr_(fptr), obj_(obj) {}
88 virtual void call() { (obj_->*fptr_)(); }
94 template <
class T,
class U>
95 class thread_function_arg :
public thread_function_base {
97 thread_function_arg(
void (T::*fptr)(U arg), T *obj, U arg)
98 : fptr_(fptr), obj_(obj), arg_(arg) {}
99 virtual void call() { (obj_->*fptr_)(arg_); }
102 void (T::*fptr_)(U arg);
106 thread_function_base *func_;
112 void operator=(
const thread &);
117 #endif // GRPCXX_IMPL_THD_NO_CXX11_H thread(void(T::*fptr)(), T *obj)
Definition: thd_no_cxx11.h:44
void join()
Definition: thd_no_cxx11.h:64
Definition: thd_no_cxx11.h:41
~thread()
Definition: thd_no_cxx11.h:55
thread(thread &&other)
Definition: thd_no_cxx11.h:59
thread(void(T::*fptr)(U arg), T *obj, U arg)
Definition: thd_no_cxx11.h:50