diff options
Diffstat (limited to 'src/thread_pool.cpp')
| -rw-r--r-- | src/thread_pool.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/thread_pool.cpp b/src/thread_pool.cpp index 3af2273..c3c8743 100644 --- a/src/thread_pool.cpp +++ b/src/thread_pool.cpp @@ -143,14 +143,24 @@ void PkeThreads_Reset(ThreadPoolHandle handle) { PkeThreads_Reset_Inner(*tp); } -bool PkeThreads_Enqueue(ThreadPoolHandle handle, std::packaged_task<void()> job) { +bool PkeThreads_Enqueue(ThreadPoolHandle handle, std::packaged_task<void()> *job) { assert(handle != ThreadPoolHandle_MAX); auto *tp = &ThreadPool_BucketContainer.buckets[handle.bucketIndex].threadPools[handle.itemIndex]; + if (tp->bkt != nullptr) { + /* 2023-12-22 JCB + * Note that if this becomes an issue we can change it. + * Technically speaking, if we call the right Pke_Delete + * we don't even need to worry about passing the MemBucket + */ + assert(Pke_InBucket(job, tp->bkt) == true && "cannot enqueue packaged task from a non-matching MemBucket"); + } - auto jobPtr = Pke_New<std::packaged_task<void()>>(tp->bkt); - *jobPtr = std::move(job); + return PkeThreads_Enqueue_Inner(*tp, job); +} - return PkeThreads_Enqueue_Inner(*tp, jobPtr); +int64_t PkeThreads_GetQueueCount (ThreadPoolHandle handle) { + auto &threadPool = ThreadPool_BucketContainer.buckets[handle.bucketIndex].threadPools[handle.itemIndex]; + return threadPool.jobQueue->Count(); } void PkeThreads_Pause(ThreadPoolHandle handle) { |
