mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Merge #4627
4627: Try to improve macos perf r=Jupeyy a=def- `@Jupeyy` didn't work, I thought maybe it's because it uses the E cores, not P cores. ## 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: Dennis Felsing <dennis@felsin9.de>
This commit is contained in:
commit
314b6d6da3
|
@ -22,5 +22,7 @@
|
|||
<true/>
|
||||
<key>NSPrefersDisplaySafeAreaCompatibilityMode</key>
|
||||
<true/>
|
||||
<key>NSQualityOfService</key>
|
||||
<string>NSQualityOfServiceUserInteractive</string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
|
@ -772,7 +772,12 @@ void *thread_init(void (*threadfunc)(void *), void *u, const char *name)
|
|||
#if defined(CONF_FAMILY_UNIX)
|
||||
{
|
||||
pthread_t id;
|
||||
int result = pthread_create(&id, NULL, thread_run, data);
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
#if defined(CONF_PLATFORM_MACOS)
|
||||
pthread_attr_set_qos_class_np(&attr, QOS_CLASS_USER_INTERACTIVE, 0);
|
||||
#endif
|
||||
int result = pthread_create(&id, &attr, thread_run, data);
|
||||
if(result != 0)
|
||||
{
|
||||
dbg_msg("thread", "creating %s thread failed: %d", name, result);
|
||||
|
|
|
@ -56,24 +56,25 @@ int putenv(const char *);
|
|||
|
||||
// ------------ CGraphicsBackend_Threaded
|
||||
|
||||
void CGraphicsBackend_Threaded::ThreadFunc()
|
||||
void CGraphicsBackend_Threaded::ThreadFunc(void *pUser)
|
||||
{
|
||||
std::unique_lock<std::mutex> Lock(m_BufferSwapMutex);
|
||||
auto *pSelf = (CGraphicsBackend_Threaded *)pUser;
|
||||
std::unique_lock<std::mutex> Lock(pSelf->m_BufferSwapMutex);
|
||||
// notify, that the thread started
|
||||
m_BufferDoneCond.notify_all();
|
||||
while(!m_Shutdown)
|
||||
pSelf->m_BufferDoneCond.notify_all();
|
||||
while(!pSelf->m_Shutdown)
|
||||
{
|
||||
m_BufferSwapCond.wait(Lock);
|
||||
if(m_pBuffer)
|
||||
pSelf->m_BufferSwapCond.wait(Lock);
|
||||
if(pSelf->m_pBuffer)
|
||||
{
|
||||
#ifdef CONF_PLATFORM_MACOS
|
||||
CAutoreleasePool AutoreleasePool;
|
||||
#endif
|
||||
m_pProcessor->RunBuffer(m_pBuffer);
|
||||
pSelf->m_pProcessor->RunBuffer(pSelf->m_pBuffer);
|
||||
|
||||
m_pBuffer = nullptr;
|
||||
m_BufferInProcess.store(false, std::memory_order_relaxed);
|
||||
m_BufferDoneCond.notify_all();
|
||||
pSelf->m_pBuffer = nullptr;
|
||||
pSelf->m_BufferInProcess.store(false, std::memory_order_relaxed);
|
||||
pSelf->m_BufferDoneCond.notify_all();
|
||||
}
|
||||
#if defined(CONF_VIDEORECORDER)
|
||||
if(IVideo::Current())
|
||||
|
@ -94,7 +95,7 @@ void CGraphicsBackend_Threaded::StartProcessor(ICommandProcessor *pProcessor)
|
|||
m_Shutdown = false;
|
||||
m_pProcessor = pProcessor;
|
||||
std::unique_lock<std::mutex> Lock(m_BufferSwapMutex);
|
||||
m_Thread = std::thread([&]() { ThreadFunc(); });
|
||||
m_Thread = thread_init(ThreadFunc, this, "Graphics thread");
|
||||
// wait for the thread to start
|
||||
m_BufferDoneCond.wait(Lock);
|
||||
}
|
||||
|
@ -106,7 +107,7 @@ void CGraphicsBackend_Threaded::StopProcessor()
|
|||
std::unique_lock<std::mutex> Lock(m_BufferSwapMutex);
|
||||
m_BufferSwapCond.notify_all();
|
||||
}
|
||||
m_Thread.join();
|
||||
thread_wait(m_Thread);
|
||||
}
|
||||
|
||||
void CGraphicsBackend_Threaded::RunBuffer(CCommandBuffer *pBuffer)
|
||||
|
|
|
@ -73,9 +73,9 @@ private:
|
|||
CCommandBuffer *m_pBuffer;
|
||||
std::atomic_bool m_Shutdown;
|
||||
std::atomic_bool m_BufferInProcess;
|
||||
std::thread m_Thread;
|
||||
void *m_Thread;
|
||||
|
||||
void ThreadFunc();
|
||||
static void ThreadFunc(void *pUser);
|
||||
};
|
||||
|
||||
// takes care of implementation independent operations
|
||||
|
|
Loading…
Reference in a new issue