| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 *usecs = usage.ru_utime.tv_usec; | 347 *usecs = usage.ru_utime.tv_usec; |
| 348 return 0; | 348 return 0; |
| 349 } | 349 } |
| 350 | 350 |
| 351 | 351 |
| 352 double OS::TimeCurrentMillis() { | 352 double OS::TimeCurrentMillis() { |
| 353 return Time::Now().ToJsTime(); | 353 return Time::Now().ToJsTime(); |
| 354 } | 354 } |
| 355 | 355 |
| 356 | 356 |
| 357 double OS::DaylightSavingsOffset(double time) { | 357 class TimezoneCache {}; |
| 358 |
| 359 |
| 360 TimezoneCache* OS::CreateTimezoneCache() { |
| 361 return NULL; |
| 362 } |
| 363 |
| 364 |
| 365 void OS::DisposeTimezoneCache(TimezoneCache* cache) { |
| 366 ASSERT(cache == NULL); |
| 367 } |
| 368 |
| 369 |
| 370 void OS::ClearTimezoneCache(TimezoneCache* cache) { |
| 371 ASSERT(cache == NULL); |
| 372 } |
| 373 |
| 374 |
| 375 double OS::DaylightSavingsOffset(double time, TimezoneCache*) { |
| 358 if (std::isnan(time)) return nan_value(); | 376 if (std::isnan(time)) return nan_value(); |
| 359 time_t tv = static_cast<time_t>(std::floor(time/msPerSecond)); | 377 time_t tv = static_cast<time_t>(std::floor(time/msPerSecond)); |
| 360 struct tm* t = localtime(&tv); | 378 struct tm* t = localtime(&tv); |
| 361 if (NULL == t) return nan_value(); | 379 if (NULL == t) return nan_value(); |
| 362 return t->tm_isdst > 0 ? 3600 * msPerSecond : 0; | 380 return t->tm_isdst > 0 ? 3600 * msPerSecond : 0; |
| 363 } | 381 } |
| 364 | 382 |
| 365 | 383 |
| 366 int OS::GetLastError() { | 384 int OS::GetLastError() { |
| 367 return errno; | 385 return errno; |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 | 573 |
| 556 | 574 |
| 557 // ---------------------------------------------------------------------------- | 575 // ---------------------------------------------------------------------------- |
| 558 // POSIX thread support. | 576 // POSIX thread support. |
| 559 // | 577 // |
| 560 | 578 |
| 561 class Thread::PlatformData : public Malloced { | 579 class Thread::PlatformData : public Malloced { |
| 562 public: | 580 public: |
| 563 PlatformData() : thread_(kNoThread) {} | 581 PlatformData() : thread_(kNoThread) {} |
| 564 pthread_t thread_; // Thread handle for pthread. | 582 pthread_t thread_; // Thread handle for pthread. |
| 583 // Synchronizes thread creation |
| 584 Mutex thread_creation_mutex_; |
| 565 }; | 585 }; |
| 566 | 586 |
| 567 Thread::Thread(const Options& options) | 587 Thread::Thread(const Options& options) |
| 568 : data_(new PlatformData), | 588 : data_(new PlatformData), |
| 569 stack_size_(options.stack_size()), | 589 stack_size_(options.stack_size()), |
| 570 start_semaphore_(NULL) { | 590 start_semaphore_(NULL) { |
| 571 if (stack_size_ > 0 && stack_size_ < PTHREAD_STACK_MIN) { | 591 if (stack_size_ > 0 && stack_size_ < PTHREAD_STACK_MIN) { |
| 572 stack_size_ = PTHREAD_STACK_MIN; | 592 stack_size_ = PTHREAD_STACK_MIN; |
| 573 } | 593 } |
| 574 set_name(options.name()); | 594 set_name(options.name()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 602 #elif defined(PR_SET_NAME) | 622 #elif defined(PR_SET_NAME) |
| 603 prctl(PR_SET_NAME, | 623 prctl(PR_SET_NAME, |
| 604 reinterpret_cast<unsigned long>(name), // NOLINT | 624 reinterpret_cast<unsigned long>(name), // NOLINT |
| 605 0, 0, 0); | 625 0, 0, 0); |
| 606 #endif | 626 #endif |
| 607 } | 627 } |
| 608 | 628 |
| 609 | 629 |
| 610 static void* ThreadEntry(void* arg) { | 630 static void* ThreadEntry(void* arg) { |
| 611 Thread* thread = reinterpret_cast<Thread*>(arg); | 631 Thread* thread = reinterpret_cast<Thread*>(arg); |
| 612 // This is also initialized by the first argument to pthread_create() but we | 632 // We take the lock here to make sure that pthread_create finished first since |
| 613 // don't know which thread will run first (the original thread or the new | 633 // we don't know which thread will run first (the original thread or the new |
| 614 // one) so we initialize it here too. | 634 // one). |
| 615 thread->data()->thread_ = pthread_self(); | 635 { LockGuard<Mutex> lock_guard(&thread->data()->thread_creation_mutex_); } |
| 616 SetThreadName(thread->name()); | 636 SetThreadName(thread->name()); |
| 617 ASSERT(thread->data()->thread_ != kNoThread); | 637 ASSERT(thread->data()->thread_ != kNoThread); |
| 618 thread->NotifyStartedAndRun(); | 638 thread->NotifyStartedAndRun(); |
| 619 return NULL; | 639 return NULL; |
| 620 } | 640 } |
| 621 | 641 |
| 622 | 642 |
| 623 void Thread::set_name(const char* name) { | 643 void Thread::set_name(const char* name) { |
| 624 strncpy(name_, name, sizeof(name_)); | 644 strncpy(name_, name, sizeof(name_)); |
| 625 name_[sizeof(name_) - 1] = '\0'; | 645 name_[sizeof(name_) - 1] = '\0'; |
| 626 } | 646 } |
| 627 | 647 |
| 628 | 648 |
| 629 void Thread::Start() { | 649 void Thread::Start() { |
| 630 int result; | 650 int result; |
| 631 pthread_attr_t attr; | 651 pthread_attr_t attr; |
| 632 memset(&attr, 0, sizeof(attr)); | 652 memset(&attr, 0, sizeof(attr)); |
| 633 result = pthread_attr_init(&attr); | 653 result = pthread_attr_init(&attr); |
| 634 ASSERT_EQ(0, result); | 654 ASSERT_EQ(0, result); |
| 635 // Native client uses default stack size. | 655 // Native client uses default stack size. |
| 636 #if !V8_OS_NACL | 656 #if !V8_OS_NACL |
| 637 if (stack_size_ > 0) { | 657 if (stack_size_ > 0) { |
| 638 result = pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_)); | 658 result = pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_)); |
| 639 ASSERT_EQ(0, result); | 659 ASSERT_EQ(0, result); |
| 640 } | 660 } |
| 641 #endif | 661 #endif |
| 642 result = pthread_create(&data_->thread_, &attr, ThreadEntry, this); | 662 { |
| 663 LockGuard<Mutex> lock_guard(&data_->thread_creation_mutex_); |
| 664 result = pthread_create(&data_->thread_, &attr, ThreadEntry, this); |
| 665 } |
| 643 ASSERT_EQ(0, result); | 666 ASSERT_EQ(0, result); |
| 644 result = pthread_attr_destroy(&attr); | 667 result = pthread_attr_destroy(&attr); |
| 645 ASSERT_EQ(0, result); | 668 ASSERT_EQ(0, result); |
| 646 ASSERT(data_->thread_ != kNoThread); | 669 ASSERT(data_->thread_ != kNoThread); |
| 647 USE(result); | 670 USE(result); |
| 648 } | 671 } |
| 649 | 672 |
| 650 | 673 |
| 651 void Thread::Join() { | 674 void Thread::Join() { |
| 652 pthread_join(data_->thread_, NULL); | 675 pthread_join(data_->thread_, NULL); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 | 801 |
| 779 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { | 802 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { |
| 780 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); | 803 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); |
| 781 int result = pthread_setspecific(pthread_key, value); | 804 int result = pthread_setspecific(pthread_key, value); |
| 782 ASSERT_EQ(0, result); | 805 ASSERT_EQ(0, result); |
| 783 USE(result); | 806 USE(result); |
| 784 } | 807 } |
| 785 | 808 |
| 786 | 809 |
| 787 } } // namespace v8::internal | 810 } } // namespace v8::internal |
| OLD | NEW |