diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2023-12-22 17:51:10 -0500 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2023-12-23 11:42:23 -0500 |
| commit | a3937e7eef97cb0badcd65c390b9dd39d4cfd094 (patch) | |
| tree | ca793f7630e0130211ed480c915968d743e7b506 /src/thread_pool.cpp | |
| parent | fa7fc343a0e444da72938fad58d219cf52228976 (diff) | |
PkeThreads_Enqueue now takes a pointer to a task
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) { |
