mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-25 00:58:30 -05:00
Switched platform specific thread creation code to bx::Thread.
This commit is contained in:
parent
bda65c2c0d
commit
88c07c3061
2 changed files with 19 additions and 45 deletions
28
src/bgfx.cpp
28
src/bgfx.cpp
|
@ -752,15 +752,9 @@ namespace bgfx
|
|||
#endif // BX_PLATFORM_
|
||||
|
||||
#if BGFX_CONFIG_MULTITHREADED
|
||||
m_renderThread = 0;
|
||||
|
||||
if (_createRenderThread)
|
||||
{
|
||||
# if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360
|
||||
m_renderThread = CreateThread(NULL, 16<<10, renderThread, NULL, 0, NULL);
|
||||
# elif BX_PLATFORM_POSIX
|
||||
pthread_create(&m_renderThread, NULL, renderThread, NULL);
|
||||
# endif // BX_PLATFORM_
|
||||
m_thread.init();
|
||||
}
|
||||
#else
|
||||
BX_UNUSED(_createRenderThread);
|
||||
|
@ -801,15 +795,9 @@ namespace bgfx
|
|||
frame();
|
||||
|
||||
#if BGFX_CONFIG_MULTITHREADED
|
||||
if (0 != m_renderThread)
|
||||
if (m_thread.isRunning() )
|
||||
{
|
||||
# if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360
|
||||
WaitForSingleObject(m_renderThread, INFINITE);
|
||||
m_renderThread = NULL;
|
||||
# elif BX_PLATFORM_POSIX
|
||||
pthread_join(m_renderThread, NULL);
|
||||
m_renderThread = 0;
|
||||
# endif // BX_PLATFORM_*
|
||||
m_thread.shutdown();
|
||||
}
|
||||
#endif // BGFX_CONFIG_MULTITHREADED
|
||||
|
||||
|
@ -817,16 +805,6 @@ namespace bgfx
|
|||
m_render->destroy();
|
||||
}
|
||||
|
||||
#if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360
|
||||
DWORD WINAPI renderThread(LPVOID)
|
||||
#else
|
||||
void* renderThread(void*)
|
||||
#endif // BX_PLATFORM_WINDOWS
|
||||
{
|
||||
while (!renderFrame() );
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
const Memory* alloc(uint32_t _size)
|
||||
{
|
||||
Memory* mem = (Memory*)g_realloc(NULL, sizeof(Memory) + _size);
|
||||
|
|
36
src/bgfx_p.h
36
src/bgfx_p.h
|
@ -72,8 +72,6 @@ extern HWND g_bgfxHwnd;
|
|||
#elif BX_PLATFORM_XBOX360
|
||||
# include <malloc.h>
|
||||
# include <xtl.h>
|
||||
#elif BX_PLATFORM_POSIX
|
||||
# include <pthread.h>
|
||||
#endif // BX_PLATFORM_*
|
||||
|
||||
#include "dds.h"
|
||||
|
@ -107,11 +105,8 @@ namespace stl = std;
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#if BGFX_CONFIG_MULTITHREADED
|
||||
# include <bx/sem.h>
|
||||
#endif // BGFX_CONFIG_MULTITHREADED
|
||||
|
||||
#include <bx/cpu.h>
|
||||
#include <bx/thread.h>
|
||||
#include <bx/timer.h>
|
||||
|
||||
#define BGFX_DRAW_WHOLE_INDEX_BUFFER 0xffffffff
|
||||
|
@ -1414,16 +1409,11 @@ namespace bgfx
|
|||
UsedList m_used;
|
||||
};
|
||||
|
||||
#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360
|
||||
DWORD WINAPI renderThread(LPVOID _arg);
|
||||
#elif BX_PLATFORM_POSIX
|
||||
void* renderThread(void*);
|
||||
#endif // BX_PLATFORM_
|
||||
|
||||
struct Context
|
||||
{
|
||||
Context()
|
||||
: m_render(&m_frame[0])
|
||||
: m_thread(renderThread, thisSuppressC4355() )
|
||||
, m_render(&m_frame[0])
|
||||
, m_submit(&m_frame[1])
|
||||
, m_dynamicIndexBufferHandle(BGFX_CONFIG_MAX_DYNAMIC_INDEX_BUFFERS)
|
||||
, m_dynamicVertexBufferHandle(BGFX_CONFIG_MAX_DYNAMIC_VERTEX_BUFFERS)
|
||||
|
@ -1447,6 +1437,18 @@ namespace bgfx
|
|||
{
|
||||
}
|
||||
|
||||
Context* thisSuppressC4355()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
static int32_t renderThread(void* _userData)
|
||||
{
|
||||
Context* ctx = (Context*)_userData;
|
||||
while (!ctx->renderFrame() );
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
// game thread
|
||||
void init(bool _createRenderThread);
|
||||
void shutdown();
|
||||
|
@ -2736,13 +2738,6 @@ namespace bgfx
|
|||
|
||||
Semaphore m_renderSem;
|
||||
Semaphore m_gameSem;
|
||||
|
||||
# if BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360
|
||||
HANDLE m_renderThread;
|
||||
# else
|
||||
pthread_t m_renderThread;
|
||||
# endif // BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360
|
||||
|
||||
#else
|
||||
void gameSemPost()
|
||||
{
|
||||
|
@ -2761,6 +2756,7 @@ namespace bgfx
|
|||
}
|
||||
#endif // BGFX_CONFIG_MULTITHREADED
|
||||
|
||||
Thread m_thread;
|
||||
Frame m_frame[2];
|
||||
Frame* m_render;
|
||||
Frame* m_submit;
|
||||
|
|
Loading…
Reference in a new issue