未验证 提交 80dafdf5 编写于 作者: D dzhwinter 提交者: GitHub

"fix threadpool style" (#7017)

* "fix threadpool style"

* "remove header"
上级 52965458
...@@ -59,7 +59,8 @@ cc_test(var_type_inference_test SRCS var_type_inference_test.cc DEPS op_registry ...@@ -59,7 +59,8 @@ cc_test(var_type_inference_test SRCS var_type_inference_test.cc DEPS op_registry
cc_library(selected_rows SRCS selected_rows.cc DEPS tensor) cc_library(selected_rows SRCS selected_rows.cc DEPS tensor)
cc_test(selected_rows_test SRCS selected_rows_test.cc DEPS selected_rows) cc_test(selected_rows_test SRCS selected_rows_test.cc DEPS selected_rows)
cc_test(threadpool_test SRCS threadpool_test.cc) cc_library(threadpool SRCS threadpool.cc)
cc_test(threadpool_test SRCS threadpool_test.cc DEPS threadpool)
cc_library(init SRCS init.cc DEPS gflags device_context place stringpiece) cc_library(init SRCS init.cc DEPS gflags device_context place stringpiece)
cc_test(init_test SRCS init_test.cc DEPS init) cc_test(init_test SRCS init_test.cc DEPS init)
......
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/framework/threadpool.h"
namespace paddle {
namespace framework {
std::unique_ptr<ThreadPool> ThreadPool::threadpool(nullptr);
std::once_flag ThreadPool::init_flag;
} // namespace framework
} // namespace paddle
...@@ -13,15 +13,13 @@ See the License for the specific language governing permissions and ...@@ -13,15 +13,13 @@ See the License for the specific language governing permissions and
limitations under the License. */ limitations under the License. */
#pragma once #pragma once
#include <condition_variable> #include <condition_variable>
#include <cstdio>
#include <functional> #include <functional>
#include <iostream>
#include <mutex> #include <mutex>
#include <queue> #include <queue>
#include <thread> #include <thread>
#include "paddle/platform/call_once.h"
#include "paddle/platform/enforce.h" #include "paddle/platform/enforce.h"
namespace paddle { namespace paddle {
...@@ -81,10 +79,9 @@ class ThreadPool { ...@@ -81,10 +79,9 @@ class ThreadPool {
} }
private: private:
ThreadPool& operator=(const ThreadPool&) = delete; DISABLE_COPY_AND_ASSIGN(ThreadPool);
ThreadPool(const ThreadPool&) = delete;
ThreadPool(int num_threads) explicit ThreadPool(int num_threads)
: num_threads_(num_threads), available_(num_threads), running_(true) { : num_threads_(num_threads), available_(num_threads), running_(true) {
threads_.resize(num_threads); threads_.resize(num_threads);
for (auto& thread : threads_) { for (auto& thread : threads_) {
...@@ -155,7 +152,5 @@ class ThreadPool { ...@@ -155,7 +152,5 @@ class ThreadPool {
std::condition_variable completed_; std::condition_variable completed_;
}; };
std::unique_ptr<ThreadPool> ThreadPool::threadpool(nullptr);
std::once_flag ThreadPool::init_flag;
} // namespace framework } // namespace framework
} // namespace paddle } // namespace paddle
...@@ -12,12 +12,10 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ...@@ -12,12 +12,10 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. */ limitations under the License. */
#include "threadpool.h"
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <atomic> #include <atomic>
#include <chrono>
#include <map> #include "threadpool.h"
#include <thread>
namespace framework = paddle::framework; namespace framework = paddle::framework;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册