Free if broadcast fails.

This commit is contained in:
Christoffer Lerno
2024-09-28 01:33:12 +02:00
parent 93f290d57c
commit 7ff645c423

View File

@@ -109,7 +109,7 @@ macro void! FixedThreadPool.@shutdown(&self, #stop) @private
*/
fn void! FixedThreadPool.push(&self, ThreadPoolFn func, args...)
{
self.mu.lock()!;
mu.in_lock()!;
defer self.mu.unlock()!!;
if (self.qindex == self.queue.len) return ThreadPoolResult.QUEUE_FULL?;
any[] data;
@@ -120,6 +120,10 @@ fn void! FixedThreadPool.push(&self, ThreadPoolFn func, args...)
}
self.queue[self.qindex] = { .func = func, .args = data };
self.qindex++;
defer catch
{
free_qitem(self.queue[--self.qindex]);
}
// Notify the threads that work is available.
self.notify.broadcast()!;
}