aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/grpc++/impl
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2015-11-20 15:37:54 -0800
committerGravatar Craig Tiller <ctiller@google.com>2015-11-20 15:37:54 -0800
commit52a2ebadcbc40d369d52e0a764616223d1233317 (patch)
tree2ee58a5f44dfeaab6e5f3fd4d682269909380981 /include/grpc++/impl
parent220c2b4a42098d5395ef9fa814d72b7a4638d512 (diff)
Two argument variant for grpc::thread
Diffstat (limited to 'include/grpc++/impl')
-rw-r--r--include/grpc++/impl/thd_no_cxx11.h23
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_;