core: block instead of yield-spinning in the timer queue dispatch thread
This commit is contained in:
parent
3e842e62a6
commit
f8da2d0900
2 changed files with 14 additions and 8 deletions
|
|
@ -12,10 +12,10 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <forward_list>
|
#include <forward_list>
|
||||||
|
|
||||||
|
#include <disruptorplus/blocking_wait_strategy.hpp>
|
||||||
#include <disruptorplus/multi_threaded_claim_strategy.hpp>
|
#include <disruptorplus/multi_threaded_claim_strategy.hpp>
|
||||||
#include <disruptorplus/ring_buffer.hpp>
|
#include <disruptorplus/ring_buffer.hpp>
|
||||||
#include <disruptorplus/sequence_barrier.hpp>
|
#include <disruptorplus/sequence_barrier.hpp>
|
||||||
#include <disruptorplus/spin_wait_strategy.hpp>
|
|
||||||
|
|
||||||
#include <rex/assert.h>
|
#include <rex/assert.h>
|
||||||
#include <rex/thread.h>
|
#include <rex/thread.h>
|
||||||
|
|
@ -142,9 +142,15 @@ class TimerQueue {
|
||||||
// This ring buffer will be used to introduce timers queued by the public API
|
// This ring buffer will be used to introduce timers queued by the public API
|
||||||
static constexpr size_t kWaitCount = 512;
|
static constexpr size_t kWaitCount = 512;
|
||||||
dp::ring_buffer<std::shared_ptr<WaitItem>> buffer_;
|
dp::ring_buffer<std::shared_ptr<WaitItem>> buffer_;
|
||||||
dp::spin_wait_strategy wait_strategy_;
|
// Blocking (condition-variable) waits, not the spin strategy: the dispatch
|
||||||
dp::multi_threaded_claim_strategy<dp::spin_wait_strategy> claim_strategy_;
|
// thread waits with a deadline of the next timer due time, and with a spin
|
||||||
dp::sequence_barrier<dp::spin_wait_strategy> consumed_;
|
// strategy that wait yield-spins for the whole interval, permanently
|
||||||
|
// burning most of a core while any guest timer is pending. Guest timers
|
||||||
|
// need millisecond-class dispatch precision, which a condition variable
|
||||||
|
// delivers comfortably.
|
||||||
|
dp::blocking_wait_strategy wait_strategy_;
|
||||||
|
dp::multi_threaded_claim_strategy<dp::blocking_wait_strategy> claim_strategy_;
|
||||||
|
dp::sequence_barrier<dp::blocking_wait_strategy> consumed_;
|
||||||
|
|
||||||
// This is a _sorted_ (ascending due_) list of active timers managed by a
|
// This is a _sorted_ (ascending due_) list of active timers managed by a
|
||||||
// dedicated thread
|
// dedicated thread
|
||||||
|
|
|
||||||
|
|
@ -118,11 +118,11 @@ namespace disruptorplus
|
||||||
std::unique_lock<std::mutex> lock(m_mutex);
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
m_cv.wait_for(
|
m_cv.wait_for(
|
||||||
lock,
|
lock,
|
||||||
|
timeout,
|
||||||
[&]() -> bool {
|
[&]() -> bool {
|
||||||
result = minimum_sequence_after(sequence, count, sequences);
|
result = minimum_sequence_after(sequence, count, sequences);
|
||||||
return difference(result, sequence) >= 0;
|
return difference(result, sequence) >= 0;
|
||||||
},
|
});
|
||||||
timeout);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
@ -171,11 +171,11 @@ namespace disruptorplus
|
||||||
std::unique_lock<std::mutex> lock(m_mutex);
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
m_cv.wait_until(
|
m_cv.wait_until(
|
||||||
lock,
|
lock,
|
||||||
|
timeoutTime,
|
||||||
[&]() -> bool {
|
[&]() -> bool {
|
||||||
result = minimum_sequence_after(sequence, count, sequences);
|
result = minimum_sequence_after(sequence, count, sequences);
|
||||||
return difference(result, sequence) >= 0;
|
return difference(result, sequence) >= 0;
|
||||||
},
|
});
|
||||||
timeoutTime);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue