clang-format scheduler

Can easily be reviewed with the git options
--ignore-all-space --word-diff-regex=. -U0
This commit is contained in:
MarcoFalke 2020-05-28 09:16:32 -04:00
parent fa3d41b5ab
commit fa8337fcdb
No known key found for this signature in database
GPG key ID: CE2B75697E69A548
2 changed files with 25 additions and 17 deletions

View file

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

View file

@ -84,8 +84,8 @@ public:
* Returns number of tasks waiting to be serviced, * Returns number of tasks waiting to be serviced,
* and first and last task times * and first and last task times
*/ */
size_t getQueueInfo(std::chrono::system_clock::time_point &first, size_t getQueueInfo(std::chrono::system_clock::time_point& first,
std::chrono::system_clock::time_point &last) const; std::chrono::system_clock::time_point& last) const;
/** Returns true if there are threads actively running in serviceQueue() */ /** Returns true if there are threads actively running in serviceQueue() */
bool AreThreadsServicingQueue() const; bool AreThreadsServicingQueue() const;
@ -110,19 +110,20 @@ private:
* B() will be able to observe all of the effects of callback A() which executed * B() will be able to observe all of the effects of callback A() which executed
* before it. * before it.
*/ */
class SingleThreadedSchedulerClient { class SingleThreadedSchedulerClient
{
private: private:
CScheduler *m_pscheduler; CScheduler* m_pscheduler;
RecursiveMutex m_cs_callbacks_pending; RecursiveMutex m_cs_callbacks_pending;
std::list<std::function<void ()>> m_callbacks_pending GUARDED_BY(m_cs_callbacks_pending); std::list<std::function<void()>> m_callbacks_pending GUARDED_BY(m_cs_callbacks_pending);
bool m_are_callbacks_running GUARDED_BY(m_cs_callbacks_pending) = false; bool m_are_callbacks_running GUARDED_BY(m_cs_callbacks_pending) = false;
void MaybeScheduleProcessQueue(); void MaybeScheduleProcessQueue();
void ProcessQueue(); void ProcessQueue();
public: public:
explicit SingleThreadedSchedulerClient(CScheduler *pschedulerIn) : m_pscheduler(pschedulerIn) {} explicit SingleThreadedSchedulerClient(CScheduler* pschedulerIn) : m_pscheduler(pschedulerIn) {}
/** /**
* Add a callback to be executed. Callbacks are executed serially * Add a callback to be executed. Callbacks are executed serially
@ -130,7 +131,7 @@ public:
* Practically, this means that callbacks can behave as if they are executed * Practically, this means that callbacks can behave as if they are executed
* in order by a single thread. * in order by a single thread.
*/ */
void AddToProcessQueue(std::function<void ()> func); void AddToProcessQueue(std::function<void()> func);
/** /**
* Processes all remaining queue members on the calling thread, blocking until queue is empty * Processes all remaining queue members on the calling thread, blocking until queue is empty