V8 Project
v8::base::Thread Class Referenceabstract

#include <platform.h>

+ Inheritance diagram for v8::base::Thread:
+ Collaboration diagram for v8::base::Thread:

Classes

class  Options
 
class  PlatformData
 

Public Types

typedef int32_t LocalStorageKey
 

Public Member Functions

 Thread (const Options &options)
 
virtual ~Thread ()
 
void Start ()
 
void StartSynchronously ()
 
void Join ()
 
const char * name () const
 
virtual void Run ()=0
 
PlatformDatadata ()
 
void NotifyStartedAndRun ()
 

Static Public Member Functions

static LocalStorageKey CreateThreadLocalKey ()
 
static void DeleteThreadLocalKey (LocalStorageKey key)
 
static void * GetThreadLocal (LocalStorageKey key)
 
static int GetThreadLocalInt (LocalStorageKey key)
 
static void SetThreadLocal (LocalStorageKey key, void *value)
 
static void SetThreadLocalInt (LocalStorageKey key, int value)
 
static bool HasThreadLocal (LocalStorageKey key)
 
static void * GetExistingThreadLocal (LocalStorageKey key)
 
static void YieldCPU ()
 

Static Public Attributes

static const int kMaxThreadNameLength = 16
 

Private Member Functions

void set_name (const char *name)
 
 DISALLOW_COPY_AND_ASSIGN (Thread)
 

Private Attributes

PlatformDatadata_
 
char name_ [kMaxThreadNameLength]
 
int stack_size_
 
Semaphore * start_semaphore_
 

Detailed Description

Definition at line 413 of file platform.h.

Member Typedef Documentation

◆ LocalStorageKey

Definition at line 416 of file platform.h.

Constructor & Destructor Documentation

◆ Thread()

v8::base::Thread::Thread ( const Options options)
explicit

Definition at line 455 of file platform-posix.cc.

456  : data_(new PlatformData),
457  stack_size_(options.stack_size()),
459  if (stack_size_ > 0 && static_cast<size_t>(stack_size_) < PTHREAD_STACK_MIN) {
460  stack_size_ = PTHREAD_STACK_MIN;
461  }
462  set_name(options.name());
463 }
Semaphore * start_semaphore_
Definition: platform.h:509
PlatformData * data_
Definition: platform.h:505
void set_name(const char *name)
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL

References v8::base::Thread::Options::name(), set_name(), and stack_size_.

+ Here is the call graph for this function:

◆ ~Thread()

v8::base::Thread::~Thread ( )
virtual

Definition at line 466 of file platform-posix.cc.

466  {
467  delete data_;
468 }

References data_.

Member Function Documentation

◆ CreateThreadLocalKey()

Thread::LocalStorageKey v8::base::Thread::CreateThreadLocalKey ( )
static

Definition at line 635 of file platform-posix.cc.

635  {
636 #ifdef V8_FAST_TLS_SUPPORTED
637  bool check_fast_tls = false;
638  if (tls_base_offset_initialized == 0) {
639  check_fast_tls = true;
640  InitializeTlsBaseOffset();
641  }
642 #endif
643  pthread_key_t key;
644  int result = pthread_key_create(&key, NULL);
645  DCHECK_EQ(0, result);
646  USE(result);
647  LocalStorageKey local_key = PthreadKeyToLocalKey(key);
648 #ifdef V8_FAST_TLS_SUPPORTED
649  // If we just initialized fast TLS support, make sure it works.
650  if (check_fast_tls) CheckFastTls(local_key);
651 #endif
652  return local_key;
653 }
int32_t LocalStorageKey
Definition: platform.h:416
#define DCHECK_EQ(v1, v2)
Definition: logging.h:206
void USE(T)
Definition: macros.h:322
static Thread::LocalStorageKey PthreadKeyToLocalKey(pthread_key_t pthread_key)

References DCHECK_EQ, NULL, v8::base::PthreadKeyToLocalKey(), and USE().

Referenced by v8::internal::anonymous_namespace{assert-scope.cc}::FINAL::Construct(), v8::internal::Isolate::InitializeOncePerProcess(), and v8::base::anonymous_namespace{platform-unittest.cc}::ThreadLocalStorageTest::ThreadLocalStorageTest().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ data()

PlatformData* v8::base::Thread::data ( )
inline

Definition at line 495 of file platform.h.

495 { return data_; }

References data_.

Referenced by v8::base::ThreadEntry().

+ Here is the caller graph for this function:

◆ DeleteThreadLocalKey()

void v8::base::Thread::DeleteThreadLocalKey ( LocalStorageKey  key)
static

Definition at line 656 of file platform-posix.cc.

656  {
657  pthread_key_t pthread_key = LocalKeyToPthreadKey(key);
658  int result = pthread_key_delete(pthread_key);
659  DCHECK_EQ(0, result);
660  USE(result);
661 }
static pthread_key_t LocalKeyToPthreadKey(Thread::LocalStorageKey local_key)

References DCHECK_EQ, v8::base::LocalKeyToPthreadKey(), and USE().

Referenced by v8::base::anonymous_namespace{platform-unittest.cc}::ThreadLocalStorageTest::~ThreadLocalStorageTest().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DISALLOW_COPY_AND_ASSIGN()

v8::base::Thread::DISALLOW_COPY_AND_ASSIGN ( Thread  )
private

◆ GetExistingThreadLocal()

static void* v8::base::Thread::GetExistingThreadLocal ( LocalStorageKey  key)
inlinestatic

Definition at line 481 of file platform.h.

481  {
482  return GetThreadLocal(key);
483  }
static void * GetThreadLocal(LocalStorageKey key)

References GetThreadLocal().

Referenced by v8::internal::Isolate::INLINE(), and v8::base::anonymous_namespace{platform-unittest.cc}::ThreadLocalStorageTest::Run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetThreadLocal()

void * v8::base::Thread::GetThreadLocal ( LocalStorageKey  key)
static

Definition at line 664 of file platform-posix.cc.

664  {
665  pthread_key_t pthread_key = LocalKeyToPthreadKey(key);
666  return pthread_getspecific(pthread_key);
667 }

References v8::base::LocalKeyToPthreadKey().

Referenced by v8::internal::Isolate::CurrentPerIsolateThreadData(), v8::internal::FINAL< kOperandKind, kNumCachedOperands >::GetCurrent(), GetExistingThreadLocal(), GetThreadLocalInt(), HasThreadLocal(), v8::internal::Isolate::INLINE(), and v8::base::anonymous_namespace{platform-unittest.cc}::ThreadLocalStorageTest::Run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetThreadLocalInt()

static int v8::base::Thread::GetThreadLocalInt ( LocalStorageKey  key)
inlinestatic

Definition at line 462 of file platform.h.

462  {
463  return static_cast<int>(reinterpret_cast<intptr_t>(GetThreadLocal(key)));
464  }

References GetThreadLocal().

Referenced by v8::internal::ThreadId::GetCurrentThreadId().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HasThreadLocal()

static bool v8::base::Thread::HasThreadLocal ( LocalStorageKey  key)
inlinestatic

Definition at line 469 of file platform.h.

469  {
470  return GetThreadLocal(key) != NULL;
471  }

References GetThreadLocal(), and NULL.

Referenced by v8::base::anonymous_namespace{platform-unittest.cc}::ThreadLocalStorageTest::Run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Join()

void v8::base::Thread::Join ( )

Definition at line 542 of file platform-posix.cc.

542  {
543  pthread_join(data_->thread_, NULL);
544 }

References data_, NULL, and v8::base::Thread::PlatformData::thread_.

Referenced by v8::internal::Profiler::Disengage(), v8::internal::SamplerThread::RemoveActiveSampler(), v8::internal::SweeperThread::Stop(), v8::internal::OptimizingCompilerThread::Stop(), v8::internal::ProfilerEventsProcessor::StopSynchronously(), v8::base::TEST(), and v8::platform::WorkerThread::~WorkerThread().

+ Here is the caller graph for this function:

◆ name()

const char* v8::base::Thread::name ( ) const
inline

Definition at line 451 of file platform.h.

451  {
452  return name_;
453  }
char name_[kMaxThreadNameLength]
Definition: platform.h:507

References name_.

Referenced by set_name(), and v8::base::ThreadEntry().

+ Here is the caller graph for this function:

◆ NotifyStartedAndRun()

void v8::base::Thread::NotifyStartedAndRun ( )
inline

Definition at line 497 of file platform.h.

497  {
498  if (start_semaphore_) start_semaphore_->Signal();
499  Run();
500  }
virtual void Run()=0

References Run(), and start_semaphore_.

Referenced by v8::base::ThreadEntry().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Run()

◆ set_name()

void v8::base::Thread::set_name ( const char *  name)
private

Definition at line 511 of file platform-posix.cc.

511  {
512  strncpy(name_, name, sizeof(name_));
513  name_[sizeof(name_) - 1] = '\0';
514 }
const char * name() const
Definition: platform.h:451

References name(), and name_.

Referenced by Thread().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetThreadLocal()

void v8::base::Thread::SetThreadLocal ( LocalStorageKey  key,
void *  value 
)
static

Definition at line 670 of file platform-posix.cc.

670  {
671  pthread_key_t pthread_key = LocalKeyToPthreadKey(key);
672  int result = pthread_setspecific(pthread_key, value);
673  DCHECK_EQ(0, result);
674  USE(result);
675 }

References DCHECK_EQ, v8::base::LocalKeyToPthreadKey(), and USE().

Referenced by v8::base::anonymous_namespace{platform-unittest.cc}::ThreadLocalStorageTest::Run(), v8::internal::FINAL< kOperandKind, kNumCachedOperands >::SetCurrent(), v8::internal::Isolate::SetIsolateThreadLocals(), and SetThreadLocalInt().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetThreadLocalInt()

static void v8::base::Thread::SetThreadLocalInt ( LocalStorageKey  key,
int  value 
)
inlinestatic

Definition at line 466 of file platform.h.

466  {
467  SetThreadLocal(key, reinterpret_cast<void*>(static_cast<intptr_t>(value)));
468  }
static void SetThreadLocal(LocalStorageKey key, void *value)

References SetThreadLocal().

Referenced by v8::internal::ThreadId::GetCurrentThreadId().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Start()

void v8::base::Thread::Start ( )

Definition at line 517 of file platform-posix.cc.

517  {
518  int result;
519  pthread_attr_t attr;
520  memset(&attr, 0, sizeof(attr));
521  result = pthread_attr_init(&attr);
522  DCHECK_EQ(0, result);
523  // Native client uses default stack size.
524 #if !V8_OS_NACL
525  if (stack_size_ > 0) {
526  result = pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_));
527  DCHECK_EQ(0, result);
528  }
529 #endif
530  {
531  LockGuard<Mutex> lock_guard(&data_->thread_creation_mutex_);
532  result = pthread_create(&data_->thread_, &attr, ThreadEntry, this);
533  }
534  DCHECK_EQ(0, result);
535  result = pthread_attr_destroy(&attr);
536  DCHECK_EQ(0, result);
538  USE(result);
539 }
#define DCHECK(condition)
Definition: logging.h:205
static void * ThreadEntry(void *arg)
static const pthread_t kNoThread
Definition: platform-qnx.cc:43

References data_, DCHECK, DCHECK_EQ, v8::base::kNoThread, stack_size_, v8::base::Thread::PlatformData::thread_, v8::base::Thread::PlatformData::thread_creation_mutex_, v8::base::ThreadEntry(), and USE().

Referenced by v8::internal::Profiler::Engage(), v8::internal::Isolate::Init(), StartSynchronously(), v8::base::TEST(), and v8::platform::WorkerThread::WorkerThread().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ StartSynchronously()

void v8::base::Thread::StartSynchronously ( )
inline

Definition at line 440 of file platform.h.

440  {
441  start_semaphore_ = new Semaphore(0);
442  Start();
443  start_semaphore_->Wait();
444  delete start_semaphore_;
446  }

References NULL, Start(), and start_semaphore_.

Referenced by v8::internal::SamplerThread::AddActiveSampler(), and v8::internal::CpuProfiler::StartProcessorIfNotStarted().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ YieldCPU()

void v8::base::Thread::YieldCPU ( )
static

Definition at line 547 of file platform-posix.cc.

547  {
548  int result = sched_yield();
549  DCHECK_EQ(0, result);
550  USE(result);
551 }

References DCHECK_EQ, and USE().

+ Here is the call graph for this function:

Member Data Documentation

◆ data_

PlatformData* v8::base::Thread::data_
private

Definition at line 505 of file platform.h.

Referenced by data(), Join(), Start(), and ~Thread().

◆ kMaxThreadNameLength

const int v8::base::Thread::kMaxThreadNameLength = 16
static

Definition at line 492 of file platform.h.

Referenced by v8::base::SetThreadName().

◆ name_

char v8::base::Thread::name_[kMaxThreadNameLength]
private

Definition at line 507 of file platform.h.

Referenced by name(), and set_name().

◆ stack_size_

int v8::base::Thread::stack_size_
private

Definition at line 508 of file platform.h.

Referenced by Start(), and Thread().

◆ start_semaphore_

Semaphore* v8::base::Thread::start_semaphore_
private

Definition at line 509 of file platform.h.

Referenced by NotifyStartedAndRun(), and StartSynchronously().


The documentation for this class was generated from the following files: