| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 #include <pthread.h> | |
| 6 | |
| 7 #include "bin/thread_pool.h" | |
| 8 | |
| 9 void ThreadPool::Start() { | |
| 10 pthread_t* threads | |
| 11 = reinterpret_cast<pthread_t*>(calloc(size_, sizeof(pthread_t*))); // NOL
INT | |
| 12 data_.set_threads(threads); | |
| 13 for (int i = 0; i < size_; i++) { | |
| 14 pthread_t handler_thread; | |
| 15 int result = pthread_create(&handler_thread, | |
| 16 NULL, | |
| 17 &ThreadPool::Main, | |
| 18 this); | |
| 19 if (result != 0) { | |
| 20 FATAL("Create and start thread pool thread"); | |
| 21 } | |
| 22 data_.threads()[i] = handler_thread; | |
| 23 } | |
| 24 } | |
| 25 | |
| 26 | |
| 27 void ThreadPool::Shutdown() { | |
| 28 terminate_ = true; | |
| 29 queue_.Shutdown(); | |
| 30 for (int i = 0; i < size_; i++) { | |
| 31 pthread_join(data_.threads()[i], NULL); | |
| 32 } | |
| 33 } | |
| OLD | NEW |