Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(720)

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. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« 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 64%
rename from src/default-platform.cc
rename to src/libplatform/default-platform.cc
index ef3c4ebd450bbc63ae99b4534a22fa5bd67a2f39..f05dc1107a0d5f1e7bbac104b91f703715587ccb 100644
--- a/src/default-platform.cc
+++ b/src/libplatform/default-platform.cc
@@ -25,24 +25,58 @@
// (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 "worker-thread.h"
+
namespace v8 {
namespace internal {
-DefaultPlatform::DefaultPlatform() {}
+DefaultPlatform::DefaultPlatform()
+ : initialized_(false) {}
+
+
+DefaultPlatform::~DefaultPlatform() {
+ LockGuard<Mutex> guard(&lock_);
+ if (initialized_) {
+ queue_.Terminate();
+ for (std::vector<WorkerThread*>::iterator i = thread_pool_.begin();
+ i != thread_pool_.end(); ++i) {
+ delete *i;
+ }
+ }
+}
+
+void DefaultPlatform::SetThreadPoolSize(int thread_pool_size) {
+ LockGuard<Mutex> guard(&lock_);
+ ASSERT(thread_pool_size >= 0);
+ if (initialized_) return;
+ initialized_ = true;
+ if (thread_pool_size < 1)
+ thread_pool_size = CPU::NumberOfProcessorsOnline();
+ thread_pool_size = Max(Min(thread_pool_size, kMaxThreadPoolSize), 1);
-DefaultPlatform::~DefaultPlatform() {}
+ for (int i = 0; i < thread_pool_size; ++i)
+ thread_pool_.push_back(new WorkerThread(&queue_));
+}
void DefaultPlatform::CallOnBackgroundThread(Task *task,
ExpectedRuntime expected_runtime) {
- // TODO(jochen): implement.
- task->Run();
- delete task;
+#ifdef DEBUG
+ {
+ LockGuard<Mutex> guard(&lock_);
+ ASSERT(initialized_);
+ }
+#endif
+ queue_.Append(task);
}
@@ -52,5 +86,4 @@ void DefaultPlatform::CallOnForegroundThread(v8::Isolate* isolate, Task* task) {
delete task;
}
-
} } // 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
This is Rietveld 408576698