summaryrefslogtreecommitdiff
path: root/indra/llcommon/workqueue.h
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon/workqueue.h')
-rw-r--r--indra/llcommon/workqueue.h69
1 files changed, 24 insertions, 45 deletions
diff --git a/indra/llcommon/workqueue.h b/indra/llcommon/workqueue.h
index 5461ce6c23..ec0700a718 100644
--- a/indra/llcommon/workqueue.h
+++ b/indra/llcommon/workqueue.h
@@ -83,13 +83,10 @@ namespace LL
/*---------------------- fire and forget API -----------------------*/
- /// fire-and-forget
- virtual void post(const Work&) = 0;
-
/**
* post work, unless the queue is closed before we can post
*/
- virtual bool postIfOpen(const Work&) = 0;
+ virtual bool post(const Work&) = 0;
/**
* post work, unless the queue is full
@@ -247,13 +244,10 @@ namespace LL
/*---------------------- fire and forget API -----------------------*/
- /// fire-and-forget
- void post(const Work&) override;
-
/**
* post work, unless the queue is closed before we can post
*/
- bool postIfOpen(const Work&) override;
+ bool post(const Work&) override;
/**
* post work, unless the queue is full
@@ -320,22 +314,16 @@ namespace LL
/*---------------------- fire and forget API -----------------------*/
- /// fire-and-forget
- void post(const Work& callable) override;
-
- /// fire-and-forget, but at a particular (future?) time
- void post(const Work& callable, const TimePoint& time);
-
/**
* post work, unless the queue is closed before we can post
*/
- bool postIfOpen(const Work& callable) override;
+ bool post(const Work& callable) override;
/**
* post work for a particular time, unless the queue is closed before
* we can post
*/
- bool postIfOpen(const Work& callable, const TimePoint& time);
+ bool post(const Work& callable, const TimePoint& time);
/**
* post work, unless the queue is full
@@ -356,7 +344,7 @@ namespace LL
* an LLCond variant, e.g. LLOneShotCond or LLBoolCond.
*/
template <typename Rep, typename Period, typename CALLABLE>
- void postEvery(const std::chrono::duration<Rep, Period>& interval,
+ bool postEvery(const std::chrono::duration<Rep, Period>& interval,
CALLABLE&& callable);
private:
@@ -417,15 +405,10 @@ namespace LL
// move-only callable; but naturally this statement must be
// the last time we reference this instance, which may become
// moved-from.
- try
- {
- auto target{ std::dynamic_pointer_cast<WorkSchedule>(mTarget.lock()) };
- target->post(std::move(*this), mStart);
- }
- catch (const Closed&)
- {
- // Once this queue is closed, oh well, just stop
- }
+ auto target{ std::dynamic_pointer_cast<WorkSchedule>(mTarget.lock()) };
+ // Discard bool return: once this queue is closed, oh well,
+ // just stop
+ target->post(std::move(*this), mStart);
}
}
@@ -437,7 +420,7 @@ namespace LL
};
template <typename Rep, typename Period, typename CALLABLE>
- void WorkSchedule::postEvery(const std::chrono::duration<Rep, Period>& interval,
+ bool WorkSchedule::postEvery(const std::chrono::duration<Rep, Period>& interval,
CALLABLE&& callable)
{
if (interval.count() <= 0)
@@ -454,7 +437,7 @@ namespace LL
// Instantiate and post a suitable BackJack, binding a weak_ptr to
// self, the current time, the desired interval and the desired
// callable.
- post(
+ return post(
BackJack<Rep, Period, CALLABLE>(
getWeak(), TimePoint::clock::now(), interval, std::move(callable)));
}
@@ -516,7 +499,7 @@ namespace LL
// Here we believe target WorkQueue still exists. Post to it a
// lambda that packages our callable, our callback and a weak_ptr
// to this originating WorkQueue.
- tptr->post(
+ return tptr->post(
[reply = super::getWeak(),
callable = std::move(callable),
callback = std::move(callback)]
@@ -547,9 +530,6 @@ namespace LL
},
// if caller passed a TimePoint, pass it along to post()
std::forward<ARGS>(args)...);
-
- // looks like we were able to post()
- return true;
}
template <typename... ARGS>
@@ -560,18 +540,9 @@ namespace LL
auto tptr = target.lock();
if (tptr)
{
- try
- {
- tptr->post(std::forward<ARGS>(args)...);
- // we were able to post()
- return true;
- }
- catch (const Closed&)
- {
- // target WorkQueue still exists, but is Closed
- }
+ return tptr->post(std::forward<ARGS>(args)...);
}
- // either target no longer exists, or its WorkQueue is Closed
+ // target no longer exists
return false;
}
@@ -583,7 +554,7 @@ namespace LL
auto operator()(WorkQueueBase* self, CALLABLE&& callable, ARGS&&... args)
{
LLCoros::Promise<RETURNTYPE> promise;
- self->post(
+ bool posted = self->post(
// We dare to bind a reference to Promise because it's
// specifically designed for cross-thread communication.
[&promise, callable = std::move(callable)]()
@@ -600,6 +571,10 @@ namespace LL
},
// if caller passed a TimePoint, pass it to post()
std::forward<ARGS>(args)...);
+ if (! posted)
+ {
+ LLTHROW(WorkQueueBase::Closed());
+ }
auto future{ LLCoros::getFuture(promise) };
// now, on the calling thread, wait for that result
LLCoros::TempStatus st("waiting for WorkQueue::waitForResult()");
@@ -615,7 +590,7 @@ namespace LL
void operator()(WorkQueueBase* self, CALLABLE&& callable, ARGS&&... args)
{
LLCoros::Promise<void> promise;
- self->post(
+ bool posted = self->post(
// &promise is designed for cross-thread access
[&promise, callable = std::move(callable)]()
mutable {
@@ -631,6 +606,10 @@ namespace LL
},
// if caller passed a TimePoint, pass it to post()
std::forward<ARGS>(args)...);
+ if (! posted)
+ {
+ LLTHROW(WorkQueueBase::Closed());
+ }
auto future{ LLCoros::getFuture(promise) };
// block until set_value()
LLCoros::TempStatus st("waiting for void WorkQueue::waitForResult()");