aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--condvar.cc4
-rw-r--r--condvar.h2
-rw-r--r--mutex.cc8
-rw-r--r--mutex.h14
-rw-r--r--ninja.cc4
-rw-r--r--regen.cc6
-rw-r--r--stats.cc10
-rw-r--r--stats.h2
-rw-r--r--thread_pool.cc8
9 files changed, 29 insertions, 29 deletions
diff --git a/condvar.cc b/condvar.cc
index d7d4e39..f8b488b 100644
--- a/condvar.cc
+++ b/condvar.cc
@@ -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");
}
diff --git a/condvar.h b/condvar.h
index 2f9ab3a..b75b9a4 100644
--- a/condvar.h
+++ b/condvar.h
@@ -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();
diff --git a/mutex.cc b/mutex.cc
index ae4bd3b..986366b 100644
--- a/mutex.cc
+++ b/mutex.cc
@@ -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");
}
diff --git a/mutex.h b/mutex.h
index d6f1f5a..e730294 100644
--- a/mutex.h
+++ b/mutex.h
@@ -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_;
diff --git a/ninja.cc b/ninja.cc
index ccc51f2..c3b6a61 100644
--- a/ninja.cc
+++ b/ninja.cc
@@ -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_;
};
diff --git a/regen.cc b/regen.cc
index a40ebf3..a448612 100644
--- a/regen.cc
+++ b/regen.cc
@@ -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_;
};
diff --git a/stats.cc b/stats.cc
index 7afda4c..60b3285 100644
--- a/stats.cc
+++ b/stats.cc
@@ -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;
}
diff --git a/stats.h b/stats.h
index 6244b54..190fa57 100644
--- a/stats.h
+++ b/stats.h
@@ -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_;