Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Unified Diff: mojo/edk/system/mutex.cc

Issue 1418043003: Remove mojo::system::Mutex's use of base::internal::LockImpl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/edk/system/mutex.h ('k') | mojo/edk/system/mutex_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/mutex.cc
diff --git a/mojo/edk/system/mutex.cc b/mojo/edk/system/mutex.cc
index 216b35a0388446f0ae910ac0e068af8ae0720616..0f07adff81b3cfb3b797fcf2f86c8b57b24ed875 100644
--- a/mojo/edk/system/mutex.cc
+++ b/mojo/edk/system/mutex.cc
@@ -5,34 +5,54 @@
#include "mojo/edk/system/mutex.h"
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
+#include <errno.h>
+#include <string.h>
#include "base/logging.h"
namespace mojo {
namespace system {
-Mutex::Mutex() : lock_() {
+Mutex::Mutex() {
+ pthread_mutexattr_t attr;
+ int error = pthread_mutexattr_init(&attr);
+ DCHECK(!error) << "pthread_mutexattr_init: " << strerror(error);
+ error = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
+ DCHECK(!error) << "pthread_mutexattr_settype: " << strerror(error);
+ error = pthread_mutex_init(&impl_, &attr);
+ DCHECK(!error) << "pthread_mutex_init: " << strerror(error);
+ error = pthread_mutexattr_destroy(&attr);
+ DCHECK(!error) << "pthread_mutexattr_destroy: " << strerror(error);
}
Mutex::~Mutex() {
- DCHECK(owning_thread_ref_.is_null());
+ int error = pthread_mutex_destroy(&impl_);
+ DCHECK(!error) << "pthread_mutex_destroy: " << strerror(error);
}
-void Mutex::AssertHeld() const {
- DCHECK(owning_thread_ref_ == base::PlatformThread::CurrentRef());
+void Mutex::Lock() MOJO_EXCLUSIVE_LOCK_FUNCTION() {
+ int error = pthread_mutex_lock(&impl_);
+ DCHECK(!error) << "pthread_mutex_lock: " << strerror(error);
}
-void Mutex::CheckHeldAndUnmark() {
- DCHECK(owning_thread_ref_ == base::PlatformThread::CurrentRef());
- owning_thread_ref_ = base::PlatformThreadRef();
+void Mutex::Unlock() MOJO_UNLOCK_FUNCTION() {
+ int error = pthread_mutex_unlock(&impl_);
+ DCHECK(!error) << "pthread_mutex_unlock: " << strerror(error);
}
-void Mutex::CheckUnheldAndMark() {
- DCHECK(owning_thread_ref_.is_null());
- owning_thread_ref_ = base::PlatformThread::CurrentRef();
+bool Mutex::TryLock() MOJO_EXCLUSIVE_TRYLOCK_FUNCTION(true) {
+ int error = pthread_mutex_trylock(&impl_);
+ DCHECK(!error || error == EBUSY) << "pthread_mutex_trylock: "
+ << strerror(error);
+ return !error;
+}
+
+void Mutex::AssertHeld() MOJO_ASSERT_EXCLUSIVE_LOCK() {
+ int error = pthread_mutex_lock(&impl_);
+ DCHECK_EQ(error, EDEADLK) << ". pthread_mutex_lock: " << strerror(error);
}
} // namespace system
} // namespace mojo
-#endif // !NDEBUG || DCHECK_ALWAYS_ON
+#endif // !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
« no previous file with comments | « mojo/edk/system/mutex.h ('k') | mojo/edk/system/mutex_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698