Chromium Code Reviews

Unified Diff: src/libplatform/default-platform.cc

Issue 104583003: [platform] Implement a worker pool (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: updates Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
« no previous file with comments | « src/libplatform/default-platform.h ('k') | src/libplatform/task-queue.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/libplatform/default-platform.cc
diff --git a/src/default-platform.cc b/src/libplatform/default-platform.cc
similarity index 61%
copy from src/default-platform.cc
copy to src/libplatform/default-platform.cc
index ef3c4ebd450bbc63ae99b4534a22fa5bd67a2f39..679fbc5f52a7e1beb9ee1c13fb08570aec90ddb0 100644
--- a/src/default-platform.cc
+++ b/src/libplatform/default-platform.cc
@@ -25,24 +25,50 @@
// (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 "default-platform.h"
+#include <queue>
+
+// TODO(jochen): We should have our own version of checks.h.
+#include "../checks.h"
+// TODO(jochen): Why is cpu.h not in platform/?
+#include "../cpu.h"
+#include "task-queue.h"
+#include "worker-thread.h"
+
namespace v8 {
namespace internal {
+int DefaultPlatform::thread_pool_size_ = 0;
+
-DefaultPlatform::DefaultPlatform() {}
+DefaultPlatform::DefaultPlatform() : thread_pool_(NULL), queue_(NULL) {}
-DefaultPlatform::~DefaultPlatform() {}
+DefaultPlatform::~DefaultPlatform() {
+ if (thread_pool_) {
+ queue_->Terminate();
+ for (int i = 0; i < thread_pool_size_; ++i) {
+ delete thread_pool_[i];
+ }
+ delete[] thread_pool_;
+ delete queue_;
+ }
+}
+
+
+// static
+void DefaultPlatform::SetThreadPoolSize(int thread_pool_size) {
+ ASSERT(thread_pool_size >= 0);
+ // TODO(jochen): If this wasn't a static member, we should
+ // ASSERT(!thread_pool_);
+ thread_pool_size_ = thread_pool_size;
+}
void DefaultPlatform::CallOnBackgroundThread(Task *task,
ExpectedRuntime expected_runtime) {
- // TODO(jochen): implement.
- task->Run();
- delete task;
+ EnsureThreadPoolStarted();
+ queue_->Append(task);
}
@@ -53,4 +79,17 @@ void DefaultPlatform::CallOnForegroundThread(v8::Isolate* isolate, Task* task) {
}
+void DefaultPlatform::EnsureThreadPoolStarted() {
+ if (thread_pool_) return;
+ queue_ = new TaskQueue;
+ if (thread_pool_size_ < 1)
+ thread_pool_size_ = CPU::NumberOfProcessorsOnline();
+ thread_pool_size_ = Max(Min(thread_pool_size_, 4), 1);
Sven Panne 2013/12/05 13:12:31 Either make it a v8 flag or make it at least a con
+
+ thread_pool_ = new WorkerThread*[thread_pool_size_];
+
+ for (int i = 0; i < thread_pool_size_; ++i)
+ thread_pool_[i] = new WorkerThread(queue_);
+}
+
} } // namespace v8::internal
« no previous file with comments | « src/libplatform/default-platform.h ('k') | src/libplatform/task-queue.h » ('j') | no next file with comments »

Powered by Google App Engine