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

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

Issue 157503002: A64: Synchronize with r18444. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 10 months 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..1e21ca4e82379b6734d54e6d9f77b50bedab61e9 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), thread_pool_size_(0) {}
+
+DefaultPlatform::~DefaultPlatform() {
+ LockGuard<Mutex> guard(&lock_);
+ queue_.Terminate();
+ if (initialized_) {
+ 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 (thread_pool_size < 1)
+ thread_pool_size = CPU::NumberOfProcessorsOnline();
+ thread_pool_size_ = Max(Min(thread_pool_size, kMaxThreadPoolSize), 1);
+}
-DefaultPlatform::~DefaultPlatform() {}
+
+void DefaultPlatform::EnsureInitialized() {
+ LockGuard<Mutex> guard(&lock_);
+ if (initialized_) return;
+ initialized_ = true;
+
+ 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;
+ EnsureInitialized();
+ 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