Index: src/libplatform/task-queue.cc |
diff --git a/src/default-platform.cc b/src/libplatform/task-queue.cc |
similarity index 63% |
rename from src/default-platform.cc |
rename to src/libplatform/task-queue.cc |
index ef3c4ebd450bbc63ae99b4534a22fa5bd67a2f39..1ea31eb26e0aa700944fa9927e460ef73b5ae9fa 100644 |
--- a/src/default-platform.cc |
+++ b/src/libplatform/task-queue.cc |
@@ -25,32 +25,56 @@ |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
-#include "v8.h" |
+#include "task-queue.h" |
-#include "default-platform.h" |
+// TODO(jochen): We should have our own version of checks.h. |
+#include "../checks.h" |
namespace v8 { |
namespace internal { |
+TaskQueue::TaskQueue() : process_queue_semaphore_(0), terminated_(false) {} |
-DefaultPlatform::DefaultPlatform() {} |
+TaskQueue::~TaskQueue() { |
+ LockGuard<Mutex> guard(&lock_); |
+ ASSERT(terminated_); |
+ ASSERT(task_queue_.empty()); |
+} |
-DefaultPlatform::~DefaultPlatform() {} |
-void DefaultPlatform::CallOnBackgroundThread(Task *task, |
- ExpectedRuntime expected_runtime) { |
- // TODO(jochen): implement. |
- task->Run(); |
- delete task; |
+void TaskQueue::Append(Task* task) { |
+ LockGuard<Mutex> guard(&lock_); |
+ ASSERT(!terminated_); |
+ task_queue_.push(task); |
+ process_queue_semaphore_.Signal(); |
} |
-void DefaultPlatform::CallOnForegroundThread(v8::Isolate* isolate, Task* task) { |
- // TODO(jochen): implement. |
- task->Run(); |
- delete task; |
+Task* TaskQueue::GetNext() { |
+ for (;;) { |
+ { |
+ LockGuard<Mutex> guard(&lock_); |
+ if (!task_queue_.empty()) { |
+ Task* result = task_queue_.front(); |
+ task_queue_.pop(); |
+ return result; |
+ } |
+ if (terminated_) { |
+ process_queue_semaphore_.Signal(); |
Hannes Payer (out of office)
2013/12/09 18:50:51
Why do you need that signal? The thread that termi
jochen (gone - plz use gerrit)
2013/12/09 19:04:31
There can be multiple threads waiting on the semap
|
+ return NULL; |
+ } |
+ } |
+ process_queue_semaphore_.Wait(); |
+ } |
} |
+void TaskQueue::Terminate() { |
+ LockGuard<Mutex> guard(&lock_); |
+ ASSERT(!terminated_); |
+ terminated_ = true; |
+ process_queue_semaphore_.Signal(); |
+} |
+ |
} } // namespace v8::internal |