[c++] replace std::lock_guard with std::scoped_lock

This commit is contained in:
Armin Novak
2025-12-03 15:06:03 +01:00
parent 98b80dcc65
commit 7ccb5994c0
7 changed files with 36 additions and 36 deletions

View File

@@ -211,7 +211,7 @@ SSIZE_T sdl_retry_dialog(freerdp* instance, const char* what, size_t current,
auto sdl = get_context(instance->context);
auto settings = instance->context->settings;
const size_t delay = freerdp_settings_get_uint32(settings, FreeRDP_TcpConnectTimeout);
std::lock_guard<CriticalSection> lock(sdl->critical);
std::scoped_lock lock(sdl->critical);
if (!sdl->connection_dialog)
return WINPR_ASSERTING_INT_CAST(SSIZE_T, delay);

View File

@@ -225,7 +225,7 @@ static const struct sdl_exit_code_map_t* sdl_map_entry_by_code(int exit_code)
static void sdl_hide_connection_dialog(SdlContext* sdl)
{
WINPR_ASSERT(sdl);
std::lock_guard<CriticalSection> lock(sdl->critical);
std::scoped_lock lock(sdl->critical);
if (sdl->connection_dialog)
sdl->connection_dialog->hide();
}
@@ -491,7 +491,7 @@ static BOOL sdl_end_paint(rdpContext* context)
auto sdl = get_context(context);
WINPR_ASSERT(sdl);
std::lock_guard<CriticalSection> lock(sdl->critical);
std::scoped_lock lock(sdl->critical);
const BOOL rc = sdl_push_user_event(SDL_USEREVENT_UPDATE, context);
return rc;
@@ -546,7 +546,7 @@ static BOOL sdl_desktop_resize(rdpContext* context)
settings = context->settings;
WINPR_ASSERT(settings);
std::lock_guard<CriticalSection> lock(sdl->critical);
std::scoped_lock lock(sdl->critical);
gdi = context->gdi;
if (!gdi_resize(gdi, freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight)))
@@ -617,7 +617,7 @@ static BOOL sdl_pre_connect(freerdp* instance)
if (!sdl_wait_for_init(sdl))
return FALSE;
std::lock_guard<CriticalSection> lock(sdl->critical);
std::scoped_lock lock(sdl->critical);
if (!freerdp_settings_get_bool(settings, FreeRDP_UseCommonStdioCallbacks))
sdl->connection_dialog = std::make_unique<SDLConnectionDialog>(instance->context);
if (sdl->connection_dialog)
@@ -702,7 +702,7 @@ static void sdl_cleanup_sdl(SdlContext* sdl)
if (!sdl)
return;
std::lock_guard<CriticalSection> lock(sdl->critical);
std::scoped_lock lock(sdl->critical);
sdl->windows.clear();
sdl->connection_dialog.reset();
@@ -791,7 +791,7 @@ static BOOL sdl_create_windows(SdlContext* sdl)
static BOOL sdl_wait_create_windows(SdlContext* sdl)
{
std::lock_guard<CriticalSection> lock(sdl->critical);
std::scoped_lock lock(sdl->critical);
sdl->windows_created.clear();
if (!sdl_push_user_event(SDL_USEREVENT_CREATE_WINDOWS, sdl))
return FALSE;
@@ -810,7 +810,7 @@ static BOOL sdl_wait_create_windows(SdlContext* sdl)
static bool shall_abort(SdlContext* sdl)
{
std::lock_guard<CriticalSection> lock(sdl->critical);
std::scoped_lock lock(sdl->critical);
if (freerdp_shall_disconnect_context(sdl->context()))
{
if (sdl->rdp_thread_running)
@@ -870,7 +870,7 @@ static int sdl_run(SdlContext* sdl)
SDL_Log("got event %s [0x%08" PRIx32 "]", sdl_event_type_str(windowEvent.type),
windowEvent.type);
#endif
std::lock_guard<CriticalSection> lock(sdl->critical);
std::scoped_lock lock(sdl->critical);
/* The session might have been disconnected while we were waiting for a new SDL event.
* In that case ignore the SDL event and terminate. */
if (freerdp_shall_disconnect_context(sdl->context()))
@@ -1209,7 +1209,7 @@ static void sdl_client_cleanup(SdlContext* sdl, int exit_code, const std::string
break;
default:
{
std::lock_guard<CriticalSection> lock(sdl->critical);
std::scoped_lock lock(sdl->critical);
if (sdl->connection_dialog && !error_msg.empty())
{
sdl->connection_dialog->showError(error_msg.c_str());
@@ -1723,7 +1723,7 @@ int main(int argc, char* argv[])
BOOL SdlContext::update_fullscreen(BOOL enter)
{
std::lock_guard<CriticalSection> lock(critical);
std::scoped_lock lock(critical);
for (const auto& window : windows)
{
if (!sdl_push_user_event(SDL_USEREVENT_WINDOW_FULLSCREEN, &window.second, enter))
@@ -1735,13 +1735,13 @@ BOOL SdlContext::update_fullscreen(BOOL enter)
BOOL SdlContext::update_minimize()
{
std::lock_guard<CriticalSection> lock(critical);
std::scoped_lock lock(critical);
return sdl_push_user_event(SDL_USEREVENT_WINDOW_MINIMIZE);
}
BOOL SdlContext::update_resizeable(BOOL enable)
{
std::lock_guard<CriticalSection> lock(critical);
std::scoped_lock lock(critical);
const auto settings = context()->settings;
const BOOL dyn = freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate);

View File

@@ -45,7 +45,7 @@ SDLConnectionDialog::~SDLConnectionDialog()
bool SDLConnectionDialog::setTitle(const char* fmt, ...)
{
std::lock_guard lock(_mux);
std::scoped_lock lock(_mux);
va_list ap = {};
va_start(ap, fmt);
_title = print(fmt, ap);
@@ -85,19 +85,19 @@ bool SDLConnectionDialog::showError(const char* fmt, ...)
bool SDLConnectionDialog::show()
{
std::lock_guard lock(_mux);
std::scoped_lock lock(_mux);
return show(_type_active);
}
bool SDLConnectionDialog::hide()
{
std::lock_guard lock(_mux);
std::scoped_lock lock(_mux);
return show(SdlConnectionDialogWrapper::MSG_DISCARD);
}
bool SDLConnectionDialog::running() const
{
std::lock_guard lock(_mux);
std::scoped_lock lock(_mux);
return _running;
}
@@ -143,7 +143,7 @@ bool SDLConnectionDialog::setModal()
bool SDLConnectionDialog::updateInternal()
{
std::lock_guard lock(_mux);
std::scoped_lock lock(_mux);
for (auto& btn : _list)
{
if (!btn.widget.update_text(_msg))
@@ -179,7 +179,7 @@ bool SDLConnectionDialog::handle(const SDL_Event& event)
{
case SDL_EVENT_USER_RETRY_DIALOG:
{
std::lock_guard lock(_mux);
std::scoped_lock lock(_mux);
auto type = static_cast<SdlConnectionDialogWrapper::MsgType>(event.user.code);
return updateMsg(type);
}
@@ -289,7 +289,7 @@ bool SDLConnectionDialog::handle(const SDL_Event& event)
bool SDLConnectionDialog::visible() const
{
std::lock_guard lock(_mux);
std::scoped_lock lock(_mux);
return SdlWidgetList::visible();
}
@@ -397,7 +397,7 @@ void SDLConnectionDialog::destroyWindow()
bool SDLConnectionDialog::show(SdlConnectionDialogWrapper::MsgType type, const char* fmt,
va_list ap)
{
std::lock_guard lock(_mux);
std::scoped_lock lock(_mux);
_msg = print(fmt, ap);
return show(type);
}
@@ -436,7 +436,7 @@ std::string SDLConnectionDialog::print(const char* fmt, va_list ap)
bool SDLConnectionDialog::setTimer(Uint32 timeoutMS)
{
std::lock_guard lock(_mux);
std::scoped_lock lock(_mux);
resetTimer();
_timer = SDL_AddTimer(timeoutMS, &SDLConnectionDialog::timeout, this);

View File

@@ -116,7 +116,7 @@ class SdlConnectionDialogWrapper
void push(EventArg&& arg);
mutable std::mutex _mux;
std::unique_ptr<SDLConnectionDialog> _connection_dialog{};
std::queue<EventArg> _queue{};
std::unique_ptr<SDLConnectionDialog> _connection_dialog;
std::queue<EventArg> _queue;
wLog* _log = nullptr;
};

View File

@@ -592,7 +592,7 @@ std::shared_ptr<BYTE> sdlClip::ReceiveFormatDataRequestHandle(
ClipboardGetFormatName(clipboard->_system, localFormatId));
ClipboardLockGuard systemlock(clipboard->_system);
std::lock_guard<CriticalSection> lock(clipboard->_lock);
std::scoped_lock lock(clipboard->_lock);
const UINT32 fileFormatId =
ClipboardGetFormatId(clipboard->_system, s_type_FileGroupDescriptorW);
@@ -725,7 +725,7 @@ UINT sdlClip::ReceiveFormatDataResponse(CliprdrClientContext* context,
WINPR_ASSERT(clipboard);
ClipboardLockGuard systemlock(clipboard->_system);
std::lock_guard<CriticalSection> lock(clipboard->_lock);
std::scoped_lock lock(clipboard->_lock);
if (clipboard->_request_queue.empty())
{
WLog_Print(clipboard->_log, WLOG_ERROR, "no pending format request");
@@ -817,7 +817,7 @@ const void* sdlClip::ClipDataCb(void* userdata, const char* mime_type, size_t* s
{
ClipboardLockGuard systemlock(clip->_system);
std::lock_guard<CriticalSection> lock(clip->_lock);
std::scoped_lock lock(clip->_lock);
/* check if we already used this mime type */
auto cache = clip->_cache_data.find(mime_type);
@@ -858,7 +858,7 @@ const void* sdlClip::ClipDataCb(void* userdata, const char* mime_type, size_t* s
if (status != WAIT_OBJECT_0 + 1)
{
std::lock_guard<CriticalSection> lock(clip->_lock);
std::scoped_lock lock(clip->_lock);
clip->_request_queue.pop();
if (status == WAIT_TIMEOUT)
@@ -871,7 +871,7 @@ const void* sdlClip::ClipDataCb(void* userdata, const char* mime_type, size_t* s
{
ClipboardLockGuard systemlock(clip->_system);
std::lock_guard<CriticalSection> lock(clip->_lock);
std::scoped_lock lock(clip->_lock);
auto request = clip->_request_queue.front();
clip->_request_queue.pop();
@@ -903,7 +903,7 @@ void sdlClip::ClipCleanCb(void* userdata)
auto clip = static_cast<sdlClip*>(userdata);
WINPR_ASSERT(clip);
ClipboardLockGuard give_me_a_name(clip->_system);
std::lock_guard<CriticalSection> lock(clip->_lock);
std::scoped_lock lock(clip->_lock);
ClipboardEmpty(clip->_system);
}

View File

@@ -495,7 +495,7 @@ static BOOL sdl_desktop_resize(rdpContext* context)
settings = context->settings;
WINPR_ASSERT(settings);
std::lock_guard<CriticalSection> lock(sdl->critical);
std::scoped_lock lock(sdl->critical);
gdi = context->gdi;
if (!gdi_resize(gdi, freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight)))
@@ -644,7 +644,7 @@ static void sdl_cleanup_sdl(SdlContext* sdl)
if (!sdl)
return;
std::lock_guard<CriticalSection> lock(sdl->critical);
std::scoped_lock lock(sdl->critical);
sdl->windows.clear();
sdl->dialog.destroy();
@@ -763,7 +763,7 @@ static BOOL sdl_wait_create_windows(SdlContext* sdl)
static bool shall_abort(SdlContext* sdl)
{
std::lock_guard<CriticalSection> lock(sdl->critical);
std::scoped_lock lock(sdl->critical);
if (freerdp_shall_disconnect_context(sdl->context()))
{
if (sdl->rdp_thread_running)
@@ -829,7 +829,7 @@ static int sdl_run(SdlContext* sdl)
sdl_event_type_str(windowEvent.type), windowEvent.type);
#endif
{
std::lock_guard<CriticalSection> lock(sdl->critical);
std::scoped_lock lock(sdl->critical);
/* The session might have been disconnected while we were waiting for a
* new SDL event. In that case ignore the SDL event and terminate. */
if (freerdp_shall_disconnect_context(sdl->context()))

View File

@@ -103,7 +103,7 @@ class ChannelData
bool add(const std::string& name, WINPR_ATTR_UNUSED bool back)
{
std::lock_guard<std::mutex> guard(_mux);
std::scoped_lock guard(_mux);
if (_map.find(name) == _map.end())
{
WLog_INFO(TAG, "adding '%s' to dump list", name.c_str());
@@ -114,7 +114,7 @@ class ChannelData
std::ofstream stream(const std::string& name, bool back)
{
std::lock_guard<std::mutex> guard(_mux);
std::scoped_lock guard(_mux);
auto& atom = _map[name];
auto count = atom++;
auto path = filepath(name, back, count);