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

Unified Diff: runtime/platform/thread.h

Issue 9196002: Move Mutex and Monitor from vm/ to platform/ (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed revire comments from ager@ 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
« no previous file with comments | « runtime/platform/platform_sources.gypi ('k') | runtime/platform/thread_linux.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/platform/thread.h
diff --git a/runtime/platform/thread.h b/runtime/platform/thread.h
new file mode 100644
index 0000000000000000000000000000000000000000..0eb8da13b2b502412cc21ac54951290785a4a64e
--- /dev/null
+++ b/runtime/platform/thread.h
@@ -0,0 +1,86 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#ifndef PLATFORM_THREAD_H_
+#define PLATFORM_THREAD_H_
+
+#include "platform/globals.h"
+
+// Declare the OS-specific types ahead of defining the generic classes.
+#if defined(TARGET_OS_LINUX)
+#include "platform/thread_linux.h"
+#elif defined(TARGET_OS_MACOS)
+#include "platform/thread_macos.h"
+#elif defined(TARGET_OS_WINDOWS)
+#include "platform/thread_win.h"
+#else
+#error Unknown target os.
+#endif
+
+namespace dart {
+
+class Thread {
+ public:
+ // Function to be called on thread start.
+ typedef void (*ThreadStartFunction) (uword parameter);
+
+ // TODO(iposva): Define the proper interface for spawning and killing threads.
+ Thread(ThreadStartFunction function, uword parameters);
+ ~Thread();
+
+ private:
+ ThreadData data_;
+
+ DISALLOW_COPY_AND_ASSIGN(Thread);
+};
+
+
+class Mutex {
+ public:
+ Mutex();
+ ~Mutex();
+
+ void Lock();
+ bool TryLock();
+ void Unlock();
+
+ private:
+ MutexData data_;
+
+ DISALLOW_COPY_AND_ASSIGN(Mutex);
+};
+
+
+class Monitor {
+ public:
+ enum WaitResult {
+ kNotified,
+ kTimedOut
+ };
+
+ static const int64_t kNoTimeout = 0;
+
+ Monitor();
+ ~Monitor();
+
+ void Enter();
+ void Exit();
+
+ // Wait for notification or timeout.
+ WaitResult Wait(int64_t millis);
+
+ // Notify waiting threads.
+ void Notify();
+ void NotifyAll();
+
+ private:
+ MonitorData data_; // OS-specific data.
+
+ DISALLOW_COPY_AND_ASSIGN(Monitor);
+};
+
+} // namespace dart
+
+
+#endif // PLATFORM_THREAD_H_
« no previous file with comments | « runtime/platform/platform_sources.gypi ('k') | runtime/platform/thread_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698