Files
sdk/runtime/bin/thread_pool_linux.cc
T
sgjesse@google.com 409a5cc49a Use platform implementation of Monitor in thread pool
This removes the direct use of pthread API for the thread pool monitor now that that code is shared. It also gets the Windows implementation for free.

Next step will be to get rid of using the pthread API for handling the threads as well, but that requires additional operations on the Thread class in platform/thread.h.

R=ager@google.com

BUG=
TEST=

Review URL: https://chromiumcodereview.appspot.com//9231020

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@3362 260f80e4-7a28-3924-810f-c04153c831b5
2012-01-17 15:36:35 +00:00

34 lines
962 B
C++

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include <pthread.h>
#include "bin/thread_pool.h"
void ThreadPool::Start() {
pthread_t* threads
= reinterpret_cast<pthread_t*>(calloc(size_, sizeof(pthread_t*))); // NOLINT
data_.set_threads(threads);
for (int i = 0; i < size_; i++) {
pthread_t handler_thread;
int result = pthread_create(&handler_thread,
NULL,
&ThreadPool::Main,
this);
if (result != 0) {
FATAL("Create and start thread pool thread");
}
data_.threads()[i] = handler_thread;
}
}
void ThreadPool::Shutdown() {
terminate_ = true;
queue_.Shutdown();
for (int i = 0; i < size_; i++) {
pthread_join(data_.threads()[i], NULL);
}
}