OLD | NEW |
---|---|
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
380 // LOCAL_STORAGE_KEY_MIN_VALUE and LOCAL_STORAGE_KEY_MAX_VALUE are specified | 380 // LOCAL_STORAGE_KEY_MIN_VALUE and LOCAL_STORAGE_KEY_MAX_VALUE are specified |
381 // to ensure that enumeration type has correct value range (see Issue 830 for | 381 // to ensure that enumeration type has correct value range (see Issue 830 for |
382 // more details). | 382 // more details). |
383 enum LocalStorageKey { | 383 enum LocalStorageKey { |
384 LOCAL_STORAGE_KEY_MIN_VALUE = kMinInt, | 384 LOCAL_STORAGE_KEY_MIN_VALUE = kMinInt, |
385 LOCAL_STORAGE_KEY_MAX_VALUE = kMaxInt | 385 LOCAL_STORAGE_KEY_MAX_VALUE = kMaxInt |
386 }; | 386 }; |
387 | 387 |
388 // Create new thread. | 388 // Create new thread. |
389 Thread(); | 389 Thread(); |
390 #ifdef DEBUG_THREAD_NAMES | |
391 explicit Thread(const char* name); | |
392 #endif | |
390 virtual ~Thread(); | 393 virtual ~Thread(); |
391 | 394 |
392 // Start new thread by calling the Run() method in the new thread. | 395 // Start new thread by calling the Run() method in the new thread. |
393 void Start(); | 396 void Start(); |
394 | 397 |
395 // Wait until thread terminates. | 398 // Wait until thread terminates. |
396 void Join(); | 399 void Join(); |
397 | 400 |
401 #ifdef DEBUG_THREAD_NAMES | |
402 inline const char* Name() const { | |
Søren Thygesen Gjesse
2011/01/03 07:48:34
Please use all lower-case for this type of accesso
marklam
2011/01/04 01:47:09
Done.
| |
403 return name_; | |
404 } | |
405 #endif | |
406 | |
398 // Abstract method for run handler. | 407 // Abstract method for run handler. |
399 virtual void Run() = 0; | 408 virtual void Run() = 0; |
400 | 409 |
401 // Thread-local storage. | 410 // Thread-local storage. |
402 static LocalStorageKey CreateThreadLocalKey(); | 411 static LocalStorageKey CreateThreadLocalKey(); |
403 static void DeleteThreadLocalKey(LocalStorageKey key); | 412 static void DeleteThreadLocalKey(LocalStorageKey key); |
404 static void* GetThreadLocal(LocalStorageKey key); | 413 static void* GetThreadLocal(LocalStorageKey key); |
405 static int GetThreadLocalInt(LocalStorageKey key) { | 414 static int GetThreadLocalInt(LocalStorageKey key) { |
406 return static_cast<int>(reinterpret_cast<intptr_t>(GetThreadLocal(key))); | 415 return static_cast<int>(reinterpret_cast<intptr_t>(GetThreadLocal(key))); |
407 } | 416 } |
408 static void SetThreadLocal(LocalStorageKey key, void* value); | 417 static void SetThreadLocal(LocalStorageKey key, void* value); |
409 static void SetThreadLocalInt(LocalStorageKey key, int value) { | 418 static void SetThreadLocalInt(LocalStorageKey key, int value) { |
410 SetThreadLocal(key, reinterpret_cast<void*>(static_cast<intptr_t>(value))); | 419 SetThreadLocal(key, reinterpret_cast<void*>(static_cast<intptr_t>(value))); |
411 } | 420 } |
412 static bool HasThreadLocal(LocalStorageKey key) { | 421 static bool HasThreadLocal(LocalStorageKey key) { |
413 return GetThreadLocal(key) != NULL; | 422 return GetThreadLocal(key) != NULL; |
414 } | 423 } |
415 | 424 |
416 // A hint to the scheduler to let another thread run. | 425 // A hint to the scheduler to let another thread run. |
417 static void YieldCPU(); | 426 static void YieldCPU(); |
418 | 427 |
419 private: | 428 private: |
429 #ifdef DEBUG_THREAD_NAMES | |
430 void SetName(const char *name); | |
Søren Thygesen Gjesse
2011/01/03 07:48:34
This setter should be called set_name, see http://
marklam
2011/01/04 01:47:09
Done.
| |
431 #endif | |
432 | |
420 class PlatformData; | 433 class PlatformData; |
421 PlatformData* data_; | 434 PlatformData* data_; |
435 #ifdef DEBUG_THREAD_NAMES | |
436 char name_[16]; | |
Søren Thygesen Gjesse
2011/01/03 07:48:34
I think that this constant deserves a comment. E.g
marklam
2011/01/04 01:47:09
Done.
| |
437 #endif | |
438 | |
422 DISALLOW_COPY_AND_ASSIGN(Thread); | 439 DISALLOW_COPY_AND_ASSIGN(Thread); |
423 }; | 440 }; |
424 | 441 |
425 | 442 |
426 // ---------------------------------------------------------------------------- | 443 // ---------------------------------------------------------------------------- |
427 // Mutex | 444 // Mutex |
428 // | 445 // |
429 // Mutexes are used for serializing access to non-reentrant sections of code. | 446 // Mutexes are used for serializing access to non-reentrant sections of code. |
430 // The implementations of mutex should allow for nested/recursive locking. | 447 // The implementations of mutex should allow for nested/recursive locking. |
431 | 448 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
611 PlatformData* data_; // Platform specific data. | 628 PlatformData* data_; // Platform specific data. |
612 int samples_taken_; // Counts stack samples taken. | 629 int samples_taken_; // Counts stack samples taken. |
613 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); | 630 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); |
614 }; | 631 }; |
615 | 632 |
616 #endif // ENABLE_LOGGING_AND_PROFILING | 633 #endif // ENABLE_LOGGING_AND_PROFILING |
617 | 634 |
618 } } // namespace v8::internal | 635 } } // namespace v8::internal |
619 | 636 |
620 #endif // V8_PLATFORM_H_ | 637 #endif // V8_PLATFORM_H_ |
OLD | NEW |