Repository navigation
Prioritize thread pause()/resume() calls (Take #2) - #11005
Conversation
| std::lock_guard<std::mutex> lock(mutex); | ||
| fn(); | ||
| if (priority == Priority::High) { | ||
| // We're always placing high priority tasks at the front. This means it's not really a |
There was a problem hiding this comment.
As discussed in chat, I think it's best to have one set of queue order semantics. For now, it hardly matters as it is only pause/resume, but this might lead to misunderstandings further down the line.
There was a problem hiding this comment.
Addressed this by having two separate queues and checking the high priority one first. I chose this implementation over a priority_queue since it removes the need to sort items upon insertion.
| std::lock_guard<std::mutex> lock(mutex); | ||
| fn(); | ||
| queue.push(std::move(task)); | ||
| wake(); |
There was a problem hiding this comment.
We could release the lock before calling wake here
afda6c2 to
e993a89
Compare
There was a problem hiding this comment.
nit: Update comment to reflect multiple queues
e993a89 to
9bd5e43
Compare
tmpsantos
left a comment
There was a problem hiding this comment.
LGTM. What about adding an unit test for the priority queue?
|
@tmpsantos I wanted to do this too, but I couldn't come up with a way to do this without a timing-dependent test which is prone to spurious failures. Do you have any ideas? |
What about something like this:
|
RunLoop already has a queue, and has the ability to schedule weak mailboxes, so we can remove the duplicate code.
9bd5e43 to
be41e35
Compare
|
Since what we want to test is the mapbox-gl-native/test/util/run_loop.test.cpp Lines 54 to 66 in 26a00f6 |
Alternative implementation of #10174 that continues to use the existing model, and just prioritizes
pause()calls by adding them to the front of the queue to address @jfirebaugh's concerns in #10174 (review)Implements part 1 of #10031