diff options
Diffstat (limited to 'include/grpc++')
-rw-r--r-- | include/grpc++/impl/thd_no_cxx11.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/include/grpc++/impl/thd_no_cxx11.h b/include/grpc++/impl/thd_no_cxx11.h index 84d03ce184..3f981d3770 100644 --- a/include/grpc++/impl/thd_no_cxx11.h +++ b/include/grpc++/impl/thd_no_cxx11.h @@ -46,10 +46,21 @@ class thread { joined_ = false; start(); } + template <class T, class U> + thread(void (T::*fptr)(U arg), T *obj, U arg) { + func_ = new thread_function_arg<T, U>(fptr, obj, arg); + joined_ = false; + start(); + } ~thread() { if (!joined_) std::terminate(); delete func_; } + thread(thread &&other) + : func_(other.func_), thd_(other.thd_), joined_(other.joined_) { + other.joined_ = true; + other.func_ = NULL; + } void join() { gpr_thd_join(thd_); joined_ = true; @@ -80,6 +91,18 @@ class thread { void (T::*fptr_)(); T *obj_; }; + template <class T, class U> + class thread_function_arg : public thread_function_base { + public: + thread_function_arg(void (T::*fptr)(U arg), T *obj, U arg) + : fptr_(fptr), obj_(obj), arg_(arg) {} + virtual void call() { (obj_->*fptr_)(arg_); } + + private: + void (T::*fptr_)(U arg); + T *obj_; + U arg_; + }; thread_function_base *func_; gpr_thd_id thd_; bool joined_; |