diff options
author | Conlain Kelly <conlain.k@gmail.com> | 2018-07-18 14:59:02 -0400 |
---|---|---|
committer | Conlain Kelly <conlain.k@gmail.com> | 2018-07-18 14:59:02 -0400 |
commit | baccac8a8b4ad7f9eca9130cf24b0ca35d6cfd4d (patch) | |
tree | e15db29fa108236baf80410a2b9dc34fe1953990 | |
parent | f77b9f7348fb823253912e07d04bca0bba936e05 (diff) | |
download | sdl_core-baccac8a8b4ad7f9eca9130cf24b0ca35d6cfd4d.tar.gz |
Cleanup, add more error checking
-rw-r--r-- | src/components/utils/src/lock_boost.cc | 49 |
1 files changed, 15 insertions, 34 deletions
diff --git a/src/components/utils/src/lock_boost.cc b/src/components/utils/src/lock_boost.cc index e3c4a8cb4f..a76bd02a78 100644 --- a/src/components/utils/src/lock_boost.cc +++ b/src/components/utils/src/lock_boost.cc @@ -32,7 +32,6 @@ #include <errno.h> #include <stdint.h> -#include <stdio.h> #include <string.h> #include <cstring> #include "utils/lock.h" @@ -45,39 +44,30 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "Utils") Lock::Lock() : lock_taken_(0) {} Lock::~Lock() { - // std::cerr << "destructing lock " << &mutex_ << " with lock count " - // << lock_taken_ << '\n'; if (lock_taken_ > 0) { LOG4CXX_FATAL(logger_, "Destroying non-released regular mutex " << &mutex_); } } void Lock::Acquire() { - // try { + try { mutex_.lock(); - // std::cerr << "acquiring lock " << &mutex_ << " with lock count " - // << lock_taken_ << '\n'; - // } catch (std::exception err) { - // LOG4CXX_FATAL(logger_, - // "Failed to acquire mutex " << &mutex_ << ": " << - // err.what()); - // NOTREACHED(); - // } + } catch (std::exception err) { + LOG4CXX_FATAL(logger_, + "Failed to acquire mutex " << &mutex_ << ": " << + err.what()); + NOTREACHED(); + } AssertFreeAndMarkTaken(); } void Lock::Release() { - // std::cerr << "releasing lock " << &mutex_ << " with lock count " - // << lock_taken_ << '\n'; AssertTakenAndMarkFree(); - mutex_.unlock(); } bool Lock::Try() { bool status = mutex_.try_lock(); - // std::cerr << "trying lock " << &mutex_ << " with lock count " << lock_taken_ - // << " status was " << status << '\n'; if (status) { AssertFreeAndMarkTaken(); } @@ -89,7 +79,6 @@ void Lock::AssertFreeAndMarkTaken() { LOG4CXX_FATAL(logger_, "Locking already taken not recursive mutex"); NOTREACHED(); } - lock_taken_++; } @@ -106,8 +95,6 @@ void Lock::AssertTakenAndMarkFree() { RecursiveLock::RecursiveLock() : lock_taken_(0) {} RecursiveLock::~RecursiveLock() { - // std::cerr << "destructing recursive lock " << &mutex_ << " with lock count " - // << lock_taken_ << '\n'; if (lock_taken_ > 0) { LOG4CXX_FATAL(logger_, "Destroying non-released recursive mutex " << &mutex_); @@ -115,31 +102,25 @@ RecursiveLock::~RecursiveLock() { } void RecursiveLock::Acquire() { - // try { + try { mutex_.lock(); - // std::cerr << "acquiring recursive lock " << &mutex_ << " with lock count " - // << lock_taken_ << '\n'; - // } catch (std::exception err) { - // LOG4CXX_FATAL(logger_, - // "Failed to acquire mutex " << &mutex_ << ": " << - // err.what()); - // NOTREACHED(); - // } - + } catch (std::exception err) { + LOG4CXX_FATAL(logger_, + "Failed to acquire mutex " << &mutex_ << ": " << + err.what()); + NOTREACHED(); + } AssertFreeAndMarkTaken(); } void RecursiveLock::Release() { - std::cerr << "releasing recursive lock " << &mutex_ << " with lock count " - << lock_taken_ << '\n'; + AssertTakenAndMarkFree(); mutex_.unlock(); } bool RecursiveLock::Try() { bool status = mutex_.try_lock(); - // std::cerr << "trying recursive lock " << &mutex_ << " with lock count " - // << lock_taken_ << " status was " << status << '\n'; if (status) { AssertFreeAndMarkTaken(); } |