Commit Graph

11 Commits (5ffcd3dc88892a651fe9a95974280efb85e18a8b)

Author SHA1 Message Date
Andrey Lihatskiy 1b68f71348 #824 Process source files in bulk: replace tabs with spaces, convert CRLF to LF, and trim trailing whitespaces as needed 2024-04-29 07:56:09 +03:00
Brad Linden 673b3309dd Merge remote-tracking branch 'origin/main' into DRTVWR-559 2023-10-25 16:12:13 -07:00
Nat Goodspeed 045342ba29 SL-18837: Bump the granularity of WorkQueue timing tests.
On a low-powered GitHub Mac runner, the system doesn't wake up as soon as it
should, and we get spurious "too late" errors. Try a bigger time increment.
2023-06-05 11:28:41 -04:00
Nat Goodspeed fc424a0db9 SL-18809: Add WorkSchedule; remove timestamps from WorkQueue.
For work queues that don't need timestamped tasks, eliminate the overhead of a
priority queue ordered by timestamp. Timestamped task support moves to
WorkSchedule. WorkQueue is a simpler queue that just waits for work.

Both WorkQueue and WorkSchedule can be accessed via new WorkQueueBase API. Of
course the WorkQueueBase API doesn't deal with timestamps, but a WorkSchedule
can be accessed directly to post timestamped tasks and then handled normally
(e.g. by ThreadPool) to run them.

Most ThreadPool functionality migrates to new ThreadPoolBase class, with
template subclass ThreadPoolUsing<WorkQueue> or ThreadPoolUsing<WorkSchedule>
depending on need. ThreadPool is now an alias for ThreadPoolUsing<WorkQueue>.
Importantly, ThreadPoolUsing::getQueue() delivers a reference to the specific
queue subclass type, so you can post timestamped tasks on a queue retrieved
from ThreadPoolUsing<WorkSchedule>::getQueue().

Since ThreadPool is no longer a simple class but an alias for a particular
template specialization, introduce threadpool_fwd.h to forward-declare it.

Recast workqueue_test.cpp to exercise WorkSchedule, since some of the tests
are time-based. A future todo would be to exercise each applicable test with
both WorkQueue and WorkSchedule.
2022-12-09 13:21:45 -05:00
Nat Goodspeed 04ebc11a2d SL-16094: Fix WorkQueue test for correct behavior of runFor().
Turns out that one of our WorkQueue integration tests was relying on the
incorrect runFor() behavior that we just fixed, so the test broke. Now that
runFor() doesn't wait around for work to be posted, use an explicit wait loop
instead.

To support this, add LLCond::get(functor), where functor must accept a const
reference to the stored data. This new get() returns whatever the functor
returns, allowing a caller to peek at the stored data.

Also use universal references for all remaining LLCond functor arguments.
2021-11-24 12:56:48 -05:00
Nat Goodspeed 0b066539fe DRTVWR-546, SL-16220, SL-16094: Undo previous glthread branch revert.
Reverting a merge is sticky: it tells git you never want to see that branch
again. Merging the DRTVWR-546 branch, which contained the revert, into the
glthread branch undid much of the development work on that branch. To restore
it we must revert the revert.

This reverts commit 029b41c041.
2021-11-24 10:47:54 -05:00
Dave Houlton 029b41c041 Revert "SL-16220: Merge branch 'origin/DRTVWR-546' into glthread"
This reverts commit 5188a26a85, reversing
changes made to 819088563e.
2021-11-15 09:25:35 -07:00
Nat Goodspeed 8b16ecb9cf SL-16220: Add tests for WorkQueue::waitForResult(), void & non-void. 2021-10-27 15:31:54 -04:00
Nat Goodspeed e7b8c27741 SL-16220: Specialize WorkQueue for callable with void return.
Add a test exercising this feature.
2021-10-25 15:55:49 -04:00
Nat Goodspeed c585ddb75e SL-16024: Defend against two threads making "anonymous" WorkQueues.
Also make workqueue_test.cpp more robust.
2021-10-07 16:45:15 -04:00
Nat Goodspeed 623ac79120 SL-16024: Add LL::WorkQueue for passing work items between threads.
A typical WorkQueue has a string name, which can be used to find it to post
work to it. "Work" is a nullary callable.

WorkQueue is a multi-producer, multi-consumer thread-safe queue: multiple
threads can service the WorkQueue, multiple threads can post work to it.

Work can be scheduled in the future by submitting with a timestamp. In
addition, a given work item can be scheduled to run on a recurring basis.

A requesting thread servicing a WorkQueue of its own, such as the viewer's
main thread, can submit work to another WorkQueue along with a callback to be
passed the result (of arbitrary type) of the first work item. The callback is
posted to the originating WorkQueue, permitting safe data exchange between
participating threads.

Methods are provided for different kinds of servicing threads. runUntilClose()
is useful for a simple worker thread. runFor(duration) devotes no more than a
specified time slice to that WorkQueue, e.g. for use by the main thread.
2021-10-07 15:32:51 -04:00