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

Side by Side Diff: runtime/platform/thread.h

Issue 463993002: - Separate the thread implementation used in bin/ and vm/ (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 #ifndef PLATFORM_THREAD_H_
6 #define PLATFORM_THREAD_H_
7
8 #include "platform/globals.h"
9
10 // Declare the OS-specific types ahead of defining the generic classes.
11 #if defined(TARGET_OS_ANDROID)
12 #include "platform/thread_android.h"
13 #elif defined(TARGET_OS_LINUX)
14 #include "platform/thread_linux.h"
15 #elif defined(TARGET_OS_MACOS)
16 #include "platform/thread_macos.h"
17 #elif defined(TARGET_OS_WINDOWS)
18 #include "platform/thread_win.h"
19 #else
20 #error Unknown target os.
21 #endif
22
23 namespace dart {
24
25 class Thread {
26 public:
27 static ThreadLocalKey kUnsetThreadLocalKey;
28 static ThreadId kInvalidThreadId;
29
30 typedef void (*ThreadStartFunction) (uword parameter);
31
32 // Start a thread running the specified function. Returns 0 if the
33 // thread started successfuly and a system specific error code if
34 // the thread failed to start.
35 static int Start(ThreadStartFunction function, uword parameters);
36
37 static ThreadLocalKey CreateThreadLocal();
38 static void DeleteThreadLocal(ThreadLocalKey key);
39 static uword GetThreadLocal(ThreadLocalKey key) {
40 return ThreadInlineImpl::GetThreadLocal(key);
41 }
42 static void SetThreadLocal(ThreadLocalKey key, uword value);
43 static intptr_t GetMaxStackSize();
44 static ThreadId GetCurrentThreadId();
45 static bool Join(ThreadId id);
46 static intptr_t ThreadIdToIntPtr(ThreadId id);
47 static bool Compare(ThreadId a, ThreadId b);
48 static void GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage);
49 };
50
51
52 class Mutex {
53 public:
54 Mutex();
55 ~Mutex();
56
57 void Lock();
58 bool TryLock();
59 void Unlock();
60
61 private:
62 MutexData data_;
63
64 DISALLOW_COPY_AND_ASSIGN(Mutex);
65 };
66
67
68 class Monitor {
69 public:
70 enum WaitResult {
71 kNotified,
72 kTimedOut
73 };
74
75 static const int64_t kNoTimeout = 0;
76
77 Monitor();
78 ~Monitor();
79
80 void Enter();
81 void Exit();
82
83 // Wait for notification or timeout.
84 WaitResult Wait(int64_t millis);
85 WaitResult WaitMicros(int64_t micros);
86
87 // Notify waiting threads.
88 void Notify();
89 void NotifyAll();
90
91 private:
92 MonitorData data_; // OS-specific data.
93
94 DISALLOW_COPY_AND_ASSIGN(Monitor);
95 };
96
97
98 } // namespace dart
99
100
101 #endif // PLATFORM_THREAD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698