From 52a2ebadcbc40d369d52e0a764616223d1233317 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 20 Nov 2015 15:37:54 -0800 Subject: [PATCH] Two argument variant for grpc::thread --- include/grpc++/impl/thd_no_cxx11.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/grpc++/impl/thd_no_cxx11.h b/include/grpc++/impl/thd_no_cxx11.h index 84d03ce1847..3f981d3770f 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 + thread(void (T::*fptr)(U arg), T *obj, U arg) { + func_ = new thread_function_arg(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 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_;