diff options
-rw-r--r-- | condvar.cc | 4 | ||||
-rw-r--r-- | condvar.h | 2 | ||||
-rw-r--r-- | mutex.cc | 8 | ||||
-rw-r--r-- | mutex.h | 14 | ||||
-rw-r--r-- | ninja.cc | 4 | ||||
-rw-r--r-- | regen.cc | 6 | ||||
-rw-r--r-- | stats.cc | 10 | ||||
-rw-r--r-- | stats.h | 2 | ||||
-rw-r--r-- | thread_pool.cc | 8 |
9 files changed, 29 insertions, 29 deletions
@@ -26,8 +26,8 @@ condition_variable::~condition_variable() { PERROR("pthread_cond_destroy"); } -void condition_variable::wait(const unique_lock<mutex>& mu) { - if (pthread_cond_wait(&cond_, &mu.mutex()->mu_) != 0) +void condition_variable::wait(const UniqueLock<Mutex>& mu) { + if (pthread_cond_wait(&cond_, &mu.Mutex()->mu_) != 0) PERROR("pthread_cond_wait"); } @@ -24,7 +24,7 @@ class condition_variable { condition_variable(); ~condition_variable(); - void wait(const unique_lock<mutex>& mu); + void wait(const UniqueLock<Mutex>& mu); void notify_one(); void notify_all(); @@ -16,22 +16,22 @@ #include "log.h" -mutex::mutex() { +Mutex::Mutex() { if (pthread_mutex_init(&mu_, NULL) != 0) PERROR("pthread_mutex_init"); } -mutex::~mutex() { +Mutex::~Mutex() { if (pthread_mutex_destroy(&mu_) != 0) PERROR("pthread_mutex_destroy"); } -void mutex::lock() { +void Mutex::lock() { if (pthread_mutex_lock(&mu_) != 0) PERROR("pthread_mutex_lock"); } -void mutex::unlock() { +void Mutex::unlock() { if (pthread_mutex_unlock(&mu_) != 0) PERROR("pthread_mutex_unlock"); } @@ -17,10 +17,10 @@ #include <pthread.h> -class mutex { +class Mutex { public: - explicit mutex(); - ~mutex(); + explicit Mutex(); + ~Mutex(); void lock(); void unlock(); @@ -31,17 +31,17 @@ class mutex { friend class condition_variable; }; -template<class T> class unique_lock { +template<class T> class UniqueLock { public: - explicit unique_lock(T& mu) + explicit UniqueLock(T& mu) : mu_(mu) { mu_.lock(); } - ~unique_lock() { + ~UniqueLock() { mu_.unlock(); } - T* mutex() const { return &mu_; } + T* Mutex() const { return &mu_; } private: T& mu_; @@ -595,7 +595,7 @@ class NinjaGenerator { if (use_local_pool) *o << " pool = local_pool\n"; if (node->is_default_target) { - unique_lock<mutex> lock(mu_); + UniqueLock<Mutex> lock(mu_); default_target_ = node; } } @@ -833,7 +833,7 @@ class NinjaGenerator { const double start_time_; vector<NinjaNode*> nodes_; - mutex mu_; + Mutex mu_; const DepNode* default_target_; }; @@ -364,7 +364,7 @@ class StampChecker { // TODO: Make glob cache thread safe and create a task for each glob. for (GlobResult* gr : globs_) { if (CheckGlobResult(gr, &err)) { - unique_lock<mutex> lock(mu_); + UniqueLock<Mutex> lock(mu_); if (!needs_regen_) { needs_regen_ = true; msg_ = err; @@ -378,7 +378,7 @@ class StampChecker { tp->Submit([this, sr]() { string err; if (CheckShellResult(sr, &err)) { - unique_lock<mutex> lock(mu_); + UniqueLock<Mutex> lock(mu_); if (!needs_regen_) { needs_regen_ = true; msg_ = err; @@ -398,7 +398,7 @@ class StampChecker { double gen_time_; vector<GlobResult*> globs_; vector<ShellResult*> commands_; - mutex mu_; + Mutex mu_; bool needs_regen_; string msg_; }; @@ -27,7 +27,7 @@ namespace { -mutex g_mu; +Mutex g_mu; vector<Stats*>* g_stats; DEFINE_THREAD_LOCAL(double, g_start_time); @@ -35,21 +35,21 @@ DEFINE_THREAD_LOCAL(double, g_start_time); Stats::Stats(const char* name) : name_(name), elapsed_(0), cnt_(0) { - unique_lock<mutex> lock(g_mu); + UniqueLock<Mutex> lock(g_mu); if (g_stats == NULL) g_stats = new vector<Stats*>; g_stats->push_back(this); } string Stats::String() const { - unique_lock<mutex> lock(mu_); + UniqueLock<Mutex> lock(mu_); return StringPrintf("%s: %f / %d", name_, elapsed_, cnt_); } void Stats::Start() { CHECK(!TLS_REF(g_start_time)); TLS_REF(g_start_time) = GetTime(); - unique_lock<mutex> lock(mu_); + UniqueLock<Mutex> lock(mu_); cnt_++; } @@ -57,7 +57,7 @@ double Stats::End() { CHECK(TLS_REF(g_start_time)); double e = GetTime() - TLS_REF(g_start_time); TLS_REF(g_start_time) = 0; - unique_lock<mutex> lock(mu_); + UniqueLock<Mutex> lock(mu_); elapsed_ += e; return e; } @@ -36,7 +36,7 @@ class Stats { const char* name_; double elapsed_; int cnt_; - mutable mutex mu_; + mutable Mutex mu_; }; class ScopedStatsRecorder { diff --git a/thread_pool.cc b/thread_pool.cc index 791b718..c504ef5 100644 --- a/thread_pool.cc +++ b/thread_pool.cc @@ -37,14 +37,14 @@ class ThreadPoolImpl : public ThreadPool { } virtual void Submit(function<void(void)> task) override { - unique_lock<mutex> lock(mu_); + UniqueLock<Mutex> lock(mu_); tasks_.push(task); cond_.notify_one(); } virtual void Wait() override { { - unique_lock<mutex> lock(mu_); + UniqueLock<Mutex> lock(mu_); is_waiting_ = true; cond_.notify_all(); } @@ -61,7 +61,7 @@ class ThreadPoolImpl : public ThreadPool { while (true) { function<void(void)> task; { - unique_lock<mutex> lock(mu_); + UniqueLock<Mutex> lock(mu_); if (tasks_.empty()) { if (is_waiting_) return; @@ -79,7 +79,7 @@ class ThreadPoolImpl : public ThreadPool { } vector<thread> threads_; - mutex mu_; + Mutex mu_; condition_variable cond_; stack<function<void(void)>> tasks_; bool is_waiting_; |