diff options
author | Sree Kuchibhotla <sreecha@users.noreply.github.com> | 2015-11-23 09:02:01 -0800 |
---|---|---|
committer | Sree Kuchibhotla <sreecha@users.noreply.github.com> | 2015-11-23 09:02:01 -0800 |
commit | 9c256980edea8d780f94e85d2f13ccb0e6d34ea7 (patch) | |
tree | 2cba9d2dd8b2e39efe9eb42b94ff3442bb0c0c57 | |
parent | ceb7318d794b4174e18364f6780a5d20e6249e23 (diff) | |
parent | 52a2ebadcbc40d369d52e0a764616223d1233317 (diff) |
Merge pull request #4192 from ctiller/stupid-threads
Two argument variant for grpc::thread
-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_; |