|
17 | 17 | #include "objectregistry.h"
|
18 | 18 |
|
19 | 19 | std::mutex ExecutorPool::initGuard;
|
20 |
| -std::atomic<ExecutorPool*> ExecutorPool::instance; |
21 | 20 |
|
22 | 21 | static const size_t EP_MIN_NONIO_THREADS = 2;
|
23 | 22 |
|
24 | 23 | static const size_t EP_MAX_AUXIO_THREADS = 8;
|
25 | 24 | static const size_t EP_MAX_NONIO_THREADS = 8;
|
26 | 25 |
|
27 | 26 | ExecutorPool *ExecutorPool::get() {
|
28 |
| - auto* tmp = instance.load(); |
| 27 | + auto* tmp = getInstance().get(); |
29 | 28 | if (tmp == nullptr) {
|
30 | 29 | LockHolder lh(initGuard);
|
31 |
| - tmp = instance.load(); |
| 30 | + tmp = getInstance().get(); |
32 | 31 | if (tmp == nullptr) {
|
33 | 32 | // Double-checked locking if instance is null - ensure two threads
|
34 | 33 | // don't both create an instance.
|
@@ -58,20 +57,16 @@ ExecutorPool *ExecutorPool::get() {
|
58 | 57 | "ExecutorPool::get() Invalid executor_pool_backend '" +
|
59 | 58 | config.getExecutorPoolBackend() + "'");
|
60 | 59 | }
|
61 |
| - instance.store(tmp); |
| 60 | + getInstance().reset(tmp); |
62 | 61 | }
|
63 | 62 | }
|
64 | 63 | return tmp;
|
65 | 64 | }
|
66 | 65 |
|
67 | 66 | void ExecutorPool::shutdown() {
|
68 | 67 | std::lock_guard<std::mutex> lock(initGuard);
|
69 |
| - auto* tmp = instance.load(); |
70 |
| - if (tmp != nullptr) { |
71 |
| - NonBucketAllocationGuard guard; |
72 |
| - delete tmp; |
73 |
| - instance = nullptr; |
74 |
| - } |
| 68 | + NonBucketAllocationGuard guard; |
| 69 | + getInstance().reset(); |
75 | 70 | }
|
76 | 71 |
|
77 | 72 | ExecutorPool::ExecutorPool(size_t maxThreads)
|
@@ -213,3 +208,8 @@ int ExecutorPool::getThreadPriority(task_type_t taskType) {
|
213 | 208 | #endif
|
214 | 209 | return 0;
|
215 | 210 | }
|
| 211 | + |
| 212 | +std::unique_ptr<ExecutorPool>& ExecutorPool::getInstance() { |
| 213 | + static std::unique_ptr<ExecutorPool> instance; |
| 214 | + return instance; |
| 215 | +} |
0 commit comments