OLD | NEW |
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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 bool ThreadHandle::IsSelf() const { | 393 bool ThreadHandle::IsSelf() const { |
394 return pthread_equal(data_->thread_, pthread_self()); | 394 return pthread_equal(data_->thread_, pthread_self()); |
395 } | 395 } |
396 | 396 |
397 | 397 |
398 bool ThreadHandle::IsValid() const { | 398 bool ThreadHandle::IsValid() const { |
399 return data_->thread_ != kNoThread; | 399 return data_->thread_ != kNoThread; |
400 } | 400 } |
401 | 401 |
402 | 402 |
403 Thread::Thread(Isolate* isolate) | 403 Thread::Thread(Isolate* isolate, const Options& options) |
404 : ThreadHandle(ThreadHandle::INVALID), | 404 : ThreadHandle(ThreadHandle::INVALID), |
405 isolate_(isolate) { | 405 isolate_(isolate), |
406 set_name("v8:<unknown>"); | 406 stack_size_(options.stack_size) { |
| 407 set_name(options.name); |
407 } | 408 } |
408 | 409 |
409 | 410 |
410 Thread::Thread(Isolate* isolate, const char* name) | 411 Thread::Thread(Isolate* isolate, const char* name) |
411 : ThreadHandle(ThreadHandle::INVALID), | 412 : ThreadHandle(ThreadHandle::INVALID), |
412 isolate_(isolate) { | 413 isolate_(isolate), |
| 414 stack_size_(0) { |
413 set_name(name); | 415 set_name(name); |
414 } | 416 } |
415 | 417 |
416 | 418 |
417 Thread::~Thread() { | 419 Thread::~Thread() { |
418 } | 420 } |
419 | 421 |
420 | 422 |
421 static void* ThreadEntry(void* arg) { | 423 static void* ThreadEntry(void* arg) { |
422 Thread* thread = reinterpret_cast<Thread*>(arg); | 424 Thread* thread = reinterpret_cast<Thread*>(arg); |
423 // This is also initialized by the first argument to pthread_create() but we | 425 // This is also initialized by the first argument to pthread_create() but we |
424 // don't know which thread will run first (the original thread or the new | 426 // don't know which thread will run first (the original thread or the new |
425 // one) so we initialize it here too. | 427 // one) so we initialize it here too. |
426 thread->thread_handle_data()->thread_ = pthread_self(); | 428 thread->thread_handle_data()->thread_ = pthread_self(); |
427 ASSERT(thread->IsValid()); | 429 ASSERT(thread->IsValid()); |
428 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate()); | 430 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate()); |
429 thread->Run(); | 431 thread->Run(); |
430 return NULL; | 432 return NULL; |
431 } | 433 } |
432 | 434 |
433 | 435 |
434 void Thread::set_name(const char* name) { | 436 void Thread::set_name(const char* name) { |
435 strncpy(name_, name, sizeof(name_)); | 437 strncpy(name_, name, sizeof(name_)); |
436 name_[sizeof(name_) - 1] = '\0'; | 438 name_[sizeof(name_) - 1] = '\0'; |
437 } | 439 } |
438 | 440 |
439 | 441 |
440 void Thread::Start() { | 442 void Thread::Start() { |
441 pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this); | 443 pthread_attr_t* attr_ptr = NULL; |
| 444 pthread_attr_t attr; |
| 445 if (stack_size_ > 0) { |
| 446 pthread_attr_init(&attr); |
| 447 pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_)); |
| 448 attr_ptr = &attr; |
| 449 } |
| 450 pthread_create(&thread_handle_data()->thread_, attr_ptr, ThreadEntry, this); |
442 ASSERT(IsValid()); | 451 ASSERT(IsValid()); |
443 } | 452 } |
444 | 453 |
445 | 454 |
446 void Thread::Join() { | 455 void Thread::Join() { |
447 pthread_join(thread_handle_data()->thread_, NULL); | 456 pthread_join(thread_handle_data()->thread_, NULL); |
448 } | 457 } |
449 | 458 |
450 | 459 |
451 Thread::LocalStorageKey Thread::CreateThreadLocalKey() { | 460 Thread::LocalStorageKey Thread::CreateThreadLocalKey() { |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 } | 663 } |
655 | 664 |
656 // This sampler is no longer the active sampler. | 665 // This sampler is no longer the active sampler. |
657 active_sampler_ = NULL; | 666 active_sampler_ = NULL; |
658 active_ = false; | 667 active_ = false; |
659 } | 668 } |
660 | 669 |
661 #endif // ENABLE_LOGGING_AND_PROFILING | 670 #endif // ENABLE_LOGGING_AND_PROFILING |
662 | 671 |
663 } } // namespace v8::internal | 672 } } // namespace v8::internal |
OLD | NEW |