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

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

Issue 7003108: "Deiceolate" Thread classes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 6 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
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 } 646 }
647 647
648 648
649 class Thread::PlatformData : public Malloced { 649 class Thread::PlatformData : public Malloced {
650 public: 650 public:
651 PlatformData() : thread_(kNoThread) {} 651 PlatformData() : thread_(kNoThread) {}
652 652
653 pthread_t thread_; // Thread handle for pthread. 653 pthread_t thread_; // Thread handle for pthread.
654 }; 654 };
655 655
656 Thread::Thread(Isolate* isolate, const Options& options) 656 Thread::Thread(const Options& options)
657 : data_(new PlatformData()), 657 : data_(new PlatformData()),
658 isolate_(isolate),
659 stack_size_(options.stack_size) { 658 stack_size_(options.stack_size) {
660 set_name(options.name); 659 set_name(options.name);
661 } 660 }
662 661
663 662
664 Thread::Thread(Isolate* isolate, const char* name) 663 Thread::Thread(const char* name)
665 : data_(new PlatformData()), 664 : data_(new PlatformData()),
666 isolate_(isolate),
667 stack_size_(0) { 665 stack_size_(0) {
668 set_name(name); 666 set_name(name);
669 } 667 }
670 668
671 669
672 Thread::~Thread() { 670 Thread::~Thread() {
673 delete data_; 671 delete data_;
674 } 672 }
675 673
676 674
677 static void* ThreadEntry(void* arg) { 675 static void* ThreadEntry(void* arg) {
678 Thread* thread = reinterpret_cast<Thread*>(arg); 676 Thread* thread = reinterpret_cast<Thread*>(arg);
679 // This is also initialized by the first argument to pthread_create() but we 677 // This is also initialized by the first argument to pthread_create() but we
680 // don't know which thread will run first (the original thread or the new 678 // don't know which thread will run first (the original thread or the new
681 // one) so we initialize it here too. 679 // one) so we initialize it here too.
682 prctl(PR_SET_NAME, 680 prctl(PR_SET_NAME,
683 reinterpret_cast<unsigned long>(thread->name()), // NOLINT 681 reinterpret_cast<unsigned long>(thread->name()), // NOLINT
684 0, 0, 0); 682 0, 0, 0);
685 thread->data()->thread_ = pthread_self(); 683 thread->data()->thread_ = pthread_self();
686 ASSERT(thread->data()->thread_ != kNoThread); 684 ASSERT(thread->data()->thread_ != kNoThread);
687 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate());
688 thread->Run(); 685 thread->Run();
689 return NULL; 686 return NULL;
690 } 687 }
691 688
692 689
693 void Thread::set_name(const char* name) { 690 void Thread::set_name(const char* name) {
694 strncpy(name_, name, sizeof(name_)); 691 strncpy(name_, name, sizeof(name_));
695 name_[sizeof(name_) - 1] = '\0'; 692 name_[sizeof(name_) - 1] = '\0';
696 } 693 }
697 694
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 964
968 965
969 class SignalSender : public Thread { 966 class SignalSender : public Thread {
970 public: 967 public:
971 enum SleepInterval { 968 enum SleepInterval {
972 HALF_INTERVAL, 969 HALF_INTERVAL,
973 FULL_INTERVAL 970 FULL_INTERVAL
974 }; 971 };
975 972
976 explicit SignalSender(int interval) 973 explicit SignalSender(int interval)
977 : Thread(NULL, "SignalSender"), 974 : Thread("SignalSender"),
978 vm_tgid_(getpid()), 975 vm_tgid_(getpid()),
979 interval_(interval) {} 976 interval_(interval) {}
980 977
981 static void InstallSignalHandler() { 978 static void InstallSignalHandler() {
982 struct sigaction sa; 979 struct sigaction sa;
983 sa.sa_sigaction = ProfilerSignalHandler; 980 sa.sa_sigaction = ProfilerSignalHandler;
984 sigemptyset(&sa.sa_mask); 981 sigemptyset(&sa.sa_mask);
985 sa.sa_flags = SA_RESTART | SA_SIGINFO; 982 sa.sa_flags = SA_RESTART | SA_SIGINFO;
986 signal_handler_installed_ = 983 signal_handler_installed_ =
987 (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0); 984 (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0);
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 1145
1149 void Sampler::Stop() { 1146 void Sampler::Stop() {
1150 ASSERT(IsActive()); 1147 ASSERT(IsActive());
1151 SignalSender::RemoveActiveSampler(this); 1148 SignalSender::RemoveActiveSampler(this);
1152 SetActive(false); 1149 SetActive(false);
1153 } 1150 }
1154 1151
1155 #endif // ENABLE_LOGGING_AND_PROFILING 1152 #endif // ENABLE_LOGGING_AND_PROFILING
1156 1153
1157 } } // namespace v8::internal 1154 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698