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