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

Side by Side Diff: src/platform-macos.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 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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 kMmapFd, kMmapFdOffset) != MAP_FAILED; 391 kMmapFd, kMmapFdOffset) != MAP_FAILED;
392 } 392 }
393 393
394 394
395 class Thread::PlatformData : public Malloced { 395 class Thread::PlatformData : public Malloced {
396 public: 396 public:
397 PlatformData() : thread_(kNoThread) {} 397 PlatformData() : thread_(kNoThread) {}
398 pthread_t thread_; // Thread handle for pthread. 398 pthread_t thread_; // Thread handle for pthread.
399 }; 399 };
400 400
401 Thread::Thread(Isolate* isolate, const Options& options) 401 Thread::Thread(const Options& options)
402 : data_(new PlatformData), 402 : data_(new PlatformData),
403 isolate_(isolate),
404 stack_size_(options.stack_size) { 403 stack_size_(options.stack_size) {
405 set_name(options.name); 404 set_name(options.name);
406 } 405 }
407 406
408 407
409 Thread::Thread(Isolate* isolate, const char* name) 408 Thread::Thread(const char* name)
410 : data_(new PlatformData), 409 : data_(new PlatformData),
411 isolate_(isolate),
412 stack_size_(0) { 410 stack_size_(0) {
413 set_name(name); 411 set_name(name);
414 } 412 }
415 413
416 414
417 Thread::~Thread() { 415 Thread::~Thread() {
418 delete data_; 416 delete data_;
419 } 417 }
420 418
421 419
(...skipping 15 matching lines...) Expand all
437 435
438 436
439 static void* ThreadEntry(void* arg) { 437 static void* ThreadEntry(void* arg) {
440 Thread* thread = reinterpret_cast<Thread*>(arg); 438 Thread* thread = reinterpret_cast<Thread*>(arg);
441 // This is also initialized by the first argument to pthread_create() but we 439 // This is also initialized by the first argument to pthread_create() but we
442 // don't know which thread will run first (the original thread or the new 440 // don't know which thread will run first (the original thread or the new
443 // one) so we initialize it here too. 441 // one) so we initialize it here too.
444 thread->data()->thread_ = pthread_self(); 442 thread->data()->thread_ = pthread_self();
445 SetThreadName(thread->name()); 443 SetThreadName(thread->name());
446 ASSERT(thread->data()->thread_ != kNoThread); 444 ASSERT(thread->data()->thread_ != kNoThread);
447 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate());
448 thread->Run(); 445 thread->Run();
449 return NULL; 446 return NULL;
450 } 447 }
451 448
452 449
453 void Thread::set_name(const char* name) { 450 void Thread::set_name(const char* name) {
454 strncpy(name_, name, sizeof(name_)); 451 strncpy(name_, name, sizeof(name_));
455 name_[sizeof(name_) - 1] = '\0'; 452 name_[sizeof(name_) - 1] = '\0';
456 } 453 }
457 454
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 private: 660 private:
664 // Note: for profiled_thread_ Mach primitives are used instead of PThread's 661 // Note: for profiled_thread_ Mach primitives are used instead of PThread's
665 // because the latter doesn't provide thread manipulation primitives required. 662 // because the latter doesn't provide thread manipulation primitives required.
666 // For details, consult "Mac OS X Internals" book, Section 7.3. 663 // For details, consult "Mac OS X Internals" book, Section 7.3.
667 thread_act_t profiled_thread_; 664 thread_act_t profiled_thread_;
668 }; 665 };
669 666
670 class SamplerThread : public Thread { 667 class SamplerThread : public Thread {
671 public: 668 public:
672 explicit SamplerThread(int interval) 669 explicit SamplerThread(int interval)
673 : Thread(NULL, "SamplerThread"), 670 : Thread("SamplerThread"),
674 interval_(interval) {} 671 interval_(interval) {}
675 672
676 static void AddActiveSampler(Sampler* sampler) { 673 static void AddActiveSampler(Sampler* sampler) {
677 ScopedLock lock(mutex_); 674 ScopedLock lock(mutex_);
678 SamplerRegistry::AddActiveSampler(sampler); 675 SamplerRegistry::AddActiveSampler(sampler);
679 if (instance_ == NULL) { 676 if (instance_ == NULL) {
680 instance_ = new SamplerThread(sampler->interval()); 677 instance_ = new SamplerThread(sampler->interval());
681 instance_->Start(); 678 instance_->Start();
682 } else { 679 } else {
683 ASSERT(instance_->interval_ == sampler->interval()); 680 ASSERT(instance_->interval_ == sampler->interval());
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 818
822 void Sampler::Stop() { 819 void Sampler::Stop() {
823 ASSERT(IsActive()); 820 ASSERT(IsActive());
824 SamplerThread::RemoveActiveSampler(this); 821 SamplerThread::RemoveActiveSampler(this);
825 SetActive(false); 822 SetActive(false);
826 } 823 }
827 824
828 #endif // ENABLE_LOGGING_AND_PROFILING 825 #endif // ENABLE_LOGGING_AND_PROFILING
829 826
830 } } // namespace v8::internal 827 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698