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

Side by Side Diff: src/platform-posix.cc

Issue 195863003: Access thread instance in posix platform using NoBarrier_Load and NoBarrier_Store. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 0, 0, 0); 608 0, 0, 0);
609 #endif 609 #endif
610 } 610 }
611 611
612 612
613 static void* ThreadEntry(void* arg) { 613 static void* ThreadEntry(void* arg) {
614 Thread* thread = reinterpret_cast<Thread*>(arg); 614 Thread* thread = reinterpret_cast<Thread*>(arg);
615 // This is also initialized by the first argument to pthread_create() but we 615 // This is also initialized by the first argument to pthread_create() but we
616 // don't know which thread will run first (the original thread or the new 616 // don't know which thread will run first (the original thread or the new
617 // one) so we initialize it here too. 617 // one) so we initialize it here too.
618 thread->data()->thread_ = pthread_self(); 618 NoBarrier_Store(reinterpret_cast<AtomicWord*>(&thread->data()->thread_),
619 pthread_self());
619 SetThreadName(thread->name()); 620 SetThreadName(thread->name());
620 ASSERT(thread->data()->thread_ != kNoThread); 621 ASSERT(static_cast<pthread_t>(
622 NoBarrier_Load(reinterpret_cast<AtomicWord*>(
623 &thread->data()->thread_))) != kNoThread);
621 thread->NotifyStartedAndRun(); 624 thread->NotifyStartedAndRun();
622 return NULL; 625 return NULL;
623 } 626 }
624 627
625 628
626 void Thread::set_name(const char* name) { 629 void Thread::set_name(const char* name) {
627 strncpy(name_, name, sizeof(name_)); 630 strncpy(name_, name, sizeof(name_));
628 name_[sizeof(name_) - 1] = '\0'; 631 name_[sizeof(name_) - 1] = '\0';
629 } 632 }
630 633
631 634
632 void Thread::Start() { 635 void Thread::Start() {
633 int result; 636 int result;
634 pthread_attr_t attr; 637 pthread_attr_t attr;
635 memset(&attr, 0, sizeof(attr)); 638 memset(&attr, 0, sizeof(attr));
636 result = pthread_attr_init(&attr); 639 result = pthread_attr_init(&attr);
637 ASSERT_EQ(0, result); 640 ASSERT_EQ(0, result);
638 // Native client uses default stack size. 641 // Native client uses default stack size.
639 #if !V8_OS_NACL 642 #if !V8_OS_NACL
640 if (stack_size_ > 0) { 643 if (stack_size_ > 0) {
641 result = pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_)); 644 result = pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_));
642 ASSERT_EQ(0, result); 645 ASSERT_EQ(0, result);
643 } 646 }
644 #endif 647 #endif
645 result = pthread_create(&data_->thread_, &attr, ThreadEntry, this); 648 result = pthread_create(&data_->thread_, &attr, ThreadEntry, this);
646 ASSERT_EQ(0, result); 649 ASSERT_EQ(0, result);
647 result = pthread_attr_destroy(&attr); 650 result = pthread_attr_destroy(&attr);
648 ASSERT_EQ(0, result); 651 ASSERT_EQ(0, result);
649 ASSERT(data_->thread_ != kNoThread); 652 ASSERT(static_cast<pthread_t>(
653 NoBarrier_Load(reinterpret_cast<AtomicWord*>(
654 &data_->thread_))) != kNoThread);
650 USE(result); 655 USE(result);
651 } 656 }
652 657
653 658
654 void Thread::Join() { 659 void Thread::Join() {
655 pthread_join(data_->thread_, NULL); 660 pthread_join(data_->thread_, NULL);
656 } 661 }
657 662
658 663
659 void Thread::YieldCPU() { 664 void Thread::YieldCPU() {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 786
782 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { 787 void Thread::SetThreadLocal(LocalStorageKey key, void* value) {
783 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); 788 pthread_key_t pthread_key = LocalKeyToPthreadKey(key);
784 int result = pthread_setspecific(pthread_key, value); 789 int result = pthread_setspecific(pthread_key, value);
785 ASSERT_EQ(0, result); 790 ASSERT_EQ(0, result);
786 USE(result); 791 USE(result);
787 } 792 }
788 793
789 794
790 } } // namespace v8::internal 795 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698