Skip to content

Commit 80dafdf

Browse files
authored
"fix threadpool style" (#7017)
* "fix threadpool style" * "remove header"
1 parent 5296545 commit 80dafdf

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

paddle/framework/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ cc_test(var_type_inference_test SRCS var_type_inference_test.cc DEPS op_registry
5959
cc_library(selected_rows SRCS selected_rows.cc DEPS tensor)
6060
cc_test(selected_rows_test SRCS selected_rows_test.cc DEPS selected_rows)
6161

62-
cc_test(threadpool_test SRCS threadpool_test.cc)
62+
cc_library(threadpool SRCS threadpool.cc)
63+
cc_test(threadpool_test SRCS threadpool_test.cc DEPS threadpool)
6364
cc_library(init SRCS init.cc DEPS gflags device_context place stringpiece)
6465
cc_test(init_test SRCS init_test.cc DEPS init)
6566

paddle/framework/threadpool.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License. */
14+
15+
#include "paddle/framework/threadpool.h"
16+
17+
namespace paddle {
18+
namespace framework {
19+
20+
std::unique_ptr<ThreadPool> ThreadPool::threadpool(nullptr);
21+
std::once_flag ThreadPool::init_flag;
22+
23+
} // namespace framework
24+
} // namespace paddle

paddle/framework/threadpool.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@ See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

1515
#pragma once
16+
1617
#include <condition_variable>
17-
#include <cstdio>
1818
#include <functional>
19-
#include <iostream>
2019
#include <mutex>
2120
#include <queue>
2221
#include <thread>
2322

24-
#include "paddle/platform/call_once.h"
2523
#include "paddle/platform/enforce.h"
2624

2725
namespace paddle {
@@ -81,10 +79,9 @@ class ThreadPool {
8179
}
8280

8381
private:
84-
ThreadPool& operator=(const ThreadPool&) = delete;
85-
ThreadPool(const ThreadPool&) = delete;
82+
DISABLE_COPY_AND_ASSIGN(ThreadPool);
8683

87-
ThreadPool(int num_threads)
84+
explicit ThreadPool(int num_threads)
8885
: num_threads_(num_threads), available_(num_threads), running_(true) {
8986
threads_.resize(num_threads);
9087
for (auto& thread : threads_) {
@@ -155,7 +152,5 @@ class ThreadPool {
155152
std::condition_variable completed_;
156153
};
157154

158-
std::unique_ptr<ThreadPool> ThreadPool::threadpool(nullptr);
159-
std::once_flag ThreadPool::init_flag;
160155
} // namespace framework
161156
} // namespace paddle

paddle/framework/threadpool_test.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

15-
#include "threadpool.h"
1615
#include <gtest/gtest.h>
1716
#include <atomic>
18-
#include <chrono>
19-
#include <map>
20-
#include <thread>
17+
18+
#include "threadpool.h"
2119

2220
namespace framework = paddle::framework;
2321

0 commit comments

Comments
 (0)