|
|
|
@ -110,8 +110,8 @@ void CScheduler::scheduleEvery(CScheduler::Function f, std::chrono::milliseconds
|
|
|
|
|
scheduleFromNow([=] { Repeat(*this, f, delta); }, delta);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t CScheduler::getQueueInfo(std::chrono::system_clock::time_point &first,
|
|
|
|
|
std::chrono::system_clock::time_point &last) const
|
|
|
|
|
size_t CScheduler::getQueueInfo(std::chrono::system_clock::time_point& first,
|
|
|
|
|
std::chrono::system_clock::time_point& last) const
|
|
|
|
|
{
|
|
|
|
|
LOCK(newTaskMutex);
|
|
|
|
|
size_t result = taskQueue.size();
|
|
|
|
@ -122,13 +122,15 @@ size_t CScheduler::getQueueInfo(std::chrono::system_clock::time_point &first,
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CScheduler::AreThreadsServicingQueue() const {
|
|
|
|
|
bool CScheduler::AreThreadsServicingQueue() const
|
|
|
|
|
{
|
|
|
|
|
LOCK(newTaskMutex);
|
|
|
|
|
return nThreadsServicingQueue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SingleThreadedSchedulerClient::MaybeScheduleProcessQueue() {
|
|
|
|
|
void SingleThreadedSchedulerClient::MaybeScheduleProcessQueue()
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
LOCK(m_cs_callbacks_pending);
|
|
|
|
|
// Try to avoid scheduling too many copies here, but if we
|
|
|
|
@ -140,8 +142,9 @@ void SingleThreadedSchedulerClient::MaybeScheduleProcessQueue() {
|
|
|
|
|
m_pscheduler->schedule(std::bind(&SingleThreadedSchedulerClient::ProcessQueue, this), std::chrono::system_clock::now());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SingleThreadedSchedulerClient::ProcessQueue() {
|
|
|
|
|
std::function<void ()> callback;
|
|
|
|
|
void SingleThreadedSchedulerClient::ProcessQueue()
|
|
|
|
|
{
|
|
|
|
|
std::function<void()> callback;
|
|
|
|
|
{
|
|
|
|
|
LOCK(m_cs_callbacks_pending);
|
|
|
|
|
if (m_are_callbacks_running) return;
|
|
|
|
@ -157,7 +160,8 @@ void SingleThreadedSchedulerClient::ProcessQueue() {
|
|
|
|
|
struct RAIICallbacksRunning {
|
|
|
|
|
SingleThreadedSchedulerClient* instance;
|
|
|
|
|
explicit RAIICallbacksRunning(SingleThreadedSchedulerClient* _instance) : instance(_instance) {}
|
|
|
|
|
~RAIICallbacksRunning() {
|
|
|
|
|
~RAIICallbacksRunning()
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
LOCK(instance->m_cs_callbacks_pending);
|
|
|
|
|
instance->m_are_callbacks_running = false;
|
|
|
|
@ -169,7 +173,8 @@ void SingleThreadedSchedulerClient::ProcessQueue() {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SingleThreadedSchedulerClient::AddToProcessQueue(std::function<void ()> func) {
|
|
|
|
|
void SingleThreadedSchedulerClient::AddToProcessQueue(std::function<void()> func)
|
|
|
|
|
{
|
|
|
|
|
assert(m_pscheduler);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
@ -179,7 +184,8 @@ void SingleThreadedSchedulerClient::AddToProcessQueue(std::function<void ()> fun
|
|
|
|
|
MaybeScheduleProcessQueue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SingleThreadedSchedulerClient::EmptyQueue() {
|
|
|
|
|
void SingleThreadedSchedulerClient::EmptyQueue()
|
|
|
|
|
{
|
|
|
|
|
assert(!m_pscheduler->AreThreadsServicingQueue());
|
|
|
|
|
bool should_continue = true;
|
|
|
|
|
while (should_continue) {
|
|
|
|
@ -189,7 +195,8 @@ void SingleThreadedSchedulerClient::EmptyQueue() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t SingleThreadedSchedulerClient::CallbacksPending() {
|
|
|
|
|
size_t SingleThreadedSchedulerClient::CallbacksPending()
|
|
|
|
|
{
|
|
|
|
|
LOCK(m_cs_callbacks_pending);
|
|
|
|
|
return m_callbacks_pending.size();
|
|
|
|
|
}
|
|
|
|
|