refactor(win32): Rename Windows thread finding methods for consistency
This commit is contained in:
parent
b0985a2740
commit
eebe5fd55f
2 changed files with 20 additions and 21 deletions
|
|
@ -108,7 +108,7 @@ ArchMultithreadWindows::~ArchMultithreadWindows()
|
||||||
void ArchMultithreadWindows::setNetworkDataForCurrentThread(void *data)
|
void ArchMultithreadWindows::setNetworkDataForCurrentThread(void *data)
|
||||||
{
|
{
|
||||||
std::scoped_lock lock{m_threadMutex};
|
std::scoped_lock lock{m_threadMutex};
|
||||||
ArchThreadImpl *thread = findNoRef(GetCurrentThreadId());
|
ArchThreadImpl *thread = findNoRefOrInsert(GetCurrentThreadId());
|
||||||
thread->m_networkData = data;
|
thread->m_networkData = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -121,7 +121,7 @@ void *ArchMultithreadWindows::getNetworkDataForThread(ArchThread thread)
|
||||||
HANDLE ArchMultithreadWindows::getCancelEventForCurrentThread()
|
HANDLE ArchMultithreadWindows::getCancelEventForCurrentThread()
|
||||||
{
|
{
|
||||||
std::scoped_lock lock{m_threadMutex};
|
std::scoped_lock lock{m_threadMutex};
|
||||||
ArchThreadImpl *thread = findNoRef(GetCurrentThreadId());
|
ArchThreadImpl *thread = findNoRefOrInsert(GetCurrentThreadId());
|
||||||
return thread->m_cancel;
|
return thread->m_cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -305,7 +305,7 @@ void ArchMultithreadWindows::closeThread(ArchThread thread)
|
||||||
// remove thread from list
|
// remove thread from list
|
||||||
{
|
{
|
||||||
std::scoped_lock lock{m_threadMutex};
|
std::scoped_lock lock{m_threadMutex};
|
||||||
assert(findNoRefOrCreate(thread->m_id) == thread);
|
assert(findNoRef(thread->m_id) == thread);
|
||||||
erase(thread);
|
erase(thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -390,7 +390,7 @@ void ArchMultithreadWindows::testCancelThread()
|
||||||
{
|
{
|
||||||
// find current thread
|
// find current thread
|
||||||
std::scoped_lock lock{m_threadMutex};
|
std::scoped_lock lock{m_threadMutex};
|
||||||
ArchThreadImpl *thread = findNoRef(GetCurrentThreadId());
|
ArchThreadImpl *thread = findNoRefOrInsert(GetCurrentThreadId());
|
||||||
|
|
||||||
// test cancel on thread
|
// test cancel on thread
|
||||||
testCancelThreadImpl(thread);
|
testCancelThreadImpl(thread);
|
||||||
|
|
@ -404,7 +404,7 @@ bool ArchMultithreadWindows::wait(ArchThread target, double timeout)
|
||||||
{
|
{
|
||||||
std::scoped_lock lock{m_threadMutex};
|
std::scoped_lock lock{m_threadMutex};
|
||||||
// find current thread
|
// find current thread
|
||||||
self = findNoRef(GetCurrentThreadId());
|
self = findNoRefOrInsert(GetCurrentThreadId());
|
||||||
// ignore wait if trying to wait on ourself
|
// ignore wait if trying to wait on ourself
|
||||||
if (target == self) {
|
if (target == self) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -497,7 +497,7 @@ void ArchMultithreadWindows::raiseSignal(ThreadSignal signal)
|
||||||
|
|
||||||
ArchThreadImpl *ArchMultithreadWindows::find(DWORD id)
|
ArchThreadImpl *ArchMultithreadWindows::find(DWORD id)
|
||||||
{
|
{
|
||||||
ArchThreadImpl *impl = findNoRef(id);
|
ArchThreadImpl *impl = findNoRefOrInsert(id);
|
||||||
if (impl != nullptr) {
|
if (impl != nullptr) {
|
||||||
refThread(impl);
|
refThread(impl);
|
||||||
}
|
}
|
||||||
|
|
@ -506,7 +506,17 @@ ArchThreadImpl *ArchMultithreadWindows::find(DWORD id)
|
||||||
|
|
||||||
ArchThreadImpl *ArchMultithreadWindows::findNoRef(DWORD id)
|
ArchThreadImpl *ArchMultithreadWindows::findNoRef(DWORD id)
|
||||||
{
|
{
|
||||||
ArchThreadImpl *impl = findNoRefOrCreate(id);
|
for (ThreadList::const_iterator index = m_threadList.begin(); index != m_threadList.end(); ++index) {
|
||||||
|
if ((*index)->m_id == id) {
|
||||||
|
return *index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
ArchThreadImpl *ArchMultithreadWindows::findNoRefOrInsert(DWORD id)
|
||||||
|
{
|
||||||
|
ArchThreadImpl *impl = findNoRef(id);
|
||||||
if (impl == nullptr) {
|
if (impl == nullptr) {
|
||||||
// create thread for calling thread which isn't in our list and
|
// create thread for calling thread which isn't in our list and
|
||||||
// add it to the list. this won't normally happen but it can if
|
// add it to the list. this won't normally happen but it can if
|
||||||
|
|
@ -520,23 +530,12 @@ ArchThreadImpl *ArchMultithreadWindows::findNoRef(DWORD id)
|
||||||
return impl;
|
return impl;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchThreadImpl *ArchMultithreadWindows::findNoRefOrCreate(DWORD id)
|
|
||||||
{
|
|
||||||
// linear search
|
|
||||||
for (ThreadList::const_iterator index = m_threadList.begin(); index != m_threadList.end(); ++index) {
|
|
||||||
if ((*index)->m_id == id) {
|
|
||||||
return *index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ArchMultithreadWindows::insert(ArchThreadImpl *thread)
|
void ArchMultithreadWindows::insert(ArchThreadImpl *thread)
|
||||||
{
|
{
|
||||||
assert(thread != nullptr);
|
assert(thread != nullptr);
|
||||||
|
|
||||||
// thread shouldn't already be on the list
|
// thread shouldn't already be on the list
|
||||||
assert(findNoRefOrCreate(thread->m_id) == nullptr);
|
assert(findNoRef(thread->m_id) == nullptr);
|
||||||
|
|
||||||
// append to list
|
// append to list
|
||||||
m_threadList.push_back(thread);
|
m_threadList.push_back(thread);
|
||||||
|
|
@ -555,7 +554,7 @@ void ArchMultithreadWindows::erase(ArchThreadImpl *thread)
|
||||||
void ArchMultithreadWindows::refThread(ArchThreadImpl *thread)
|
void ArchMultithreadWindows::refThread(ArchThreadImpl *thread)
|
||||||
{
|
{
|
||||||
assert(thread != nullptr);
|
assert(thread != nullptr);
|
||||||
assert(findNoRefOrCreate(thread->m_id) != nullptr);
|
assert(findNoRef(thread->m_id) != nullptr);
|
||||||
++thread->m_refCount;
|
++thread->m_refCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ public:
|
||||||
private:
|
private:
|
||||||
ArchThreadImpl *find(DWORD id);
|
ArchThreadImpl *find(DWORD id);
|
||||||
ArchThreadImpl *findNoRef(DWORD id);
|
ArchThreadImpl *findNoRef(DWORD id);
|
||||||
ArchThreadImpl *findNoRefOrCreate(DWORD id);
|
ArchThreadImpl *findNoRefOrInsert(DWORD id);
|
||||||
void insert(ArchThreadImpl *thread);
|
void insert(ArchThreadImpl *thread);
|
||||||
void erase(ArchThreadImpl *thread);
|
void erase(ArchThreadImpl *thread);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue