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 RUNTIME_VM_OS_THREAD_LINUX_H_ |
6 | #define RUNTIME_VM_OS_THREAD_LINUX_H_ |
7 | |
8 | #if !defined(RUNTIME_VM_OS_THREAD_H_) |
9 | #error Do not include os_thread_linux.h directly; use os_thread.h instead. |
10 | #endif |
11 | |
12 | #include <pthread.h> |
13 | |
14 | #include "platform/assert.h" |
15 | #include "platform/globals.h" |
16 | |
17 | namespace dart { |
18 | |
19 | typedef pthread_key_t ThreadLocalKey; |
20 | typedef pthread_t ThreadId; |
21 | typedef pthread_t ThreadJoinId; |
22 | |
23 | static const ThreadLocalKey kUnsetThreadLocalKey = |
24 | static_cast<pthread_key_t>(-1); |
25 | |
26 | class ThreadInlineImpl { |
27 | private: |
28 | ThreadInlineImpl() {} |
29 | ~ThreadInlineImpl() {} |
30 | |
31 | static uword GetThreadLocal(ThreadLocalKey key) { |
32 | ASSERT(key != kUnsetThreadLocalKey); |
33 | return reinterpret_cast<uword>(pthread_getspecific(key)); |
34 | } |
35 | |
36 | friend class OSThread; |
37 | |
38 | DISALLOW_ALLOCATION(); |
39 | DISALLOW_COPY_AND_ASSIGN(ThreadInlineImpl); |
40 | }; |
41 | |
42 | class MutexData { |
43 | private: |
44 | MutexData() {} |
45 | ~MutexData() {} |
46 | |
47 | pthread_mutex_t* mutex() { return &mutex_; } |
48 | |
49 | pthread_mutex_t mutex_; |
50 | |
51 | friend class Mutex; |
52 | |
53 | DISALLOW_ALLOCATION(); |
54 | DISALLOW_COPY_AND_ASSIGN(MutexData); |
55 | }; |
56 | |
57 | class MonitorData { |
58 | private: |
59 | MonitorData() {} |
60 | ~MonitorData() {} |
61 | |
62 | pthread_mutex_t* mutex() { return &mutex_; } |
63 | pthread_cond_t* cond() { return &cond_; } |
64 | |
65 | pthread_mutex_t mutex_; |
66 | pthread_cond_t cond_; |
67 | |
68 | friend class Monitor; |
69 | |
70 | DISALLOW_ALLOCATION(); |
71 | DISALLOW_COPY_AND_ASSIGN(MonitorData); |
72 | }; |
73 | |
74 | } // namespace dart |
75 | |
76 | #endif // RUNTIME_VM_OS_THREAD_LINUX_H_ |
77 |