OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/libplatform/task-queue.h" | 5 #include "src/libplatform/task-queue.h" |
6 | 6 |
7 // TODO(jochen): We should have our own version of checks.h. | 7 #include "src/base/logging.h" |
8 #include "src/checks.h" | |
9 | 8 |
10 namespace v8 { | 9 namespace v8 { |
11 namespace internal { | 10 namespace internal { |
12 | 11 |
13 TaskQueue::TaskQueue() : process_queue_semaphore_(0), terminated_(false) {} | 12 TaskQueue::TaskQueue() : process_queue_semaphore_(0), terminated_(false) {} |
14 | 13 |
15 | 14 |
16 TaskQueue::~TaskQueue() { | 15 TaskQueue::~TaskQueue() { |
17 LockGuard<Mutex> guard(&lock_); | 16 base::LockGuard<base::Mutex> guard(&lock_); |
18 ASSERT(terminated_); | 17 ASSERT(terminated_); |
19 ASSERT(task_queue_.empty()); | 18 ASSERT(task_queue_.empty()); |
20 } | 19 } |
21 | 20 |
22 | 21 |
23 void TaskQueue::Append(Task* task) { | 22 void TaskQueue::Append(Task* task) { |
24 LockGuard<Mutex> guard(&lock_); | 23 base::LockGuard<base::Mutex> guard(&lock_); |
25 ASSERT(!terminated_); | 24 ASSERT(!terminated_); |
26 task_queue_.push(task); | 25 task_queue_.push(task); |
27 process_queue_semaphore_.Signal(); | 26 process_queue_semaphore_.Signal(); |
28 } | 27 } |
29 | 28 |
30 | 29 |
31 Task* TaskQueue::GetNext() { | 30 Task* TaskQueue::GetNext() { |
32 for (;;) { | 31 for (;;) { |
33 { | 32 { |
34 LockGuard<Mutex> guard(&lock_); | 33 base::LockGuard<base::Mutex> guard(&lock_); |
35 if (!task_queue_.empty()) { | 34 if (!task_queue_.empty()) { |
36 Task* result = task_queue_.front(); | 35 Task* result = task_queue_.front(); |
37 task_queue_.pop(); | 36 task_queue_.pop(); |
38 return result; | 37 return result; |
39 } | 38 } |
40 if (terminated_) { | 39 if (terminated_) { |
41 process_queue_semaphore_.Signal(); | 40 process_queue_semaphore_.Signal(); |
42 return NULL; | 41 return NULL; |
43 } | 42 } |
44 } | 43 } |
45 process_queue_semaphore_.Wait(); | 44 process_queue_semaphore_.Wait(); |
46 } | 45 } |
47 } | 46 } |
48 | 47 |
49 | 48 |
50 void TaskQueue::Terminate() { | 49 void TaskQueue::Terminate() { |
51 LockGuard<Mutex> guard(&lock_); | 50 base::LockGuard<base::Mutex> guard(&lock_); |
52 ASSERT(!terminated_); | 51 ASSERT(!terminated_); |
53 terminated_ = true; | 52 terminated_ = true; |
54 process_queue_semaphore_.Signal(); | 53 process_queue_semaphore_.Signal(); |
55 } | 54 } |
56 | 55 |
57 } } // namespace v8::internal | 56 } } // namespace v8::internal |
OLD | NEW |