diff options
author | Pixel <pixel@nobis-crew.org> | 2012-03-08 07:25:27 -0800 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2012-03-08 07:46:59 -0800 |
commit | 2380ebca01bdff36c2d12b0a23bef84e07920cb3 (patch) | |
tree | 47dbc4523a2d6c61fed221fe4c67410fd107b2c4 /src | |
parent | 85e533ca87fff1b7ab40bd87a3a44b6969eefd13 (diff) |
Adding the ScopeLock class to simplify a bit some pieces of code.
Diffstat (limited to 'src')
-rw-r--r-- | src/HttpServer.cc | 10 | ||||
-rw-r--r-- | src/Printer.cc | 3 | ||||
-rw-r--r-- | src/TaskMan.cc | 9 |
3 files changed, 7 insertions, 15 deletions
diff --git a/src/HttpServer.cc b/src/HttpServer.cc index c596005..fe421b9 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -607,21 +607,19 @@ void Balau::HttpServer::stop() { } void Balau::HttpServer::registerAction(Action * action) { - m_actionsLock.enterW(); + ScopeLockW slw(m_actionsLock); action->ref(); m_actions.push_front(action); - m_actionsLock.leave(); } void Balau::HttpServer::flushAllActions() { - m_actionsLock.enterW(); + ScopeLockW slw(m_actionsLock); Action * a; while (!m_actions.empty()) { a = m_actions.front(); m_actions.pop_front(); a->unref(); } - m_actionsLock.leave(); } Balau::HttpServer::Action::ActionMatch Balau::HttpServer::Action::matches(const char * uri, const char * host) { @@ -636,7 +634,7 @@ Balau::HttpServer::Action::ActionMatch Balau::HttpServer::Action::matches(const } Balau::HttpServer::ActionFound Balau::HttpServer::findAction(const char * uri, const char * host) { - m_actionsLock.enterR(); + ScopeLockR slr(m_actionsLock); ActionList::iterator i; ActionFound r; @@ -653,8 +651,6 @@ Balau::HttpServer::ActionFound Balau::HttpServer::findAction(const char * uri, c else r.action->ref(); - m_actionsLock.leave(); - return r; } diff --git a/src/Printer.cc b/src/Printer.cc index 026ee1a..ee6029c 100644 --- a/src/Printer.cc +++ b/src/Printer.cc @@ -40,7 +40,7 @@ void Balau::Printer::_log(uint32_t level, const char * fmt, va_list ap) { if (l & level) break; - m_lock.enter(); + ScopeLock sl(m_lock); if (m_detailledLogs) { struct ev_loop * loop = ev_default_loop(0); ev_now_update(loop); @@ -50,7 +50,6 @@ void Balau::Printer::_log(uint32_t level, const char * fmt, va_list ap) { _print(prefixes[i]); _print(fmt, ap); _print("\n"); - m_lock.leave(); } void Balau::Printer::_print(const char * fmt, va_list ap) { diff --git a/src/TaskMan.cc b/src/TaskMan.cc index 843423f..ea7a613 100644 --- a/src/TaskMan.cc +++ b/src/TaskMan.cc @@ -53,13 +53,12 @@ void Balau::TaskScheduler::registerTask(Task * t) { } void Balau::TaskScheduler::registerTaskMan(TaskMan * t) { - m_lock.enter(); + ScopeLock sl(m_lock); m_taskManagers.push(t); - m_lock.leave(); } void Balau::TaskScheduler::unregisterTaskMan(TaskMan * t) { - m_lock.enter(); + ScopeLock sl(m_lock); TaskMan * p = NULL; // yes, this is a potentially dangerous operation. // But unregistering task managers shouldn't happen that often. @@ -70,12 +69,11 @@ void Balau::TaskScheduler::unregisterTaskMan(TaskMan * t) { break; m_taskManagers.push(p); } - m_lock.leave(); } void Balau::TaskScheduler::stopAll(int code) { m_stopping = true; - m_lock.enter(); + ScopeLock sl(m_lock); std::queue<TaskMan *> altQueue; TaskMan * tm; while (!m_taskManagers.empty()) { @@ -90,7 +88,6 @@ void Balau::TaskScheduler::stopAll(int code) { altQueue.pop(); m_taskManagers.push(tm); } - m_lock.leave(); } void * Balau::TaskScheduler::proc() { |