summaryrefslogtreecommitdiff
path: root/indra/llcommon/tests/workqueue_test.cpp
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2021-10-25 15:55:49 -0400
committerNat Goodspeed <nat@lindenlab.com>2021-10-25 15:55:49 -0400
commite7b8c27741201528bf78f95c96ba820833923dab (patch)
tree5184649d45aa56f6a7fe2c85ec7d201eca957b3b /indra/llcommon/tests/workqueue_test.cpp
parentd2763897f22e3d7789f97fe68000662ecd4a3548 (diff)
SL-16220: Specialize WorkQueue for callable with void return.
Add a test exercising this feature.
Diffstat (limited to 'indra/llcommon/tests/workqueue_test.cpp')
-rw-r--r--indra/llcommon/tests/workqueue_test.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/indra/llcommon/tests/workqueue_test.cpp b/indra/llcommon/tests/workqueue_test.cpp
index d5405400fd..b69df49d33 100644
--- a/indra/llcommon/tests/workqueue_test.cpp
+++ b/indra/llcommon/tests/workqueue_test.cpp
@@ -138,7 +138,8 @@ namespace tut
[](){ return 17; },
// Note that a postTo() *callback* can safely bind a reference to
// a variable on the invoking thread, because the callback is run
- // on the invoking thread.
+ // on the invoking thread. (Of course the bound variable must
+ // survive until the callback is called.)
[&result](int i){ result = i; });
// this should post the callback to main
qptr->runOne();
@@ -156,4 +157,24 @@ namespace tut
main.runPending();
ensure_equals("failed to run string callback", alpha, "abc");
}
+
+ template<> template<>
+ void object::test<5>()
+ {
+ set_test_name("postTo with void return");
+ WorkQueue main("main");
+ auto qptr = WorkQueue::getInstance("queue");
+ std::string observe;
+ main.postTo(
+ qptr,
+ // The ONLY reason we can get away with binding a reference to
+ // 'observe' in our work callable is because we're directly
+ // calling qptr->runOne() on this same thread. It would be a
+ // mistake to do that if some other thread were servicing 'queue'.
+ [&observe](){ observe = "queue"; },
+ [&observe](){ observe.append(";main"); });
+ qptr->runOne();
+ main.runOne();
+ ensure_equals("failed to run both lambdas", observe, "queue;main");
+ }
} // namespace tut