| 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 #ifndef RUNTIME_VM_LOCKERS_H_ | 5 #ifndef RUNTIME_VM_LOCKERS_H_ |
| 6 #define RUNTIME_VM_LOCKERS_H_ | 6 #define RUNTIME_VM_LOCKERS_H_ |
| 7 | 7 |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
| 10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 Thread::Current()->DecrementNoSafepointScopeDepth(); | 163 Thread::Current()->DecrementNoSafepointScopeDepth(); |
| 164 } | 164 } |
| 165 #endif | 165 #endif |
| 166 } | 166 } |
| 167 | 167 |
| 168 Monitor::WaitResult Wait(int64_t millis = Monitor::kNoTimeout) { | 168 Monitor::WaitResult Wait(int64_t millis = Monitor::kNoTimeout) { |
| 169 return monitor_->Wait(millis); | 169 return monitor_->Wait(millis); |
| 170 } | 170 } |
| 171 | 171 |
| 172 Monitor::WaitResult WaitWithSafepointCheck( | 172 Monitor::WaitResult WaitWithSafepointCheck( |
| 173 Thread* thread, int64_t millis = Monitor::kNoTimeout); | 173 Thread* thread, |
| 174 int64_t millis = Monitor::kNoTimeout); |
| 174 | 175 |
| 175 Monitor::WaitResult WaitMicros(int64_t micros = Monitor::kNoTimeout) { | 176 Monitor::WaitResult WaitMicros(int64_t micros = Monitor::kNoTimeout) { |
| 176 return monitor_->WaitMicros(micros); | 177 return monitor_->WaitMicros(micros); |
| 177 } | 178 } |
| 178 | 179 |
| 179 void Notify() { | 180 void Notify() { monitor_->Notify(); } |
| 180 monitor_->Notify(); | |
| 181 } | |
| 182 | 181 |
| 183 void NotifyAll() { | 182 void NotifyAll() { monitor_->NotifyAll(); } |
| 184 monitor_->NotifyAll(); | |
| 185 } | |
| 186 | 183 |
| 187 private: | 184 private: |
| 188 Monitor* const monitor_; | 185 Monitor* const monitor_; |
| 189 bool no_safepoint_scope_; | 186 bool no_safepoint_scope_; |
| 190 | 187 |
| 191 DISALLOW_COPY_AND_ASSIGN(MonitorLocker); | 188 DISALLOW_COPY_AND_ASSIGN(MonitorLocker); |
| 192 }; | 189 }; |
| 193 | 190 |
| 194 /* | 191 /* |
| 195 * Safepoint mutex locker : | 192 * Safepoint mutex locker : |
| 196 * This locker abstraction should be used when the enclosing code could | 193 * This locker abstraction should be used when the enclosing code could |
| 197 * potentially trigger a safepoint. | 194 * potentially trigger a safepoint. |
| 198 * This locker ensures that other threads that try to acquire the same lock | 195 * This locker ensures that other threads that try to acquire the same lock |
| 199 * will be marked as being at a safepoint if they get blocked trying to | 196 * will be marked as being at a safepoint if they get blocked trying to |
| 200 * acquire the lock. | 197 * acquire the lock. |
| 201 * NOTE: please do not use the passed in mutex object independent of the locker | 198 * NOTE: please do not use the passed in mutex object independent of the locker |
| 202 * class, For example the code below will not work correctly: | 199 * class, For example the code below will not work correctly: |
| 203 * { | 200 * { |
| 204 * SafepointMutexLocker ml(m); | 201 * SafepointMutexLocker ml(m); |
| 205 * .... | 202 * .... |
| 206 * m->Exit(); | 203 * m->Exit(); |
| 207 * .... | 204 * .... |
| 208 * m->Enter(); | 205 * m->Enter(); |
| 209 * ... | 206 * ... |
| 210 * } | 207 * } |
| 211 */ | 208 */ |
| 212 class SafepointMutexLocker : public ValueObject { | 209 class SafepointMutexLocker : public ValueObject { |
| 213 public: | 210 public: |
| 214 explicit SafepointMutexLocker(Mutex* mutex); | 211 explicit SafepointMutexLocker(Mutex* mutex); |
| 215 virtual ~SafepointMutexLocker() { | 212 virtual ~SafepointMutexLocker() { mutex_->Unlock(); } |
| 216 mutex_->Unlock(); | |
| 217 } | |
| 218 | 213 |
| 219 private: | 214 private: |
| 220 Mutex* const mutex_; | 215 Mutex* const mutex_; |
| 221 | 216 |
| 222 DISALLOW_COPY_AND_ASSIGN(SafepointMutexLocker); | 217 DISALLOW_COPY_AND_ASSIGN(SafepointMutexLocker); |
| 223 }; | 218 }; |
| 224 | 219 |
| 225 /* | 220 /* |
| 226 * Safepoint monitor locker : | 221 * Safepoint monitor locker : |
| 227 * This locker abstraction should be used when the enclosing code could | 222 * This locker abstraction should be used when the enclosing code could |
| 228 * potentially trigger a safepoint. | 223 * potentially trigger a safepoint. |
| 229 * This locker ensures that other threads that try to acquire the same lock | 224 * This locker ensures that other threads that try to acquire the same lock |
| 230 * will be marked as being at a safepoint if they get blocked trying to | 225 * will be marked as being at a safepoint if they get blocked trying to |
| 231 * acquire the lock. | 226 * acquire the lock. |
| 232 * NOTE: please do not use the passed in monitor object independent of the | 227 * NOTE: please do not use the passed in monitor object independent of the |
| 233 * locker class, For example the code below will not work correctly: | 228 * locker class, For example the code below will not work correctly: |
| 234 * { | 229 * { |
| 235 * SafepointMonitorLocker ml(m); | 230 * SafepointMonitorLocker ml(m); |
| 236 * .... | 231 * .... |
| 237 * m->Exit(); | 232 * m->Exit(); |
| 238 * .... | 233 * .... |
| 239 * m->Enter(); | 234 * m->Enter(); |
| 240 * ... | 235 * ... |
| 241 * } | 236 * } |
| 242 */ | 237 */ |
| 243 class SafepointMonitorLocker : public ValueObject { | 238 class SafepointMonitorLocker : public ValueObject { |
| 244 public: | 239 public: |
| 245 explicit SafepointMonitorLocker(Monitor* monitor); | 240 explicit SafepointMonitorLocker(Monitor* monitor); |
| 246 virtual ~SafepointMonitorLocker() { | 241 virtual ~SafepointMonitorLocker() { monitor_->Exit(); } |
| 247 monitor_->Exit(); | |
| 248 } | |
| 249 | 242 |
| 250 Monitor::WaitResult Wait(int64_t millis = Monitor::kNoTimeout); | 243 Monitor::WaitResult Wait(int64_t millis = Monitor::kNoTimeout); |
| 251 | 244 |
| 252 private: | 245 private: |
| 253 Monitor* const monitor_; | 246 Monitor* const monitor_; |
| 254 | 247 |
| 255 DISALLOW_COPY_AND_ASSIGN(SafepointMonitorLocker); | 248 DISALLOW_COPY_AND_ASSIGN(SafepointMonitorLocker); |
| 256 }; | 249 }; |
| 257 | 250 |
| 258 } // namespace dart | 251 } // namespace dart |
| 259 | 252 |
| 260 | 253 |
| 261 #endif // RUNTIME_VM_LOCKERS_H_ | 254 #endif // RUNTIME_VM_LOCKERS_H_ |
| OLD | NEW |