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

Side by Side Diff: src/platform-solaris.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-openbsd.cc ('k') | src/platform-win32.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-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 bool ThreadHandle::IsSelf() const { 408 bool ThreadHandle::IsSelf() const {
409 return pthread_equal(data_->thread_, pthread_self()); 409 return pthread_equal(data_->thread_, pthread_self());
410 } 410 }
411 411
412 412
413 bool ThreadHandle::IsValid() const { 413 bool ThreadHandle::IsValid() const {
414 return data_->thread_ != kNoThread; 414 return data_->thread_ != kNoThread;
415 } 415 }
416 416
417 417
418 Thread::Thread(Isolate* isolate) 418 Thread::Thread(Isolate* isolate, const Options& options)
419 : ThreadHandle(ThreadHandle::INVALID), 419 : ThreadHandle(ThreadHandle::INVALID),
420 isolate_(isolate) { 420 isolate_(isolate),
421 set_name("v8:<unknown>"); 421 stack_size_(options.stack_size) {
422 set_name(options.name);
422 } 423 }
423 424
424 425
425 Thread::Thread(Isolate* isolate, const char* name) 426 Thread::Thread(Isolate* isolate, const char* name)
426 : ThreadHandle(ThreadHandle::INVALID), 427 : ThreadHandle(ThreadHandle::INVALID),
427 isolate_(isolate) { 428 isolate_(isolate),
429 stack_size_(0) {
428 set_name(name); 430 set_name(name);
429 } 431 }
430 432
431 433
432 Thread::~Thread() { 434 Thread::~Thread() {
433 } 435 }
434 436
435 437
436 static void* ThreadEntry(void* arg) { 438 static void* ThreadEntry(void* arg) {
437 Thread* thread = reinterpret_cast<Thread*>(arg); 439 Thread* thread = reinterpret_cast<Thread*>(arg);
438 // This is also initialized by the first argument to pthread_create() but we 440 // This is also initialized by the first argument to pthread_create() but we
439 // don't know which thread will run first (the original thread or the new 441 // don't know which thread will run first (the original thread or the new
440 // one) so we initialize it here too. 442 // one) so we initialize it here too.
441 thread->thread_handle_data()->thread_ = pthread_self(); 443 thread->thread_handle_data()->thread_ = pthread_self();
442 ASSERT(thread->IsValid()); 444 ASSERT(thread->IsValid());
443 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate()); 445 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate());
444 thread->Run(); 446 thread->Run();
445 return NULL; 447 return NULL;
446 } 448 }
447 449
448 450
449 void Thread::set_name(const char* name) { 451 void Thread::set_name(const char* name) {
450 strncpy(name_, name, sizeof(name_)); 452 strncpy(name_, name, sizeof(name_));
451 name_[sizeof(name_) - 1] = '\0'; 453 name_[sizeof(name_) - 1] = '\0';
452 } 454 }
453 455
454 456
455 void Thread::Start() { 457 void Thread::Start() {
458 pthread_attr_t* attr_ptr = NULL;
459 pthread_attr_t attr;
460 if (stack_size_ > 0) {
461 pthread_attr_init(&attr);
462 pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_));
463 attr_ptr = &attr;
464 }
456 pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this); 465 pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this);
457 ASSERT(IsValid()); 466 ASSERT(IsValid());
458 } 467 }
459 468
460 469
461 void Thread::Join() { 470 void Thread::Join() {
462 pthread_join(thread_handle_data()->thread_, NULL); 471 pthread_join(thread_handle_data()->thread_, NULL);
463 } 472 }
464 473
465 474
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 data_->signal_handler_installed_ = false; 787 data_->signal_handler_installed_ = false;
779 } 788 }
780 789
781 // This sampler is no longer the active sampler. 790 // This sampler is no longer the active sampler.
782 active_sampler_ = NULL; 791 active_sampler_ = NULL;
783 } 792 }
784 793
785 #endif // ENABLE_LOGGING_AND_PROFILING 794 #endif // ENABLE_LOGGING_AND_PROFILING
786 795
787 } } // namespace v8::internal 796 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-openbsd.cc ('k') | src/platform-win32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698