Commit Graph

8 Commits (b49c3a083b73f6a5762f353f618a2e1fe25cf690)

Author SHA1 Message Date
Brad Linden d74173861d
Attempt to fix intermittent failuresin threadsafeschedule_test (#1623) 2024-06-05 13:49:02 -07:00
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
Nat Goodspeed 6fb9a4640b DRTVWR-588: Try to make threadsafequeue timing more robust.
The test was coded to push (what's intended to be) the third entry with
timestamp (now + 200ms), then (what's intended to be) the second entry with
timestamp (now + 100ms).

The trouble is that it was re-querying "now" each time. On a slow CI host, the
clock might have advanced by more than 100ms between the first push and the
second -- meaning that the second push would actually have a _later_
timestamp, and thus, even with the queue sorting properly, fail the test's
order validation.

Capture the timestamp once, then add both time deltas to the same time point
to get the relative order right regardless of elapsed real time.
2023-10-31 12:03:03 -04: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 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 cf70766b45 SL-16024: Fix ThreadSafeSchedule::tryPopFor(), tryPopUntil().
ThreadSafeSchedule::tryPopUntil() (and therefore tryPopFor()) was simply
delegating to LLThreadSafeQueue::tryPopUntil(), with an adjusted timeout since
we want to wake up as soon as the head item, if any, becomes ready. But then
we have to loop back to retry the pop to actually deal with that head item.

In addition, ThreadSafeSchedule::popWithTime() was spinning rather than
properly blocking on a timed condition variable. Fixed.
2021-10-06 12:54:29 -04:00
Nat Goodspeed 955b967623 SL-16024: Add ThreadSafeSchedule, a timestamped LLThreadSafeQueue.
ThreadSafeSchedule orders its items by timestamp, which can be passed either
implicitly or explicitly. The timestamp specifies earliest delivery time: an
item cannot be popped until that time.

Add initial tests.

Tweak the LLThreadSafeQueue base class to support ThreadSafeSchedule:
introduce virtual canPop() method to report whether the current head item is
available to pop. The base class unconditionally says yes, ThreadSafeSchedule
says it depends on whether its timestamp is still in the future.

This replaces the protected pop_() overload accepting a predicate. Rather than
explicitly passing a predicate through a couple levels of function call, use
canPop() at the level it matters. Runtime behavior that varies depending on
an object's leaf class is what virtual functions were invented for.

Give pop_() a three-state enum return so pop() can distinguish between "closed
and empty" (throws exception) versus "closed, not yet drained because we're
not yet ready to pop the head item" (waits).

Also break out protected tryPopUntil_() method, the body logic of
tryPopUntil(). The public method locks the data structure, the protected
method requires that its caller has already done so.

Add chrono.h with a more full-featured LL::time_point_cast() function than the
one found in <chrono>, which only converts between time_point durations, not
between time_points based on different clocks.
2021-10-05 17:31:53 -04:00