mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Merge #4713
4713: Give the condition waits proper conditions r=def- a=Jupeyy <!-- What is the motivation for the changes of this pull request --> ## Checklist - [ ] Tested the change ingame - [ ] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test if it works standalone, system.c especially - [ ] Considered possible null pointers and out of bounds array indexing - [ ] Changed no physics that affect existing maps - [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: Jupeyy <jupjopjap@gmail.com>
This commit is contained in:
commit
40380d088f
|
@ -61,6 +61,7 @@ void CGraphicsBackend_Threaded::ThreadFunc(void *pUser)
|
||||||
auto *pSelf = (CGraphicsBackend_Threaded *)pUser;
|
auto *pSelf = (CGraphicsBackend_Threaded *)pUser;
|
||||||
std::unique_lock<std::mutex> Lock(pSelf->m_BufferSwapMutex);
|
std::unique_lock<std::mutex> Lock(pSelf->m_BufferSwapMutex);
|
||||||
// notify, that the thread started
|
// notify, that the thread started
|
||||||
|
pSelf->m_Started = true;
|
||||||
pSelf->m_BufferDoneCond.notify_all();
|
pSelf->m_BufferDoneCond.notify_all();
|
||||||
while(!pSelf->m_Shutdown)
|
while(!pSelf->m_Shutdown)
|
||||||
{
|
{
|
||||||
|
@ -75,11 +76,12 @@ void CGraphicsBackend_Threaded::ThreadFunc(void *pUser)
|
||||||
pSelf->m_pBuffer = nullptr;
|
pSelf->m_pBuffer = nullptr;
|
||||||
pSelf->m_BufferInProcess.store(false, std::memory_order_relaxed);
|
pSelf->m_BufferInProcess.store(false, std::memory_order_relaxed);
|
||||||
pSelf->m_BufferDoneCond.notify_all();
|
pSelf->m_BufferDoneCond.notify_all();
|
||||||
}
|
|
||||||
#if defined(CONF_VIDEORECORDER)
|
#if defined(CONF_VIDEORECORDER)
|
||||||
if(IVideo::Current())
|
if(IVideo::Current())
|
||||||
IVideo::Current()->NextVideoFrameThread();
|
IVideo::Current()->NextVideoFrameThread();
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +99,7 @@ void CGraphicsBackend_Threaded::StartProcessor(ICommandProcessor *pProcessor)
|
||||||
std::unique_lock<std::mutex> Lock(m_BufferSwapMutex);
|
std::unique_lock<std::mutex> Lock(m_BufferSwapMutex);
|
||||||
m_Thread = thread_init(ThreadFunc, this, "Graphics thread");
|
m_Thread = thread_init(ThreadFunc, this, "Graphics thread");
|
||||||
// wait for the thread to start
|
// wait for the thread to start
|
||||||
m_BufferDoneCond.wait(Lock);
|
m_BufferDoneCond.wait(Lock, [this]() -> bool { return m_Started; });
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGraphicsBackend_Threaded::StopProcessor()
|
void CGraphicsBackend_Threaded::StopProcessor()
|
||||||
|
@ -127,7 +129,7 @@ bool CGraphicsBackend_Threaded::IsIdle() const
|
||||||
void CGraphicsBackend_Threaded::WaitForIdle()
|
void CGraphicsBackend_Threaded::WaitForIdle()
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> Lock(m_BufferSwapMutex);
|
std::unique_lock<std::mutex> Lock(m_BufferSwapMutex);
|
||||||
if(m_pBuffer != nullptr)
|
while(m_pBuffer != nullptr)
|
||||||
m_BufferDoneCond.wait(Lock);
|
m_BufferDoneCond.wait(Lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,7 @@ private:
|
||||||
std::condition_variable m_BufferDoneCond;
|
std::condition_variable m_BufferDoneCond;
|
||||||
CCommandBuffer *m_pBuffer;
|
CCommandBuffer *m_pBuffer;
|
||||||
std::atomic_bool m_Shutdown;
|
std::atomic_bool m_Shutdown;
|
||||||
|
bool m_Started = false;
|
||||||
std::atomic_bool m_BufferInProcess;
|
std::atomic_bool m_BufferInProcess;
|
||||||
void *m_Thread;
|
void *m_Thread;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue