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

Unified Diff: runtime/vm/thread_linux.cc

Issue 9196002: Move Mutex and Monitor from vm/ to platform/ (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 11 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
Index: runtime/vm/thread_linux.cc
diff --git a/runtime/vm/thread_linux.cc b/runtime/vm/thread_linux.cc
index a46ec80139b7bb4d1b46b3427196ca6df71acf45..0efeaf0d2065c8bc1889a1c5d8fe95e994060b3d 100644
--- a/runtime/vm/thread_linux.cc
+++ b/runtime/vm/thread_linux.cc
@@ -16,21 +16,6 @@ namespace dart {
}
-static void ComputeTimeSpec(struct timespec* ts, int64_t millis) {
- int64_t secs = millis / kMillisecondsPerSecond;
- int64_t nanos =
- (millis - (secs * kMillisecondsPerSecond)) * kNanosecondsPerMillisecond;
- int result = clock_gettime(CLOCK_MONOTONIC, ts);
- ASSERT(result == 0);
- ts->tv_sec += secs;
- ts->tv_nsec += nanos;
- if (ts->tv_nsec >= kNanosecondsPerSecond) {
- ts->tv_sec += 1;
- ts->tv_nsec -= kNanosecondsPerSecond;
- }
-}
-
-
class ThreadStartData {
public:
ThreadStartData(Thread::ThreadStartFunction function,
@@ -102,148 +87,4 @@ Thread::Thread(ThreadStartFunction function, uword parameter) {
Thread::~Thread() {
}
-
-Mutex::Mutex() {
- pthread_mutexattr_t attr;
- int result = pthread_mutexattr_init(&attr);
- VALIDATE_PTHREAD_RESULT(result);
-
-#if defined(DEBUG)
- result = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
- VALIDATE_PTHREAD_RESULT(result);
-#endif // defined(DEBUG)
-
- result = pthread_mutex_init(data_.mutex(), &attr);
- // Verify that creating a pthread_mutex succeeded.
- VALIDATE_PTHREAD_RESULT(result);
-
- result = pthread_mutexattr_destroy(&attr);
- VALIDATE_PTHREAD_RESULT(result);
-}
-
-
-Mutex::~Mutex() {
- int result = pthread_mutex_destroy(data_.mutex());
- // Verify that the pthread_mutex was destroyed.
- VALIDATE_PTHREAD_RESULT(result);
-}
-
-
-void Mutex::Lock() {
- int result = pthread_mutex_lock(data_.mutex());
- // Specifically check for dead lock to help debugging.
- ASSERT(result != EDEADLK);
- ASSERT(result == 0); // Verify no other errors.
- // TODO(iposva): Do we need to track lock owners?
-}
-
-
-bool Mutex::TryLock() {
- int result = pthread_mutex_trylock(data_.mutex());
- // Return false if the lock is busy and locking failed.
- if (result == EBUSY) {
- return false;
- }
- ASSERT(result == 0); // Verify no other errors.
- // TODO(iposva): Do we need to track lock owners?
- return true;
-}
-
-
-void Mutex::Unlock() {
- // TODO(iposva): Do we need to track lock owners?
- int result = pthread_mutex_unlock(data_.mutex());
- // Specifically check for wrong thread unlocking to aid debugging.
- ASSERT(result != EPERM);
- ASSERT(result == 0); // Verify no other errors.
-}
-
-
-Monitor::Monitor() {
- pthread_mutexattr_t mutex_attr;
- int result = pthread_mutexattr_init(&mutex_attr);
- VALIDATE_PTHREAD_RESULT(result);
-
-#if defined(DEBUG)
- result = pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_ERRORCHECK);
- VALIDATE_PTHREAD_RESULT(result);
-#endif // defined(DEBUG)
-
- result = pthread_mutex_init(data_.mutex(), &mutex_attr);
- VALIDATE_PTHREAD_RESULT(result);
-
- result = pthread_mutexattr_destroy(&mutex_attr);
- VALIDATE_PTHREAD_RESULT(result);
-
- pthread_condattr_t cond_attr;
- result = pthread_condattr_init(&cond_attr);
- VALIDATE_PTHREAD_RESULT(result);
-
- result = pthread_condattr_setclock(&cond_attr, CLOCK_MONOTONIC);
- VALIDATE_PTHREAD_RESULT(result);
-
- result = pthread_cond_init(data_.cond(), &cond_attr);
- VALIDATE_PTHREAD_RESULT(result);
-
- result = pthread_condattr_destroy(&cond_attr);
- VALIDATE_PTHREAD_RESULT(result);
-}
-
-
-Monitor::~Monitor() {
- int result = pthread_mutex_destroy(data_.mutex());
- VALIDATE_PTHREAD_RESULT(result);
-
- result = pthread_cond_destroy(data_.cond());
- VALIDATE_PTHREAD_RESULT(result);
-}
-
-
-void Monitor::Enter() {
- int result = pthread_mutex_lock(data_.mutex());
- VALIDATE_PTHREAD_RESULT(result);
- // TODO(iposva): Do we need to track lock owners?
-}
-
-
-void Monitor::Exit() {
- // TODO(iposva): Do we need to track lock owners?
- int result = pthread_mutex_unlock(data_.mutex());
- VALIDATE_PTHREAD_RESULT(result);
-}
-
-
-Monitor::WaitResult Monitor::Wait(int64_t millis) {
- // TODO(iposva): Do we need to track lock owners?
- Monitor::WaitResult retval = kNotified;
- if (millis == 0) {
- // Wait forever.
- int result = pthread_cond_wait(data_.cond(), data_.mutex());
- VALIDATE_PTHREAD_RESULT(result);
- } else {
- struct timespec ts;
- ComputeTimeSpec(&ts, millis);
- int result = pthread_cond_timedwait(data_.cond(), data_.mutex(), &ts);
- ASSERT((result == 0) || (result == ETIMEDOUT));
- if (result == ETIMEDOUT) {
- retval = kTimedOut;
- }
- }
- return retval;
-}
-
-
-void Monitor::Notify() {
- // TODO(iposva): Do we need to track lock owners?
- int result = pthread_cond_signal(data_.cond());
- VALIDATE_PTHREAD_RESULT(result);
-}
-
-
-void Monitor::NotifyAll() {
- // TODO(iposva): Do we need to track lock owners?
- int result = pthread_cond_broadcast(data_.cond());
- VALIDATE_PTHREAD_RESULT(result);
-}
-
} // namespace dart

Powered by Google App Engine
This is Rietveld 408576698