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

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

Issue 6070009: Added labelled thread names to help with some debugging activity. Right now,... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 11 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 | « src/platform-freebsd.cc ('k') | src/platform-macos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 return pthread_equal(data_->thread_, pthread_self()); 544 return pthread_equal(data_->thread_, pthread_self());
545 } 545 }
546 546
547 547
548 bool ThreadHandle::IsValid() const { 548 bool ThreadHandle::IsValid() const {
549 return data_->thread_ != kNoThread; 549 return data_->thread_ != kNoThread;
550 } 550 }
551 551
552 552
553 Thread::Thread() : ThreadHandle(ThreadHandle::INVALID) { 553 Thread::Thread() : ThreadHandle(ThreadHandle::INVALID) {
554 set_name("v8:<unknown>");
555 }
556
557
558 Thread::Thread(const char* name) : ThreadHandle(ThreadHandle::INVALID) {
559 set_name(name);
554 } 560 }
555 561
556 562
557 Thread::~Thread() { 563 Thread::~Thread() {
558 } 564 }
559 565
560 566
561 static void* ThreadEntry(void* arg) { 567 static void* ThreadEntry(void* arg) {
562 Thread* thread = reinterpret_cast<Thread*>(arg); 568 Thread* thread = reinterpret_cast<Thread*>(arg);
563 // This is also initialized by the first argument to pthread_create() but we 569 // This is also initialized by the first argument to pthread_create() but we
564 // don't know which thread will run first (the original thread or the new 570 // don't know which thread will run first (the original thread or the new
565 // one) so we initialize it here too. 571 // one) so we initialize it here too.
572 ::prctl(PR_SET_NAME, thread->name(), 0, 0, 0);
566 thread->thread_handle_data()->thread_ = pthread_self(); 573 thread->thread_handle_data()->thread_ = pthread_self();
567 ASSERT(thread->IsValid()); 574 ASSERT(thread->IsValid());
568 thread->Run(); 575 thread->Run();
569 return NULL; 576 return NULL;
570 } 577 }
571 578
572 579
580 void Thread::set_name(const char* name) {
581 strncpy(name_, name, sizeof(name_));
582 name_[sizeof(name_) - 1] = '\0';
583 }
584
585
573 void Thread::Start() { 586 void Thread::Start() {
574 pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this); 587 pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this);
575 ASSERT(IsValid()); 588 ASSERT(IsValid());
576 } 589 }
577 590
578 591
579 void Thread::Join() { 592 void Thread::Join() {
580 pthread_join(thread_handle_data()->thread_, NULL); 593 pthread_join(thread_handle_data()->thread_, NULL);
581 } 594 }
582 595
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 } 957 }
945 958
946 // This sampler is no longer the active sampler. 959 // This sampler is no longer the active sampler.
947 active_sampler_ = NULL; 960 active_sampler_ = NULL;
948 } 961 }
949 962
950 963
951 #endif // ENABLE_LOGGING_AND_PROFILING 964 #endif // ENABLE_LOGGING_AND_PROFILING
952 965
953 } } // namespace v8::internal 966 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-freebsd.cc ('k') | src/platform-macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698