From 6e2ad6860f2cc3ac99071b6c1b65d0ca4c52942a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 7 Feb 2016 12:48:01 +0100 Subject: [PATCH] lib/upnp/ClientInit: use class ScopeLock --- src/lib/upnp/ClientInit.cxx | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/lib/upnp/ClientInit.cxx b/src/lib/upnp/ClientInit.cxx index 50fcbdb16..5558ee8d6 100644 --- a/src/lib/upnp/ClientInit.cxx +++ b/src/lib/upnp/ClientInit.cxx @@ -65,9 +65,11 @@ UpnpClientGlobalInit(UpnpClient_Handle &handle, Error &error) if (!UpnpGlobalInit(error)) return false; - upnp_client_init_mutex.lock(); - bool success = upnp_client_ref > 0 || DoInit(error); - upnp_client_init_mutex.unlock(); + bool success; + { + const ScopeLock protect(upnp_client_init_mutex); + success = upnp_client_ref > 0 || DoInit(error); + } if (success) { ++upnp_client_ref; @@ -81,13 +83,13 @@ UpnpClientGlobalInit(UpnpClient_Handle &handle, Error &error) void UpnpClientGlobalFinish() { - upnp_client_init_mutex.lock(); + { + const ScopeLock protect(upnp_client_init_mutex); - assert(upnp_client_ref > 0); - if (--upnp_client_ref == 0) - UpnpUnRegisterClient(upnp_client_handle); - - upnp_client_init_mutex.unlock(); + assert(upnp_client_ref > 0); + if (--upnp_client_ref == 0) + UpnpUnRegisterClient(upnp_client_handle); + } UpnpGlobalFinish(); }