/
CoreThread.cpp
44 lines (36 loc) · 1.13 KB
/
CoreThread.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (C) 2012-2015 Leap Motion, Inc. All rights reserved.
#include "stdafx.h"
#include "CoreThread.h"
#include "BasicThreadStateBlock.h"
#include "CurrentContextPusher.h"
CoreThread::CoreThread(const char* pName):
BasicThread(pName)
{}
CoreThread::~CoreThread(void){}
void CoreThread::DoRunLoopCleanup(std::shared_ptr<CoreContext>&& ctxt, std::shared_ptr<CoreObject>&& refTracker) {
// Kill everything in the dispatch queue and also run it down
{
CurrentContextPusher pshr(ctxt);
Rundown();
}
// Handoff to base class:
BasicThread::DoRunLoopCleanup(std::move(ctxt), std::move(refTracker));
}
void CoreThread::Run() {
while(!ShouldStop())
WaitForEvent();
}
void CoreThread::OnStop(bool graceful) {
// Base class handling first:
BasicThread::OnStop(graceful);
if(graceful) {
// Pend a call which will invoke Abort once the dispatch queue is done:
DispatchQueue::Pend([this] {
this->Abort();
// Notify callers of our new state:
this->m_state->m_stateCondition.notify_all();
});
} else
// Abort the dispatch queue so anyone waiting will wake up
DispatchQueue::Abort();
}