提交 64e7688a 编写于 作者: X Xin Pan

clean more APIs

test=develop
上级 c891bc22
...@@ -25,22 +25,14 @@ DEFINE_int32(dist_threadpool_size, 0, ...@@ -25,22 +25,14 @@ DEFINE_int32(dist_threadpool_size, 0,
namespace paddle { namespace paddle {
namespace framework { namespace framework {
std::mutex threadpool_mu;
std::unique_ptr<ThreadPool> ThreadPool::threadpool_(nullptr); std::unique_ptr<ThreadPool> ThreadPool::threadpool_(nullptr);
std::once_flag ThreadPool::init_flag_; std::once_flag ThreadPool::init_flag_;
ThreadPool* ThreadPool::GetInstance() { ThreadPool* ThreadPool::GetInstance() {
std::lock_guard<std::mutex> l(threadpool_mu);
std::call_once(init_flag_, &ThreadPool::Init); std::call_once(init_flag_, &ThreadPool::Init);
return threadpool_.get(); return threadpool_.get();
} }
void ThreadPool::TestReset() {
std::lock_guard<std::mutex> l(threadpool_mu);
threadpool_.reset(nullptr);
ThreadPool::Init();
}
void ThreadPool::Init() { void ThreadPool::Init() {
if (threadpool_.get() == nullptr) { if (threadpool_.get() == nullptr) {
// TODO(Yancey1989): specify the max threads number // TODO(Yancey1989): specify the max threads number
......
...@@ -55,10 +55,6 @@ class ThreadPool { ...@@ -55,10 +55,6 @@ class ThreadPool {
// Returns the singleton of ThreadPool. // Returns the singleton of ThreadPool.
static ThreadPool* GetInstance(); static ThreadPool* GetInstance();
// delete current thread pool and create a new one.
// Only used by test cases to reset the threadpool.
static void TestReset();
~ThreadPool(); ~ThreadPool();
// Run pushes a function to the task queue and returns a std::future // Run pushes a function to the task queue and returns a std::future
......
...@@ -52,6 +52,5 @@ TEST(ThreadPool, ConcurrentRun) { ...@@ -52,6 +52,5 @@ TEST(ThreadPool, ConcurrentRun) {
for (auto& t : threads) { for (auto& t : threads) {
t.join(); t.join();
} }
framework::ThreadPool::TestReset();
EXPECT_EQ(sum, ((n + 1) * n) / 2); EXPECT_EQ(sum, ((n + 1) * n) / 2);
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册