From 2fe09084fa633d30cabe2595fd4c4b088971d47c Mon Sep 17 00:00:00 2001 From: Determinant Date: Wed, 12 Jun 2019 19:28:47 -0400 Subject: deduplicate the error callback --- include/salticidae/event.h | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'include/salticidae/event.h') diff --git a/include/salticidae/event.h b/include/salticidae/event.h index 5a315dd..eb0b382 100644 --- a/include/salticidae/event.h +++ b/include/salticidae/event.h @@ -467,14 +467,8 @@ class MPSCQueueEventDriven: public MPSCQueue { // since all enqueue operations are finalized, the dequeue should be able // to see those enqueued values in func() wait_sig.exchange(true, std::memory_order_acq_rel); - bool again; - try { - again = func(*this); - } catch (SalticidaeError &err) { + if (func(*this)) write(fd, &dummy, 8); - throw err; - } - if (again) write(fd, &dummy, 8); }); ev.add(FdEvent::READ); } @@ -558,6 +552,7 @@ class ThreadCall { const size_t burst_size; using queue_t = MPSCQueueEventDriven; queue_t q; + bool stopped; public: struct Result { @@ -607,7 +602,7 @@ class ThreadCall { } }; - ThreadCall(size_t burst_size): burst_size(burst_size) {} + ThreadCall(size_t burst_size): burst_size(burst_size), stopped(false) {} ThreadCall(const ThreadCall &) = delete; ThreadCall(ThreadCall &&) = delete; ThreadCall(EventContext ec, size_t burst_size = 128): ec(ec), burst_size(burst_size) { @@ -616,12 +611,7 @@ class ThreadCall { Handle *h; while (q.try_dequeue(h)) { - try { - h->exec(); - } catch (SalticidaeError &err) { - delete h; - throw err; - } + if (!stopped) h->exec(); delete h; if (++cnt == burst_size) return true; } @@ -652,6 +642,7 @@ class ThreadCall { } const EventContext &get_ec() const { return ec; } + void stop() { stopped = true; } }; } -- cgit v1.2.3