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

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

Issue 6711068: Use v8::internal threading support in samples/shell.cc. (Closed)
Patch Set: Created 9 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
« no previous file with comments | « src/platform-cygwin.cc ('k') | src/platform-linux.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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 bool ThreadHandle::IsSelf() const { 418 bool ThreadHandle::IsSelf() const {
419 return pthread_equal(data_->thread_, pthread_self()); 419 return pthread_equal(data_->thread_, pthread_self());
420 } 420 }
421 421
422 422
423 bool ThreadHandle::IsValid() const { 423 bool ThreadHandle::IsValid() const {
424 return data_->thread_ != kNoThread; 424 return data_->thread_ != kNoThread;
425 } 425 }
426 426
427 427
428 Thread::Thread(Isolate* isolate) 428 Thread::Thread(Isolate* isolate, const Options& options)
429 : ThreadHandle(ThreadHandle::INVALID), 429 : ThreadHandle(ThreadHandle::INVALID),
430 isolate_(isolate) { 430 isolate_(isolate),
431 set_name("v8:<unknown>"); 431 stack_size_(options.stack_size) {
432 set_name(options.name);
432 } 433 }
433 434
435
434 Thread::Thread(Isolate* isolate, const char* name) 436 Thread::Thread(Isolate* isolate, const char* name)
435 : ThreadHandle(ThreadHandle::INVALID), 437 : ThreadHandle(ThreadHandle::INVALID),
436 isolate_(isolate) { 438 isolate_(isolate),
439 stack_size_(0) {
437 set_name(name); 440 set_name(name);
438 } 441 }
439 442
440 443
441 Thread::~Thread() { 444 Thread::~Thread() {
442 } 445 }
443 446
444 447
445 static void* ThreadEntry(void* arg) { 448 static void* ThreadEntry(void* arg) {
446 Thread* thread = reinterpret_cast<Thread*>(arg); 449 Thread* thread = reinterpret_cast<Thread*>(arg);
447 // This is also initialized by the first argument to pthread_create() but we 450 // This is also initialized by the first argument to pthread_create() but we
448 // don't know which thread will run first (the original thread or the new 451 // don't know which thread will run first (the original thread or the new
449 // one) so we initialize it here too. 452 // one) so we initialize it here too.
450 thread->thread_handle_data()->thread_ = pthread_self(); 453 thread->thread_handle_data()->thread_ = pthread_self();
451 ASSERT(thread->IsValid()); 454 ASSERT(thread->IsValid());
452 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate()); 455 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate());
453 thread->Run(); 456 thread->Run();
454 return NULL; 457 return NULL;
455 } 458 }
456 459
457 460
458 void Thread::set_name(const char* name) { 461 void Thread::set_name(const char* name) {
459 strncpy(name_, name, sizeof(name_)); 462 strncpy(name_, name, sizeof(name_));
460 name_[sizeof(name_) - 1] = '\0'; 463 name_[sizeof(name_) - 1] = '\0';
461 } 464 }
462 465
463 466
464 void Thread::Start() { 467 void Thread::Start() {
465 pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this); 468 pthread_attr_t* attr_ptr = NULL;
469 pthread_attr_t attr;
470 if (stack_size_ > 0) {
471 pthread_attr_init(&attr);
472 pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_));
473 attr_ptr = &attr;
474 }
475 pthread_create(&thread_handle_data()->thread_, attr_ptr, ThreadEntry, this);
466 ASSERT(IsValid()); 476 ASSERT(IsValid());
467 } 477 }
468 478
469 479
470 void Thread::Join() { 480 void Thread::Join() {
471 pthread_join(thread_handle_data()->thread_, NULL); 481 pthread_join(thread_handle_data()->thread_, NULL);
472 } 482 }
473 483
474 484
475 Thread::LocalStorageKey Thread::CreateThreadLocalKey() { 485 Thread::LocalStorageKey Thread::CreateThreadLocalKey() {
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 if (data_->signal_sender_launched_) { 792 if (data_->signal_sender_launched_) {
783 Top::WakeUpRuntimeProfilerThreadBeforeShutdown(); 793 Top::WakeUpRuntimeProfilerThreadBeforeShutdown();
784 pthread_join(data_->signal_sender_thread_, NULL); 794 pthread_join(data_->signal_sender_thread_, NULL);
785 data_->signal_sender_launched_ = false; 795 data_->signal_sender_launched_ = false;
786 } 796 }
787 } 797 }
788 798
789 #endif // ENABLE_LOGGING_AND_PROFILING 799 #endif // ENABLE_LOGGING_AND_PROFILING
790 800
791 } } // namespace v8::internal 801 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-cygwin.cc ('k') | src/platform-linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698