OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/thread.h" | 5 #include "platform/thread.h" |
6 | 6 |
7 #include <process.h> | 7 #include <process.h> |
8 | 8 |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 | 10 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 #ifdef DEBUG | 55 #ifdef DEBUG |
56 fprintf(stderr, "_beginthreadex error: %d (%s)\n", errno, strerror(errno)); | 56 fprintf(stderr, "_beginthreadex error: %d (%s)\n", errno, strerror(errno)); |
57 #endif | 57 #endif |
58 return errno; | 58 return errno; |
59 } | 59 } |
60 | 60 |
61 return 0; | 61 return 0; |
62 } | 62 } |
63 | 63 |
64 | 64 |
| 65 ThreadLocalKey Thread::kInvalidThreadLocal = TLS_OUT_OF_INDEXES; |
| 66 |
| 67 |
| 68 ThreadLocalKey Thread::CreateThreadLocal() { |
| 69 ThreadLocalKey key = TlsAlloc(); |
| 70 if (key == kInvalidThreadLocal) { |
| 71 FATAL("TlsAlloc failed"); |
| 72 } |
| 73 return key; |
| 74 } |
| 75 |
| 76 |
| 77 void Thread::DeleteThreadLocal(ThreadLocalKey key) { |
| 78 ASSERT(key != kInvalidThreadLocal); |
| 79 BOOL result = TlsFree(key); |
| 80 if (!result) { |
| 81 FATAL("TlsFree failed"); |
| 82 } |
| 83 } |
| 84 |
| 85 |
| 86 uword Thread::GetThreadLocal(ThreadLocalKey key) { |
| 87 ASSERT(key != kInvalidThreadLocal); |
| 88 return reinterpret_cast<uword>(TlsGetValue(key)); |
| 89 } |
| 90 |
| 91 |
| 92 void Thread::SetThreadLocal(ThreadLocalKey key, uword value) { |
| 93 ASSERT(key != kInvalidThreadLocal); |
| 94 BOOL result = TlsSetValue(key, reinterpret_cast<void*>(value)); |
| 95 if (!result) { |
| 96 FATAL("TlsSetValue failed"); |
| 97 } |
| 98 } |
| 99 |
| 100 |
65 Mutex::Mutex() { | 101 Mutex::Mutex() { |
66 // Allocate unnamed semaphore with initial count 1 and max count 1. | 102 // Allocate unnamed semaphore with initial count 1 and max count 1. |
67 data_.semaphore_ = CreateSemaphore(NULL, 1, 1, NULL); | 103 data_.semaphore_ = CreateSemaphore(NULL, 1, 1, NULL); |
68 if (data_.semaphore_ == NULL) { | 104 if (data_.semaphore_ == NULL) { |
69 FATAL("Mutex allocation failed"); | 105 FATAL("Mutex allocation failed"); |
70 } | 106 } |
71 } | 107 } |
72 | 108 |
73 | 109 |
74 Mutex::~Mutex() { | 110 Mutex::~Mutex() { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 void Monitor::Notify() { | 193 void Monitor::Notify() { |
158 WakeConditionVariable(&data_.cond_); | 194 WakeConditionVariable(&data_.cond_); |
159 } | 195 } |
160 | 196 |
161 | 197 |
162 void Monitor::NotifyAll() { | 198 void Monitor::NotifyAll() { |
163 WakeAllConditionVariable(&data_.cond_); | 199 WakeAllConditionVariable(&data_.cond_); |
164 } | 200 } |
165 | 201 |
166 } // namespace dart | 202 } // namespace dart |
OLD | NEW |