diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-05-30 15:56:46 -0400 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-05-30 15:56:46 -0400 |
| commit | f1d22f3fde0cb7bf201168a11774793b4efc98f7 (patch) | |
| tree | d982c699978d794e203572efc1cfe95f41b0b827 /src | |
| parent | 781410537a1c7ddac340efabeedd4c9309e5cf39 (diff) | |
pke: thrdpl: BucketContainer > pk_bkt_arr
Diffstat (limited to 'src')
| -rw-r--r-- | src/thread-pool.cpp | 30 | ||||
| -rw-r--r-- | src/thread-pool.hpp | 4 |
2 files changed, 17 insertions, 17 deletions
diff --git a/src/thread-pool.cpp b/src/thread-pool.cpp index 15c5551..5bd61c5 100644 --- a/src/thread-pool.cpp +++ b/src/thread-pool.cpp @@ -1,7 +1,6 @@ #include "thread-pool.hpp" -#include "bucketed-array.hpp" #include "pk.h" #include <functional> @@ -19,9 +18,9 @@ struct ThreadPool { struct pk_membucket *bkt = nullptr; }; -const pk_handle_item_index_T MAX_THREADS_PER_BUCKET = 8; - -BucketContainer<ThreadPool, ThreadPoolHandle> ThreadPool_BucketContainer{}; +struct ThreadPoolMaster { + pk_bkt_arr_t<ThreadPool> bc{}; +}thrdpl_mstr; void ThreadRun(ThreadPool *tp) { std::packaged_task<void()> *j = nullptr; @@ -124,14 +123,15 @@ void inline PkeThreads_Shutdown_Inner(ThreadPool &tp) { } void PkeThreads_Init() { - Buckets_Init(ThreadPool_BucketContainer, MAX_THREADS_PER_BUCKET); + new (&thrdpl_mstr.bc) pk_bkt_arr_t<ThreadPool>; } ThreadPoolHandle PkeThreads_Init(uint8_t threadCount, uint8_t maxQueueCount, struct pk_membucket *bkt) { assert(threadCount > 0); - ThreadPoolHandle newHandle{Buckets_NewHandle(ThreadPool_BucketContainer)}; + ThreadPoolHandle newHandle{pk_bkt_arr_new_handle(&thrdpl_mstr.bc)}; - auto *tp = &ThreadPool_BucketContainer.buckets[newHandle.bucketIndex][newHandle.itemIndex]; + auto *tp = &thrdpl_mstr.bc[newHandle]; + new (tp) ThreadPool{}; tp->bkt = bkt; tp->isRunning = true; @@ -152,13 +152,13 @@ ThreadPoolHandle PkeThreads_Init(uint8_t threadCount, uint8_t maxQueueCount, str void PkeThreads_Reset(ThreadPoolHandle handle) { assert(handle != ThreadPoolHandle_MAX); - auto *tp = &ThreadPool_BucketContainer.buckets[handle.bucketIndex][handle.itemIndex]; + auto *tp = &thrdpl_mstr.bc[handle]; PkeThreads_Reset_Inner(*tp); } bool PkeThreads_Enqueue(ThreadPoolHandle handle, std::packaged_task<void()> *job) { assert(handle != ThreadPoolHandle_MAX); - auto *tp = &ThreadPool_BucketContainer.buckets[handle.bucketIndex][handle.itemIndex]; + auto *tp = &thrdpl_mstr.bc[handle]; if (tp->bkt != nullptr) { /* 2023-12-22 JCB * Note that if this becomes an issue we can change it. @@ -172,27 +172,27 @@ bool PkeThreads_Enqueue(ThreadPoolHandle handle, std::packaged_task<void()> *job } uint32_t PkeThreads_GetQueueCount (ThreadPoolHandle handle) { - auto &threadPool = ThreadPool_BucketContainer.buckets[handle.bucketIndex][handle.itemIndex]; + auto &threadPool = thrdpl_mstr.bc[handle]; return threadPool.jobQueue.next; } void PkeThreads_Pause(ThreadPoolHandle handle) { assert(handle != ThreadPoolHandle_MAX); - auto *tp = &ThreadPool_BucketContainer.buckets[handle.bucketIndex][handle.itemIndex]; + auto *tp = &thrdpl_mstr.bc[handle]; PkeThreads_Pause_Inner(*tp); } void PkeThreads_Resume(ThreadPoolHandle handle) { assert(handle != ThreadPoolHandle_MAX); - auto *tp = &ThreadPool_BucketContainer.buckets[handle.bucketIndex][handle.itemIndex]; + auto *tp = &thrdpl_mstr.bc[handle]; PkeThreads_Resume_Inner(*tp); } void PkeThreads_Shutdown(ThreadPoolHandle handle) { assert(handle != ThreadPoolHandle_MAX); - auto *tp = &ThreadPool_BucketContainer.buckets[handle.bucketIndex][handle.itemIndex]; + auto *tp = &thrdpl_mstr.bc[handle]; PkeThreads_Shutdown_Inner(*tp); PkeThreads_JoinAll_Inner(*tp); @@ -200,7 +200,7 @@ void PkeThreads_Shutdown(ThreadPoolHandle handle) { void PkeThreads_Teardown(ThreadPoolHandle handle) { assert(handle != ThreadPoolHandle_MAX); - auto *tp = &ThreadPool_BucketContainer.buckets[handle.bucketIndex][handle.itemIndex]; + auto *tp = &thrdpl_mstr.bc[handle]; PkeThreads_Shutdown_Inner(*tp); PkeThreads_JoinAll_Inner(*tp); @@ -213,5 +213,5 @@ void PkeThreads_Teardown(ThreadPoolHandle handle) { } void PkeThreads_Teardown() { - Buckets_Destroy(ThreadPool_BucketContainer); + pk_bkt_arr_teardown(&thrdpl_mstr.bc); } diff --git a/src/thread-pool.hpp b/src/thread-pool.hpp index 3afb99b..060b87a 100644 --- a/src/thread-pool.hpp +++ b/src/thread-pool.hpp @@ -6,9 +6,9 @@ #include <cstdint> #include <future> -struct ThreadPoolHandle : public pk_handle { }; +struct ThreadPoolHandle : public pk_bkt_arr_handle { }; -constexpr ThreadPoolHandle ThreadPoolHandle_MAX = ThreadPoolHandle{ pk_handle_MAX_constexpr }; +constexpr ThreadPoolHandle ThreadPoolHandle_MAX = ThreadPoolHandle{ pk_bkt_arr_handle_MAX_constexpr }; void PkeThreads_Init(); ThreadPoolHandle PkeThreads_Init (uint8_t threadCount, uint8_t maxQueueCount, struct pk_membucket *bkt = nullptr); |
