From a3937e7eef97cb0badcd65c390b9dd39d4cfd094 Mon Sep 17 00:00:00 2001 From: Jonathan Bradley Date: Fri, 22 Dec 2023 17:51:10 -0500 Subject: PkeThreads_Enqueue now takes a pointer to a task --- src/thread_pool.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/thread_pool.cpp') 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 job) { +bool PkeThreads_Enqueue(ThreadPoolHandle handle, std::packaged_task *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>(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) { -- cgit v1.2.3