[client,sdl] use CriticalSectionLock
use c++ RAII to lock critical sections
This commit is contained in:
parent
86470103c4
commit
26ee0590d6
@ -406,9 +406,9 @@ static BOOL sdl_end_paint(rdpContext* context)
|
||||
auto sdl = reinterpret_cast<sdlContext*>(context);
|
||||
WINPR_ASSERT(sdl);
|
||||
|
||||
EnterCriticalSection(&sdl->critical);
|
||||
CriticalSectionLock lock(sdl->critical);
|
||||
const BOOL rc = sdl_push_user_event(SDL_USEREVENT_UPDATE, context);
|
||||
LeaveCriticalSection(&sdl->critical);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -638,17 +638,10 @@ fail:
|
||||
|
||||
static BOOL sdl_wait_create_windows(sdlContext* sdl)
|
||||
{
|
||||
BOOL res = FALSE;
|
||||
EnterCriticalSection(&sdl->critical);
|
||||
res = ResetEvent(sdl->windows_created);
|
||||
if (!res)
|
||||
goto unlock;
|
||||
res = sdl_push_user_event(SDL_USEREVENT_CREATE_WINDOWS, sdl);
|
||||
if (!res)
|
||||
goto unlock;
|
||||
unlock:
|
||||
LeaveCriticalSection(&sdl->critical);
|
||||
if (!res)
|
||||
CriticalSectionLock lock(sdl->critical);
|
||||
if (!ResetEvent(sdl->windows_created))
|
||||
return FALSE;
|
||||
if (!sdl_push_user_event(SDL_USEREVENT_CREATE_WINDOWS, sdl))
|
||||
return FALSE;
|
||||
|
||||
HANDLE handles[] = { sdl->initialized, freerdp_abort_event(&sdl->common.context) };
|
||||
@ -692,7 +685,7 @@ static int sdl_run(sdlContext* sdl)
|
||||
SDL_Log("got event %s [0x%08" PRIx32 "]", sdl_event_type_str(windowEvent.type),
|
||||
windowEvent.type);
|
||||
#endif
|
||||
EnterCriticalSection(&sdl->critical);
|
||||
CriticalSectionLock lock(sdl->critical);
|
||||
switch (windowEvent.type)
|
||||
{
|
||||
case SDL_QUIT:
|
||||
@ -838,7 +831,6 @@ static int sdl_run(sdlContext* sdl)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
LeaveCriticalSection(&sdl->critical);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,7 +178,7 @@ BOOL update_fullscreen(sdlContext* sdl, BOOL enter)
|
||||
{
|
||||
WINPR_ASSERT(sdl);
|
||||
|
||||
EnterCriticalSection(&sdl->critical);
|
||||
CriticalSectionLock lock(sdl->critical);
|
||||
for (uint32_t x = 0; x < sdl->windowCount; x++)
|
||||
{
|
||||
sdl_window_t* window = &sdl->windows[x];
|
||||
@ -186,7 +186,6 @@ BOOL update_fullscreen(sdlContext* sdl, BOOL enter)
|
||||
return FALSE;
|
||||
}
|
||||
sdl->fullscreen = enter;
|
||||
LeaveCriticalSection(&sdl->critical);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -194,7 +193,7 @@ BOOL update_resizeable(sdlContext* sdl, BOOL enable)
|
||||
{
|
||||
WINPR_ASSERT(sdl);
|
||||
|
||||
EnterCriticalSection(&sdl->critical);
|
||||
CriticalSectionLock lock(sdl->critical);
|
||||
|
||||
const rdpSettings* settings = sdl->common.context.settings;
|
||||
const BOOL dyn = freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate);
|
||||
@ -209,6 +208,5 @@ BOOL update_resizeable(sdlContext* sdl, BOOL enable)
|
||||
}
|
||||
sdl->resizeable = use;
|
||||
|
||||
LeaveCriticalSection(&sdl->critical);
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -26,6 +26,22 @@
|
||||
|
||||
#include "sdl_freerdp.hpp"
|
||||
|
||||
class CriticalSectionLock
|
||||
{
|
||||
public:
|
||||
CriticalSectionLock(CRITICAL_SECTION& section) : _section(section)
|
||||
{
|
||||
EnterCriticalSection(&_section);
|
||||
}
|
||||
~CriticalSectionLock()
|
||||
{
|
||||
LeaveCriticalSection(&_section);
|
||||
}
|
||||
|
||||
private:
|
||||
CRITICAL_SECTION _section;
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
SDL_USEREVENT_UPDATE = SDL_USEREVENT + 1,
|
||||
|
Loading…
Reference in New Issue
Block a user