MCPcopy Create free account
hub / github.com/SpecialKO/SpecialK / SK_Win32_IsGUIThread

Function SK_Win32_IsGUIThread

src/window.cpp:8818–8875  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8816#include <winnt.h>
8817
8818BOOL
8819SK_Win32_IsGUIThread ( DWORD dwTid,
8820 SK_TLS **ppTLS )
8821{
8822 UNREFERENCED_PARAMETER (ppTLS);
8823
8824 static volatile LONG64 last_result [3] = { 0x0, 0x0, 0x0 };
8825 LONG64 test_result0 =
8826 ReadAcquire64 (&last_result [0]),
8827 test_result1 =
8828 ReadAcquire64 (&last_result [1]),
8829 test_result2 =
8830 ReadAcquire64 (&last_result [2]);
8831
8832 static volatile LONG write_idx = 0;
8833
8834 if ( (DWORD)(test_result0 & 0x00000000FFFFFFFFULL) == dwTid)
8835 return ( test_result0 >> 32) > 0 ? TRUE : FALSE;
8836 else if ((DWORD)(test_result1 & 0x00000000FFFFFFFFULL) == dwTid)
8837 return ( test_result1 >> 32) > 0 ? TRUE : FALSE;
8838 else if ((DWORD)(test_result2 & 0x00000000FFFFFFFFULL) == dwTid)
8839 return ( test_result2 >> 32) > 0 ? TRUE : FALSE;
8840
8841 DWORD dwTidOfMe =
8842 SK_GetCurrentThreadId ();
8843
8844 BOOL
8845 bGUI = FALSE;
8846
8847 if (dwTidOfMe == dwTid)
8848 {
8849 bGUI =
8850 IsGUIThread (FALSE);
8851 }
8852
8853 else
8854 {
8855 GUITHREADINFO
8856 gti = { };
8857 gti.cbSize = sizeof (GUITHREADINFO);
8858
8859 bGUI =
8860 SK_GetGUIThreadInfo (dwTid, &gti);
8861 }
8862
8863 auto idx =
8864 InterlockedIncrement (&write_idx);
8865
8866 LONG64 test_result = (bGUI ? (1ull << 32) : 0)
8867 | (LONG64)(dwTid & 0xFFFFFFFFUL);
8868
8869 InterlockedExchange64 (
8870 &last_result [idx % 3], test_result
8871 );
8872
8873 return
8874 bGUI;
8875}

Callers 2

SK_GL_TrackHDCFunction · 0.85
updateStateMethod · 0.85

Calls 1

SK_GetGUIThreadInfoFunction · 0.85

Tested by

no test coverage detected