V8 Project
v8::platform Namespace Reference

Namespaces

 anonymous_namespace{default-platform-unittest.cc}
 
 anonymous_namespace{task-queue-unittest.cc}
 
 anonymous_namespace{worker-thread-unittest.cc}
 

Classes

class  DefaultPlatform
 
class  TaskQueue
 
class  WorkerThread
 

Functions

 TEST (DefaultPlatformTest, PumpMessageLoop)
 
v8::PlatformCreateDefaultPlatform (int thread_pool_size=0)
 Returns a new instance of the default v8::Platform implementation. More...
 
bool PumpMessageLoop (v8::Platform *platform, v8::Isolate *isolate)
 Pumps the message loop for the given isolate. More...
 
 TEST (TaskQueueTest, Basic)
 
 TEST (TaskQueueTest, TerminateMultipleReaders)
 
 TEST (WorkerThreadTest, Basic)
 

Function Documentation

◆ CreateDefaultPlatform()

v8::Platform * v8::platform::CreateDefaultPlatform ( int  thread_pool_size = 0)

Returns a new instance of the default v8::Platform implementation.

The caller will take ownership of the returned pointer. |thread_pool_size| is the number of worker threads to allocate for background jobs. If a value of zero is passed, a suitable default based on the current number of processors online will be chosen.

Definition at line 19 of file default-platform.cc.

19  {
20  DefaultPlatform* platform = new DefaultPlatform();
21  platform->SetThreadPoolSize(thread_pool_size);
22  platform->EnsureInitialized();
23  return platform;
24 }

References v8::platform::DefaultPlatform::EnsureInitialized(), and v8::platform::DefaultPlatform::SetThreadPoolSize().

Referenced by main(), v8::Shell::Main(), and anonymous_namespace{run-all-unittests.cc}::FINAL::SetUp().

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

◆ PumpMessageLoop()

bool v8::platform::PumpMessageLoop ( v8::Platform platform,
v8::Isolate isolate 
)

Pumps the message loop for the given isolate.

The caller has to make sure that this is called from the right thread. Returns true if a task was executed, and false otherwise. This call does not block if no task is pending. The |platform| has to be created using |CreateDefaultPlatform|.

Definition at line 27 of file default-platform.cc.

27  {
28  return reinterpret_cast<DefaultPlatform*>(platform)->PumpMessageLoop(isolate);
29 }
bool PumpMessageLoop(v8::Platform *platform, v8::Isolate *isolate)
Pumps the message loop for the given isolate.

◆ TEST() [1/4]

v8::platform::TEST ( DefaultPlatformTest  ,
PumpMessageLoop   
)

Definition at line 25 of file default-platform-unittest.cc.

25  {
26  InSequence s;
27 
28  int dummy;
29  Isolate* isolate = reinterpret_cast<Isolate*>(&dummy);
30 
31  DefaultPlatform platform;
32  EXPECT_FALSE(platform.PumpMessageLoop(isolate));
33 
34  StrictMock<MockTask>* task = new StrictMock<MockTask>;
35  platform.CallOnForegroundThread(isolate, task);
36  EXPECT_CALL(*task, Run());
37  EXPECT_CALL(*task, Die());
38  EXPECT_TRUE(platform.PumpMessageLoop(isolate));
39  EXPECT_FALSE(platform.PumpMessageLoop(isolate));
40 }

References v8::platform::DefaultPlatform::CallOnForegroundThread(), and v8::platform::DefaultPlatform::PumpMessageLoop().

+ Here is the call graph for this function:

◆ TEST() [2/4]

v8::platform::TEST ( TaskQueueTest  ,
Basic   
)

Definition at line 38 of file task-queue-unittest.cc.

38  {
39  TaskQueue queue;
40  MockTask task;
41  queue.Append(&task);
42  EXPECT_EQ(&task, queue.GetNext());
43  queue.Terminate();
44  EXPECT_THAT(queue.GetNext(), IsNull());
45 }

References v8::platform::TaskQueue::Append(), v8::platform::TaskQueue::GetNext(), and v8::platform::TaskQueue::Terminate().

+ Here is the call graph for this function:

◆ TEST() [3/4]

v8::platform::TEST ( TaskQueueTest  ,
TerminateMultipleReaders   
)

Definition at line 48 of file task-queue-unittest.cc.

48  {
49  TaskQueue queue;
50  TaskQueueThread thread1(&queue);
51  TaskQueueThread thread2(&queue);
52  thread1.Start();
53  thread2.Start();
54  queue.Terminate();
55  thread1.Join();
56  thread2.Join();
57 }

References v8::platform::TaskQueue::Terminate().

+ Here is the call graph for this function:

◆ TEST() [4/4]

v8::platform::TEST ( WorkerThreadTest  ,
Basic   
)

Definition at line 28 of file worker-thread-unittest.cc.

28  {
29  static const size_t kNumTasks = 10;
30 
31  TaskQueue queue;
32  for (size_t i = 0; i < kNumTasks; ++i) {
33  InSequence s;
34  StrictMock<MockTask>* task = new StrictMock<MockTask>;
35  EXPECT_CALL(*task, Run());
36  EXPECT_CALL(*task, Die());
37  queue.Append(task);
38  }
39 
40  WorkerThread thread1(&queue);
41  WorkerThread thread2(&queue);
42 
43  // TaskQueue DCHECKS that it's empty in its destructor.
44  queue.Terminate();
45 }

References v8::platform::TaskQueue::Append(), and v8::platform::TaskQueue::Terminate().

+ Here is the call graph for this function: