-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
205 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* GlobalTaskGroup.cpp | ||
* | ||
* Copyright (c) 2019 hikyuu.org | ||
* | ||
* Created on: 2020-4-20 | ||
* Author: fasiondog | ||
*/ | ||
|
||
#include <chrono> | ||
#include "GlobalTaskGroup.h" | ||
|
||
namespace hku { | ||
|
||
static ThreadPool* g_threadPool; | ||
|
||
HKU_API ThreadPool* getGlobalTaskGroup() { | ||
return g_threadPool; | ||
} | ||
|
||
void initThreadPool() { | ||
if (!g_threadPool) { | ||
auto cpu_num = std::thread::hardware_concurrency(); | ||
if (cpu_num >= 4) { | ||
cpu_num -= 2; | ||
} else if (cpu_num > 1) { | ||
cpu_num--; | ||
} | ||
g_threadPool = new ThreadPool(cpu_num); | ||
} | ||
} | ||
|
||
void releaseThreadPool() { | ||
if (g_threadPool) { | ||
g_threadPool->stop(); | ||
delete g_threadPool; | ||
g_threadPool = nullptr; | ||
} | ||
} | ||
|
||
} /* namespace hku */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* GlobalTaskGroup.h | ||
* | ||
* Copyright (c) 2019 hikyuu.org | ||
* | ||
* Created on: 2020-4-20 | ||
* Author: fasiondog | ||
*/ | ||
|
||
#pragma | ||
#ifndef HKU_GLOBAL_TASK_GROUP | ||
#define HKU_GLOBAL_TASK_GROUP | ||
|
||
#include "utilities/thread/ThreadPool.h" | ||
|
||
#ifndef HKU_API | ||
#define HKU_API | ||
#endif | ||
|
||
namespace hku { | ||
|
||
/** | ||
* 获取全局线程池任务组 | ||
* @note 请使用 future 获取任务返回 | ||
*/ | ||
HKU_API ThreadPool* getGlobalTaskGroup(); | ||
|
||
/* | ||
* 内部函数,初始化全局任务组 | ||
*/ | ||
void initThreadPool(); | ||
|
||
/* 内部函数,初始化全局任务组 */ | ||
void releaseThreadPool(); | ||
|
||
} /* namespace hku */ | ||
|
||
#endif /* HKU_GLOBAL_TASK_GROUP */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.