Add RunOnWndMsgThread to run arbitrary code on the window message thread
This commit is contained in:
parent
7902c12738
commit
5a8cfaf7f9
|
@ -71,6 +71,7 @@
|
|||
#include <assert.h>
|
||||
#include <process.h>
|
||||
#include <clocale>
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
#include <thread>
|
||||
|
||||
|
@ -557,6 +558,16 @@ const char *CxbxGetErrorDescription(HRESULT hResult)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
static constexpr UINT WM_CXBXR_RUN_ON_MESSAGE_THREAD = WM_USER+0;
|
||||
|
||||
// A helper function to run any code on a window message thread
|
||||
// Used for those D3D9 function which *must* be ran on this particular thread
|
||||
static void RunOnWndMsgThread(const std::function<void()>& func)
|
||||
{
|
||||
const void* param = &func;
|
||||
SendMessage(g_hEmuWindow, WM_CXBXR_RUN_ON_MESSAGE_THREAD, reinterpret_cast<WPARAM>(param), 0);
|
||||
}
|
||||
|
||||
|
||||
const char *D3DErrorString(HRESULT hResult)
|
||||
{
|
||||
|
@ -2109,6 +2120,13 @@ static LRESULT WINAPI EmuMsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPar
|
|||
}
|
||||
break;
|
||||
|
||||
case WM_CXBXR_RUN_ON_MESSAGE_THREAD:
|
||||
{
|
||||
auto func = reinterpret_cast<const std::function<void()>*>(wParam);
|
||||
(*func)();
|
||||
return 0;
|
||||
}
|
||||
|
||||
default:
|
||||
return DefWindowProc(hWnd, msg, wParam, lParam);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue