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

Side by Side Diff: runtime/vm/os_thread.h

Issue 1758503002: Make the lock/unlock and Enter/Exit methods in Mutex and Monitor private so taht we always use the … (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: self-code-review-comments Created 4 years, 9 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
« no previous file with comments | « runtime/vm/message_handler_test.cc ('k') | runtime/vm/service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 VM_OS_THREAD_H_ 5 #ifndef VM_OS_THREAD_H_
6 #define VM_OS_THREAD_H_ 6 #define VM_OS_THREAD_H_
7 7
8 #include "platform/globals.h" 8 #include "platform/globals.h"
9 #include "vm/allocation.h" 9 #include "vm/allocation.h"
10 #include "vm/globals.h" 10 #include "vm/globals.h"
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 private: 259 private:
260 OSThread* next_; 260 OSThread* next_;
261 }; 261 };
262 262
263 263
264 class Mutex { 264 class Mutex {
265 public: 265 public:
266 Mutex(); 266 Mutex();
267 ~Mutex(); 267 ~Mutex();
268 268
269 void Lock();
270 bool TryLock(); // Returns false if lock is busy and locking failed.
271 void Unlock();
272
273 #if defined(DEBUG) 269 #if defined(DEBUG)
274 bool IsOwnedByCurrentThread() const { 270 bool IsOwnedByCurrentThread() const {
275 return owner_ == OSThread::GetCurrentThreadId(); 271 return owner_ == OSThread::GetCurrentThreadId();
276 } 272 }
277 #else 273 #else
278 bool IsOwnedByCurrentThread() const { 274 bool IsOwnedByCurrentThread() const {
279 UNREACHABLE(); 275 UNREACHABLE();
280 return false; 276 return false;
281 } 277 }
282 #endif 278 #endif
283 279
284 private: 280 private:
281 void Lock();
282 bool TryLock(); // Returns false if lock is busy and locking failed.
283 void Unlock();
284
285 MutexData data_; 285 MutexData data_;
286 #if defined(DEBUG) 286 #if defined(DEBUG)
287 ThreadId owner_; 287 ThreadId owner_;
288 #endif // defined(DEBUG) 288 #endif // defined(DEBUG)
289 289
290 friend class MutexLocker;
291 friend class SafepointMutexLocker;
292 friend class OSThreadIterator;
293 friend class TimelineEventBlockIterator;
294 friend class TimelineEventRecorder;
295 friend class PageSpace;
296 friend void Dart_TestMutex();
290 DISALLOW_COPY_AND_ASSIGN(Mutex); 297 DISALLOW_COPY_AND_ASSIGN(Mutex);
291 }; 298 };
292 299
293 300
294 class Monitor { 301 class Monitor {
295 public: 302 public:
296 enum WaitResult { 303 enum WaitResult {
297 kNotified, 304 kNotified,
298 kTimedOut 305 kTimedOut
299 }; 306 };
300 307
301 static const int64_t kNoTimeout = 0; 308 static const int64_t kNoTimeout = 0;
302 309
303 Monitor(); 310 Monitor();
304 ~Monitor(); 311 ~Monitor();
305 312
306 bool TryEnter(); // Returns false if lock is busy and locking failed.
307 void Enter();
308 void Exit();
309
310 // Wait for notification or timeout.
311 WaitResult Wait(int64_t millis);
312 WaitResult WaitMicros(int64_t micros);
313
314 // Notify waiting threads.
315 void Notify();
316 void NotifyAll();
317
318 #if defined(DEBUG) 313 #if defined(DEBUG)
319 bool IsOwnedByCurrentThread() const { 314 bool IsOwnedByCurrentThread() const {
320 return owner_ == OSThread::GetCurrentThreadId(); 315 return owner_ == OSThread::GetCurrentThreadId();
321 } 316 }
322 #else 317 #else
323 bool IsOwnedByCurrentThread() const { 318 bool IsOwnedByCurrentThread() const {
324 UNREACHABLE(); 319 UNREACHABLE();
325 return false; 320 return false;
326 } 321 }
327 #endif 322 #endif
328 323
329 private: 324 private:
325 bool TryEnter(); // Returns false if lock is busy and locking failed.
326 void Enter();
327 void Exit();
328
329 // Wait for notification or timeout.
330 WaitResult Wait(int64_t millis);
331 WaitResult WaitMicros(int64_t micros);
332
333 // Notify waiting threads.
334 void Notify();
335 void NotifyAll();
336
330 MonitorData data_; // OS-specific data. 337 MonitorData data_; // OS-specific data.
331 #if defined(DEBUG) 338 #if defined(DEBUG)
332 ThreadId owner_; 339 ThreadId owner_;
333 #endif // defined(DEBUG) 340 #endif // defined(DEBUG)
334 341
342 friend class MonitorLocker;
343 friend class SafepointMonitorLocker;
344 friend void Dart_TestMonitor();
335 DISALLOW_COPY_AND_ASSIGN(Monitor); 345 DISALLOW_COPY_AND_ASSIGN(Monitor);
336 }; 346 };
337 347
338 348
339 } // namespace dart 349 } // namespace dart
340 350
341 351
342 #endif // VM_OS_THREAD_H_ 352 #endif // VM_OS_THREAD_H_
OLDNEW
« no previous file with comments | « runtime/vm/message_handler_test.cc ('k') | runtime/vm/service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698