| 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 (with a value for storing in the TLS isolate field). | 388 // Create new thread (with a value for storing in the TLS isolate field). |
| 389 explicit Thread(Isolate* isolate); | 389 explicit Thread(Isolate* isolate); |
| 390 Thread(Isolate* isolate, const char* name); |
| 390 virtual ~Thread(); | 391 virtual ~Thread(); |
| 391 | 392 |
| 392 // Start new thread by calling the Run() method in the new thread. | 393 // Start new thread by calling the Run() method in the new thread. |
| 393 void Start(); | 394 void Start(); |
| 394 | 395 |
| 395 // Wait until thread terminates. | 396 // Wait until thread terminates. |
| 396 void Join(); | 397 void Join(); |
| 397 | 398 |
| 399 inline const char* name() const { |
| 400 return name_; |
| 401 } |
| 402 |
| 398 // Abstract method for run handler. | 403 // Abstract method for run handler. |
| 399 virtual void Run() = 0; | 404 virtual void Run() = 0; |
| 400 | 405 |
| 401 // Thread-local storage. | 406 // Thread-local storage. |
| 402 static LocalStorageKey CreateThreadLocalKey(); | 407 static LocalStorageKey CreateThreadLocalKey(); |
| 403 static void DeleteThreadLocalKey(LocalStorageKey key); | 408 static void DeleteThreadLocalKey(LocalStorageKey key); |
| 404 static void* GetThreadLocal(LocalStorageKey key); | 409 static void* GetThreadLocal(LocalStorageKey key); |
| 405 static int GetThreadLocalInt(LocalStorageKey key) { | 410 static int GetThreadLocalInt(LocalStorageKey key) { |
| 406 return static_cast<int>(reinterpret_cast<intptr_t>(GetThreadLocal(key))); | 411 return static_cast<int>(reinterpret_cast<intptr_t>(GetThreadLocal(key))); |
| 407 } | 412 } |
| 408 static void SetThreadLocal(LocalStorageKey key, void* value); | 413 static void SetThreadLocal(LocalStorageKey key, void* value); |
| 409 static void SetThreadLocalInt(LocalStorageKey key, int value) { | 414 static void SetThreadLocalInt(LocalStorageKey key, int value) { |
| 410 SetThreadLocal(key, reinterpret_cast<void*>(static_cast<intptr_t>(value))); | 415 SetThreadLocal(key, reinterpret_cast<void*>(static_cast<intptr_t>(value))); |
| 411 } | 416 } |
| 412 static bool HasThreadLocal(LocalStorageKey key) { | 417 static bool HasThreadLocal(LocalStorageKey key) { |
| 413 return GetThreadLocal(key) != NULL; | 418 return GetThreadLocal(key) != NULL; |
| 414 } | 419 } |
| 415 | 420 |
| 416 // A hint to the scheduler to let another thread run. | 421 // A hint to the scheduler to let another thread run. |
| 417 static void YieldCPU(); | 422 static void YieldCPU(); |
| 418 | 423 |
| 419 Isolate* isolate() const { return isolate_; } | 424 Isolate* isolate() const { return isolate_; } |
| 420 | 425 |
| 426 // The thread name length is limited to 16 based on Linux's implementation of |
| 427 // prctl(). |
| 428 static const int kMaxThreadNameLength = 16; |
| 421 private: | 429 private: |
| 430 void set_name(const char *name); |
| 431 |
| 422 class PlatformData; | 432 class PlatformData; |
| 423 PlatformData* data_; | 433 PlatformData* data_; |
| 424 Isolate* isolate_; | 434 Isolate* isolate_; |
| 435 char name_[kMaxThreadNameLength]; |
| 436 |
| 425 DISALLOW_COPY_AND_ASSIGN(Thread); | 437 DISALLOW_COPY_AND_ASSIGN(Thread); |
| 426 }; | 438 }; |
| 427 | 439 |
| 428 | 440 |
| 429 // ---------------------------------------------------------------------------- | 441 // ---------------------------------------------------------------------------- |
| 430 // Mutex | 442 // Mutex |
| 431 // | 443 // |
| 432 // Mutexes are used for serializing access to non-reentrant sections of code. | 444 // Mutexes are used for serializing access to non-reentrant sections of code. |
| 433 // The implementations of mutex should allow for nested/recursive locking. | 445 // The implementations of mutex should allow for nested/recursive locking. |
| 434 | 446 |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 int samples_taken_; // Counts stack samples taken. | 635 int samples_taken_; // Counts stack samples taken. |
| 624 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); | 636 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); |
| 625 }; | 637 }; |
| 626 | 638 |
| 627 | 639 |
| 628 #endif // ENABLE_LOGGING_AND_PROFILING | 640 #endif // ENABLE_LOGGING_AND_PROFILING |
| 629 | 641 |
| 630 } } // namespace v8::internal | 642 } } // namespace v8::internal |
| 631 | 643 |
| 632 #endif // V8_PLATFORM_H_ | 644 #endif // V8_PLATFORM_H_ |
| OLD | NEW |