Addressing concerns.

pull/1185/head
Nicolas "Pixel" Noble 10 years ago
parent d81684f191
commit b092916a2a
  1. 3
      include/grpc++/impl/sync.h
  2. 13
      include/grpc++/impl/sync_no_cxx11.h
  3. 3
      include/grpc++/impl/thd.h
  4. 16
      include/grpc++/impl/thd_no_cxx11.h

@ -37,10 +37,9 @@
#include <grpc++/config.h>
#ifdef GRPC_CXX0X_NO_THREAD
#include <grpc++/impl/sync_nocxx11.h>
#include <grpc++/impl/sync_no_cxx11.h>
#else
#include <grpc++/impl/sync_cxx11.h>
#endif
#endif // GRPCXX_IMPL_SYNC_H

@ -56,13 +56,14 @@ class mutex {
template <class mutex>
class lock_guard {
public:
lock_guard(mutex &mu) : mu_(mu), locked(true) { gpr_mu_lock(&mu.mu_); }
~lock_guard() { unlock(); }
void lock() {
lock_guard(mutex &mu) : mu_(mu), locked(true) { gpr_mu_lock(&mu.mu_); }
~lock_guard() { unlock_internal(); }
protected:
void lock_internal() {
if (!locked) gpr_mu_lock(&mu_.mu_);
locked = true;
}
void unlock() {
void unlock_internal() {
if (locked) gpr_mu_unlock(&mu_.mu_);
locked = false;
}
@ -75,7 +76,9 @@ class lock_guard {
template <class mutex>
class unique_lock : public lock_guard<mutex> {
public:
unique_lock(mutex &mu) : lock_guard(mu) { }
unique_lock(mutex &mu) : lock_guard(mu) { }
void lock() { lock_internal(); }
void unlock() { unlock_internal(); }
};
class condition_variable {

@ -37,10 +37,9 @@
#include <grpc++/config.h>
#ifdef GRPC_CXX0X_NO_THREAD
#include <grpc++/impl/thd_nocxx11.h>
#include <grpc++/impl/thd_no_cxx11.h>
#else
#include <grpc++/impl/thd_cxx11.h>
#endif
#endif // GRPCXX_IMPL_THD_H

@ -42,15 +42,22 @@ class thread {
public:
template<class T> thread(void (T::*fptr)(), T *obj) {
func_ = new thread_function<T>(fptr, obj);
joined_ = false;
start();
}
~thread() { delete func_; }
void join() { gpr_thd_join(thd); }
~thread() {
if (!joined_) std::terminate();
delete func_;
}
void join() {
gpr_thd_join(thd_);
joined_ = true;
}
private:
void start() {
gpr_thd_options options = gpr_thd_options_default();
gpr_thd_options_set_joinable(&options);
gpr_thd_new(&thd, thread_func, (void *) func_, &options);
gpr_thd_new(&thd_, thread_func, (void *) func_, &options);
}
static void thread_func(void *arg) {
thread_function_base *func = (thread_function_base *) arg;
@ -73,7 +80,8 @@ class thread {
T *obj_;
};
thread_function_base *func_;
gpr_thd_id thd;
gpr_thd_id thd_;
bool joined_;
};
} // namespace grpc

Loading…
Cancel
Save