From b2009e2fca96bb06b63a21ba416eadf099d3a51c Mon Sep 17 00:00:00 2001 From: Jim-Marsden <47166310+Jim-Marsden@users.noreply.github.com> Date: Tue, 10 Jan 2023 20:43:38 -0800 Subject: [PATCH] Changed from std::scoped_lock to std::lock_guard --- examples/island/Island.cpp | 12 ++++---- examples/voip/Server.cpp | 6 ++-- src/SFML/Audio/AlResource.cpp | 4 +-- src/SFML/Audio/Music.cpp | 8 +++--- src/SFML/Audio/SoundStream.cpp | 26 ++++++++--------- src/SFML/Graphics/RenderTarget.cpp | 4 +-- src/SFML/Graphics/RenderTextureImplFBO.cpp | 14 +++++----- src/SFML/Graphics/Shader.cpp | 4 +-- src/SFML/Graphics/Texture.cpp | 4 +-- src/SFML/Graphics/VertexBuffer.cpp | 2 +- src/SFML/Main/MainAndroid.cpp | 22 +++++++-------- src/SFML/System/Android/ResourceStream.cpp | 4 +-- src/SFML/Window/Android/InputImpl.cpp | 20 ++++++------- src/SFML/Window/Android/VideoModeImpl.cpp | 2 +- src/SFML/Window/Android/WindowImplAndroid.cpp | 20 ++++++------- src/SFML/Window/DRM/InputImplUDev.cpp | 16 +++++------ src/SFML/Window/EglContext.cpp | 6 ++-- src/SFML/Window/GlContext.cpp | 28 +++++++++---------- src/SFML/Window/Unix/Display.cpp | 8 +++--- src/SFML/Window/Unix/GlxContext.cpp | 4 +-- src/SFML/Window/Unix/WindowImplX11.cpp | 6 ++-- src/SFML/Window/Win32/WglContext.cpp | 4 +-- 22 files changed, 112 insertions(+), 112 deletions(-) diff --git a/examples/island/Island.cpp b/examples/island/Island.cpp index 2032c479..ca4b70a1 100644 --- a/examples/island/Island.cpp +++ b/examples/island/Island.cpp @@ -224,7 +224,7 @@ int main() if (prerequisitesSupported) { { - std::scoped_lock lock(workQueueMutex); + std::lock_guard lock(workQueueMutex); // Don't bother updating/drawing the VertexBuffer while terrain is being regenerated if (!pendingWorkCount) @@ -267,7 +267,7 @@ int main() // Shut down our thread pool { - std::scoped_lock lock(workQueueMutex); + std::lock_guard lock(workQueueMutex); workPending = false; } @@ -581,7 +581,7 @@ void threadFunction() // Check if there are new work items in the queue { - std::scoped_lock lock(workQueueMutex); + std::lock_guard lock(workQueueMutex); if (!workPending) return; @@ -604,7 +604,7 @@ void threadFunction() processWorkItem(vertices, workItem); { - std::scoped_lock lock(workQueueMutex); + std::lock_guard lock(workQueueMutex); --pendingWorkCount; } @@ -626,7 +626,7 @@ void generateTerrain(sf::Vertex* buffer) for (;;) { { - std::scoped_lock lock(workQueueMutex); + std::lock_guard lock(workQueueMutex); if (workQueue.empty()) break; @@ -637,7 +637,7 @@ void generateTerrain(sf::Vertex* buffer) // Queue all the new work items { - std::scoped_lock lock(workQueueMutex); + std::lock_guard lock(workQueueMutex); for (unsigned int i = 0; i < blockCount; ++i) { diff --git a/examples/voip/Server.cpp b/examples/voip/Server.cpp index 14701621..053b83f4 100644 --- a/examples/voip/Server.cpp +++ b/examples/voip/Server.cpp @@ -81,7 +81,7 @@ private: // Copy samples into a local buffer to avoid synchronization problems // (don't forget that we run in two separate threads) { - std::scoped_lock lock(m_mutex); + std::lock_guard lock(m_mutex); m_tempBuffer.assign(m_samples.begin() + static_cast::difference_type>(m_offset), m_samples.end()); } @@ -130,8 +130,8 @@ private: // Don't forget that the other thread can access the sample array at any time // (so we protect any operation on it with the mutex) { - std::scoped_lock lock(m_mutex); - std::size_t oldSize = m_samples.size(); + std::lock_guard lock(m_mutex); + std::size_t oldSize = m_samples.size(); m_samples.resize(oldSize + sampleCount); std::memcpy(&(m_samples[oldSize]), static_cast(packet.getData()) + 1, diff --git a/src/SFML/Audio/AlResource.cpp b/src/SFML/Audio/AlResource.cpp index 1cc6386b..74ac0bb5 100644 --- a/src/SFML/Audio/AlResource.cpp +++ b/src/SFML/Audio/AlResource.cpp @@ -51,7 +51,7 @@ namespace sf AlResource::AlResource() { // Protect from concurrent access - std::scoped_lock lock(mutex); + std::lock_guard lock(mutex); // If this is the very first resource, trigger the global device initialization if (count == 0) @@ -66,7 +66,7 @@ AlResource::AlResource() AlResource::~AlResource() { // Protect from concurrent access - std::scoped_lock lock(mutex); + std::lock_guard lock(mutex); // Decrement the resources counter --count; diff --git a/src/SFML/Audio/Music.cpp b/src/SFML/Audio/Music.cpp index eb4d04d8..c486cc96 100644 --- a/src/SFML/Audio/Music.cpp +++ b/src/SFML/Audio/Music.cpp @@ -176,7 +176,7 @@ void Music::setLoopPoints(TimeSpan timePoints) //////////////////////////////////////////////////////////// bool Music::onGetData(SoundStream::Chunk& data) { - std::scoped_lock lock(m_mutex); + std::lock_guard lock(m_mutex); std::size_t toFill = m_samples.size(); std::uint64_t currentOffset = m_file.getSampleOffset(); @@ -202,7 +202,7 @@ bool Music::onGetData(SoundStream::Chunk& data) //////////////////////////////////////////////////////////// void Music::onSeek(Time timeOffset) { - std::scoped_lock lock(m_mutex); + std::lock_guard lock(m_mutex); m_file.seek(timeOffset); } @@ -211,8 +211,8 @@ void Music::onSeek(Time timeOffset) std::int64_t Music::onLoop() { // Called by underlying SoundStream so we can determine where to loop. - std::scoped_lock lock(m_mutex); - std::uint64_t currentOffset = m_file.getSampleOffset(); + std::lock_guard lock(m_mutex); + std::uint64_t currentOffset = m_file.getSampleOffset(); if (getLoop() && (m_loopSpan.length != 0) && (currentOffset == m_loopSpan.offset + m_loopSpan.length)) { // Looping is enabled, and either we're at the loop end, or we're at the EOF diff --git a/src/SFML/Audio/SoundStream.cpp b/src/SFML/Audio/SoundStream.cpp index 1857217b..5635438e 100644 --- a/src/SFML/Audio/SoundStream.cpp +++ b/src/SFML/Audio/SoundStream.cpp @@ -67,7 +67,7 @@ void SoundStream::initialize(unsigned int channelCount, unsigned int sampleRate) m_samplesProcessed = 0; { - std::scoped_lock lock(m_threadMutex); + std::lock_guard lock(m_threadMutex); m_isStreaming = false; } @@ -99,7 +99,7 @@ void SoundStream::play() Status threadStartState = Stopped; { - std::scoped_lock lock(m_threadMutex); + std::lock_guard lock(m_threadMutex); isStreaming = m_isStreaming; threadStartState = m_threadStartState; @@ -109,7 +109,7 @@ void SoundStream::play() if (isStreaming && (threadStartState == Paused)) { // If the sound is paused, resume it - std::scoped_lock lock(m_threadMutex); + std::lock_guard lock(m_threadMutex); m_threadStartState = Playing; alCheck(alSourcePlay(m_source)); return; @@ -136,7 +136,7 @@ void SoundStream::pause() { // Handle pause() being called before the thread has started { - std::scoped_lock lock(m_threadMutex); + std::lock_guard lock(m_threadMutex); if (!m_isStreaming) return; @@ -181,7 +181,7 @@ SoundStream::Status SoundStream::getStatus() const // To compensate for the lag between play() and alSourceplay() if (status == Stopped) { - std::scoped_lock lock(m_threadMutex); + std::lock_guard lock(m_threadMutex); if (m_isStreaming) status = m_threadStartState; @@ -265,7 +265,7 @@ void SoundStream::streamData() bool requestStop = false; { - std::scoped_lock lock(m_threadMutex); + std::lock_guard lock(m_threadMutex); // Check if the thread was launched Stopped if (m_threadStartState == Stopped) @@ -287,7 +287,7 @@ void SoundStream::streamData() alCheck(alSourcePlay(m_source)); { - std::scoped_lock lock(m_threadMutex); + std::lock_guard lock(m_threadMutex); // Check if the thread was launched Paused if (m_threadStartState == Paused) @@ -297,7 +297,7 @@ void SoundStream::streamData() for (;;) { { - std::scoped_lock lock(m_threadMutex); + std::lock_guard lock(m_threadMutex); if (!m_isStreaming) break; } @@ -313,7 +313,7 @@ void SoundStream::streamData() else { // End streaming - std::scoped_lock lock(m_threadMutex); + std::lock_guard lock(m_threadMutex); m_isStreaming = false; } } @@ -357,7 +357,7 @@ void SoundStream::streamData() << "and initialize() has been called correctly" << std::endl; // Abort streaming (exit main loop) - std::scoped_lock lock(m_threadMutex); + std::lock_guard lock(m_threadMutex); m_isStreaming = false; requestStop = true; break; @@ -380,7 +380,7 @@ void SoundStream::streamData() if (alGetLastError() != AL_NO_ERROR) { // Abort streaming (exit main loop) - std::scoped_lock lock(m_threadMutex); + std::lock_guard lock(m_threadMutex); m_isStreaming = false; break; } @@ -500,7 +500,7 @@ void SoundStream::clearQueue() void SoundStream::launchStreamingThread(Status threadStartState) { { - std::scoped_lock lock(m_threadMutex); + std::lock_guard lock(m_threadMutex); m_isStreaming = true; m_threadStartState = threadStartState; } @@ -515,7 +515,7 @@ void SoundStream::awaitStreamingThread() { // Request the thread to join { - std::scoped_lock lock(m_threadMutex); + std::lock_guard lock(m_threadMutex); m_isStreaming = false; } diff --git a/src/SFML/Graphics/RenderTarget.cpp b/src/SFML/Graphics/RenderTarget.cpp index 0ea3f55d..ad6f64b5 100644 --- a/src/SFML/Graphics/RenderTarget.cpp +++ b/src/SFML/Graphics/RenderTarget.cpp @@ -55,7 +55,7 @@ std::recursive_mutex mutex; // tracking the currently active RenderTarget within a given context std::uint64_t getUniqueId() { - std::scoped_lock lock(mutex); + std::lock_guard lock(mutex); static std::uint64_t id = 1; // start at 1, zero is "no RenderTarget" @@ -392,7 +392,7 @@ bool RenderTarget::setActive(bool active) { // Mark this RenderTarget as active or no longer active in the tracking map { - std::scoped_lock lock(RenderTargetImpl::mutex); + std::lock_guard lock(RenderTargetImpl::mutex); std::uint64_t contextId = Context::getActiveContextId(); diff --git a/src/SFML/Graphics/RenderTextureImplFBO.cpp b/src/SFML/Graphics/RenderTextureImplFBO.cpp index ace801eb..aee474d8 100644 --- a/src/SFML/Graphics/RenderTextureImplFBO.cpp +++ b/src/SFML/Graphics/RenderTextureImplFBO.cpp @@ -84,7 +84,7 @@ void destroyStaleFBOs() // Callback that is called every time a context is destroyed void contextDestroyCallback(void* /*arg*/) { - std::scoped_lock lock(mutex); + std::lock_guard lock(mutex); std::uint64_t contextId = sf::Context::getActiveContextId(); @@ -117,7 +117,7 @@ namespace sf::priv //////////////////////////////////////////////////////////// RenderTextureImplFBO::RenderTextureImplFBO() { - std::scoped_lock lock(mutex); + std::lock_guard lock(mutex); // Register the context destruction callback registerContextDestroyCallback(contextDestroyCallback, nullptr); @@ -133,7 +133,7 @@ RenderTextureImplFBO::~RenderTextureImplFBO() { TransientContextLock contextLock; - std::scoped_lock lock(mutex); + std::lock_guard lock(mutex); // Remove the frame buffer mapping from the set of all active mappings frameBuffers.erase(&m_frameBuffers); @@ -462,7 +462,7 @@ bool RenderTextureImplFBO::createFrameBuffer() } { - std::scoped_lock lock(mutex); + std::lock_guard lock(mutex); // Insert the FBO into our map m_frameBuffers.emplace(Context::getActiveContextId(), frameBuffer); @@ -519,7 +519,7 @@ bool RenderTextureImplFBO::createFrameBuffer() } { - std::scoped_lock lock(mutex); + std::lock_guard lock(mutex); // Insert the FBO into our map m_multisampleFrameBuffers.emplace(Context::getActiveContextId(), multisampleFrameBuffer); @@ -570,7 +570,7 @@ bool RenderTextureImplFBO::activate(bool active) // If none is found, there is no FBO corresponding to the // currently active context so we will have to create a new FBO { - std::scoped_lock lock(mutex); + std::lock_guard lock(mutex); std::unordered_map::iterator it; @@ -624,7 +624,7 @@ void RenderTextureImplFBO::updateTexture(unsigned int) { std::uint64_t contextId = Context::getActiveContextId(); - std::scoped_lock lock(mutex); + std::lock_guard lock(mutex); auto frameBufferIt = m_frameBuffers.find(contextId); auto multisampleIt = m_multisampleFrameBuffers.find(contextId); diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index 77dc8452..4a6eae23 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -745,7 +745,7 @@ void Shader::bind(const Shader* shader) //////////////////////////////////////////////////////////// bool Shader::isAvailable() { - std::scoped_lock lock(isAvailableMutex); + std::lock_guard lock(isAvailableMutex); static bool checked = false; static bool available = false; @@ -770,7 +770,7 @@ bool Shader::isAvailable() //////////////////////////////////////////////////////////// bool Shader::isGeometryAvailable() { - std::scoped_lock lock(isAvailableMutex); + std::lock_guard lock(isAvailableMutex); static bool checked = false; static bool available = false; diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index 9ff3fcd0..df6970d6 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -52,7 +52,7 @@ std::recursive_mutex maximumSizeMutex; // is used for states cache (see RenderTarget) std::uint64_t getUniqueId() { - std::scoped_lock lock(idMutex); + std::lock_guard lock(idMutex); static std::uint64_t id = 1; // start at 1, zero is "no texture" @@ -833,7 +833,7 @@ void Texture::bind(const Texture* texture, CoordinateType coordinateType) //////////////////////////////////////////////////////////// unsigned int Texture::getMaximumSize() { - std::scoped_lock lock(TextureImpl::maximumSizeMutex); + std::lock_guard lock(TextureImpl::maximumSizeMutex); static bool checked = false; static GLint size = 0; diff --git a/src/SFML/Graphics/VertexBuffer.cpp b/src/SFML/Graphics/VertexBuffer.cpp index 5abca70e..e79aefd2 100644 --- a/src/SFML/Graphics/VertexBuffer.cpp +++ b/src/SFML/Graphics/VertexBuffer.cpp @@ -336,7 +336,7 @@ VertexBuffer::Usage VertexBuffer::getUsage() const //////////////////////////////////////////////////////////// bool VertexBuffer::isAvailable() { - std::scoped_lock lock(VertexBufferImpl::isAvailableMutex); + std::lock_guard lock(VertexBufferImpl::isAvailableMutex); static bool checked = false; static bool available = false; diff --git a/src/SFML/Main/MainAndroid.cpp b/src/SFML/Main/MainAndroid.cpp index 89edae23..cea46b7b 100644 --- a/src/SFML/Main/MainAndroid.cpp +++ b/src/SFML/Main/MainAndroid.cpp @@ -94,7 +94,7 @@ ActivityStates* retrieveStates(ANativeActivity* activity) static void initializeMain(ActivityStates* states) { // Protect from concurrent access - std::scoped_lock lock(states->mutex); + std::lock_guard lock(states->mutex); // Prepare and share the looper to be read later ALooper* looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); @@ -118,7 +118,7 @@ static void initializeMain(ActivityStates* states) static void terminateMain(ActivityStates* states) { // Protect from concurrent access - std::scoped_lock lock(states->mutex); + std::lock_guard lock(states->mutex); // The main thread has finished, we must explicitly ask the activity to finish states->mainOver = true; @@ -139,7 +139,7 @@ void* main(ActivityStates* states) terminateMain(states); { - std::scoped_lock lock(states->mutex); + std::lock_guard lock(states->mutex); states->terminated = true; } @@ -261,7 +261,7 @@ static void onResume(ANativeActivity* activity) { // Retrieve our activity states from the activity instance sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity); - std::scoped_lock lock(states->mutex); + std::lock_guard lock(states->mutex); if (states->fullscreen) goToFullscreenMode(activity); @@ -279,7 +279,7 @@ static void onPause(ANativeActivity* activity) { // Retrieve our activity states from the activity instance sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity); - std::scoped_lock lock(states->mutex); + std::lock_guard lock(states->mutex); // Send an event to warn people the activity has been paused sf::Event event; @@ -303,7 +303,7 @@ static void onDestroy(ANativeActivity* activity) // Send an event to warn people the activity is being destroyed { - std::scoped_lock lock(states->mutex); + std::lock_guard lock(states->mutex); // If the main thread hasn't yet finished, send the event and wait for // it to finish. @@ -345,7 +345,7 @@ static void onDestroy(ANativeActivity* activity) static void onNativeWindowCreated(ANativeActivity* activity, ANativeWindow* window) { sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity); - std::scoped_lock lock(states->mutex); + std::lock_guard lock(states->mutex); // Update the activity states states->window = window; @@ -370,7 +370,7 @@ static void onNativeWindowCreated(ANativeActivity* activity, ANativeWindow* wind static void onNativeWindowDestroyed(ANativeActivity* activity, ANativeWindow* /* window */) { sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity); - std::scoped_lock lock(states->mutex); + std::lock_guard lock(states->mutex); // Update the activity states states->window = nullptr; @@ -411,7 +411,7 @@ static void onInputQueueCreated(ANativeActivity* activity, AInputQueue* queue) // Attach the input queue { - std::scoped_lock lock(states->mutex); + std::lock_guard lock(states->mutex); AInputQueue_attachLooper(queue, states->looper, 1, states->processEvent, nullptr); states->inputQueue = queue; @@ -427,7 +427,7 @@ static void onInputQueueDestroyed(ANativeActivity* activity, AInputQueue* queue) // Detach the input queue { - std::scoped_lock lock(states->mutex); + std::lock_guard lock(states->mutex); AInputQueue_detachLooper(queue); states->inputQueue = nullptr; @@ -448,7 +448,7 @@ static void onContentRectChanged(ANativeActivity* activity, const ARect* /* rect { // Retrieve our activity states from the activity instance sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity); - std::scoped_lock lock(states->mutex); + std::lock_guard lock(states->mutex); // Make sure the window still exists before we access the dimensions on it if (states->window != nullptr) diff --git a/src/SFML/System/Android/ResourceStream.cpp b/src/SFML/System/Android/ResourceStream.cpp index 90008473..870d11c8 100644 --- a/src/SFML/System/Android/ResourceStream.cpp +++ b/src/SFML/System/Android/ResourceStream.cpp @@ -38,8 +38,8 @@ namespace sf::priv //////////////////////////////////////////////////////////// ResourceStream::ResourceStream(const std::filesystem::path& filename) : m_file(nullptr) { - ActivityStates& states = getActivity(); - std::scoped_lock lock(states.mutex); + ActivityStates& states = getActivity(); + std::lock_guard lock(states.mutex); m_file = AAssetManager_open(states.activity->assetManager, filename.c_str(), AASSET_MODE_UNKNOWN); } diff --git a/src/SFML/Window/Android/InputImpl.cpp b/src/SFML/Window/Android/InputImpl.cpp index 34108c87..e9b65c32 100644 --- a/src/SFML/Window/Android/InputImpl.cpp +++ b/src/SFML/Window/Android/InputImpl.cpp @@ -49,8 +49,8 @@ void InputImpl::setVirtualKeyboardVisible(bool visible) { // todo: Check if the window is active - ActivityStates& states = getActivity(); - std::scoped_lock lock(states.mutex); + ActivityStates& states = getActivity(); + std::lock_guard lock(states.mutex); // Initializes JNI jint lFlags = 0; @@ -133,8 +133,8 @@ bool InputImpl::isMouseButtonPressed(Mouse::Button button) { ALooper_pollAll(0, nullptr, nullptr, nullptr); - ActivityStates& states = getActivity(); - std::scoped_lock lock(states.mutex); + ActivityStates& states = getActivity(); + std::lock_guard lock(states.mutex); return states.isButtonPressed[button]; } @@ -145,8 +145,8 @@ Vector2i InputImpl::getMousePosition() { ALooper_pollAll(0, nullptr, nullptr, nullptr); - ActivityStates& states = getActivity(); - std::scoped_lock lock(states.mutex); + ActivityStates& states = getActivity(); + std::lock_guard lock(states.mutex); return states.mousePosition; } @@ -178,8 +178,8 @@ bool InputImpl::isTouchDown(unsigned int finger) { ALooper_pollAll(0, nullptr, nullptr, nullptr); - ActivityStates& states = getActivity(); - std::scoped_lock lock(states.mutex); + ActivityStates& states = getActivity(); + std::lock_guard lock(states.mutex); return states.touchEvents.find(static_cast(finger)) != states.touchEvents.end(); } @@ -190,8 +190,8 @@ Vector2i InputImpl::getTouchPosition(unsigned int finger) { ALooper_pollAll(0, nullptr, nullptr, nullptr); - ActivityStates& states = getActivity(); - std::scoped_lock lock(states.mutex); + ActivityStates& states = getActivity(); + std::lock_guard lock(states.mutex); return states.touchEvents.find(static_cast(finger))->second; } diff --git a/src/SFML/Window/Android/VideoModeImpl.cpp b/src/SFML/Window/Android/VideoModeImpl.cpp index 342d8924..1828f463 100644 --- a/src/SFML/Window/Android/VideoModeImpl.cpp +++ b/src/SFML/Window/Android/VideoModeImpl.cpp @@ -52,7 +52,7 @@ VideoMode VideoModeImpl::getDesktopMode() { // Get the activity states priv::ActivityStates& states = priv::getActivity(); - std::scoped_lock lock(states.mutex); + std::lock_guard lock(states.mutex); return VideoMode(Vector2u(states.screenSize)); } diff --git a/src/SFML/Window/Android/WindowImplAndroid.cpp b/src/SFML/Window/Android/WindowImplAndroid.cpp index 7f16d3f9..070b60d7 100644 --- a/src/SFML/Window/Android/WindowImplAndroid.cpp +++ b/src/SFML/Window/Android/WindowImplAndroid.cpp @@ -62,8 +62,8 @@ WindowImplAndroid::WindowImplAndroid(VideoMode mode, const ContextSettings& /* settings */) : m_size(mode.size) { - ActivityStates& states = getActivity(); - std::scoped_lock lock(states.mutex); + ActivityStates& states = getActivity(); + std::lock_guard lock(states.mutex); if (style & Style::Fullscreen) states.fullscreen = true; @@ -88,8 +88,8 @@ WindowImplAndroid::~WindowImplAndroid() //////////////////////////////////////////////////////////// WindowHandle WindowImplAndroid::getSystemHandle() const { - ActivityStates& states = getActivity(); - std::scoped_lock lock(states.mutex); + ActivityStates& states = getActivity(); + std::lock_guard lock(states.mutex); return states.window; } @@ -101,8 +101,8 @@ void WindowImplAndroid::processEvents() // Process incoming OS events ALooper_pollAll(0, nullptr, nullptr, nullptr); - ActivityStates& states = getActivity(); - std::scoped_lock lock(states.mutex); + ActivityStates& states = getActivity(); + std::lock_guard lock(states.mutex); if (m_windowBeingCreated) { @@ -239,8 +239,8 @@ void WindowImplAndroid::forwardEvent(const Event& event) //////////////////////////////////////////////////////////// int WindowImplAndroid::processEvent(int /* fd */, int /* events */, void* /* data */) { - ActivityStates& states = getActivity(); - std::scoped_lock lock(states.mutex); + ActivityStates& states = getActivity(); + std::lock_guard lock(states.mutex); AInputEvent* _event = nullptr; @@ -693,8 +693,8 @@ Keyboard::Key WindowImplAndroid::androidKeyToSF(std::int32_t key) int WindowImplAndroid::getUnicode(AInputEvent* event) { // Retrieve activity states - ActivityStates& states = getActivity(); - std::scoped_lock lock(states.mutex); + ActivityStates& states = getActivity(); + std::lock_guard lock(states.mutex); // Initializes JNI jint lResult; diff --git a/src/SFML/Window/DRM/InputImplUDev.cpp b/src/SFML/Window/DRM/InputImplUDev.cpp index e9cedc8f..6c4c4e81 100644 --- a/src/SFML/Window/DRM/InputImplUDev.cpp +++ b/src/SFML/Window/DRM/InputImplUDev.cpp @@ -352,7 +352,7 @@ void processSlots() bool eventProcess(sf::Event& event) { - std::scoped_lock lock(inputMutex); + std::lock_guard lock(inputMutex); // Ensure that we are initialized initFileDescriptors(); @@ -565,7 +565,7 @@ namespace sf::priv //////////////////////////////////////////////////////////// bool InputImpl::isKeyPressed(Keyboard::Key key) { - std::scoped_lock lock(inputMutex); + std::lock_guard lock(inputMutex); if ((key < 0) || (key >= static_cast(keyMap.size()))) return false; @@ -584,7 +584,7 @@ void InputImpl::setVirtualKeyboardVisible(bool /*visible*/) //////////////////////////////////////////////////////////// bool InputImpl::isMouseButtonPressed(Mouse::Button button) { - std::scoped_lock lock(inputMutex); + std::lock_guard lock(inputMutex); if ((button < 0) || (button >= static_cast(mouseMap.size()))) return false; @@ -596,7 +596,7 @@ bool InputImpl::isMouseButtonPressed(Mouse::Button button) //////////////////////////////////////////////////////////// Vector2i InputImpl::getMousePosition() { - std::scoped_lock lock(inputMutex); + std::lock_guard lock(inputMutex); return mousePos; } @@ -611,7 +611,7 @@ Vector2i InputImpl::getMousePosition(const WindowBase& /*relativeTo*/) //////////////////////////////////////////////////////////// void InputImpl::setMousePosition(const Vector2i& position) { - std::scoped_lock lock(inputMutex); + std::lock_guard lock(inputMutex); mousePos = position; } @@ -659,7 +659,7 @@ Vector2i InputImpl::getTouchPosition(unsigned int finger, const WindowBase& /*re //////////////////////////////////////////////////////////// bool InputImpl::checkEvent(sf::Event& event) { - std::scoped_lock lock(inputMutex); + std::lock_guard lock(inputMutex); if (!eventQueue.empty()) { event = eventQueue.front(); @@ -693,7 +693,7 @@ bool InputImpl::checkEvent(sf::Event& event) //////////////////////////////////////////////////////////// void InputImpl::setTerminalConfig() { - std::scoped_lock lock(inputMutex); + std::lock_guard lock(inputMutex); initFileDescriptors(); tcgetattr(STDIN_FILENO, &newTerminalConfig); // get current terminal config @@ -710,7 +710,7 @@ void InputImpl::setTerminalConfig() //////////////////////////////////////////////////////////// void InputImpl::restoreTerminalConfig() { - std::scoped_lock lock(inputMutex); + std::lock_guard lock(inputMutex); initFileDescriptors(); tcsetattr(STDIN_FILENO, TCSANOW, &oldTerminalConfig); // restore terminal config diff --git a/src/SFML/Window/EglContext.cpp b/src/SFML/Window/EglContext.cpp index 1ac315a2..dfe4d7ba 100644 --- a/src/SFML/Window/EglContext.cpp +++ b/src/SFML/Window/EglContext.cpp @@ -59,7 +59,7 @@ EGLDisplay getInitializedDisplay() // On Android, its native activity handles this for us sf::priv::ActivityStates& states = sf::priv::getActivity(); - std::scoped_lock lock(states.mutex); + std::lock_guard lock(states.mutex); return states.display; @@ -133,8 +133,8 @@ EglContext::EglContext(EglContext* shared, #ifdef SFML_SYSTEM_ANDROID // On Android, we must save the created context - ActivityStates& states = getActivity(); - std::scoped_lock lock(states.mutex); + ActivityStates& states = getActivity(); + std::lock_guard lock(states.mutex); states.context = this; diff --git a/src/SFML/Window/GlContext.cpp b/src/SFML/Window/GlContext.cpp index ee1a82d2..bf49e972 100644 --- a/src/SFML/Window/GlContext.cpp +++ b/src/SFML/Window/GlContext.cpp @@ -241,10 +241,10 @@ struct TransientContext /////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - unsigned int referenceCount; - std::unique_ptr context; - std::optional> sharedContextLock; - bool useSharedContext; + unsigned int referenceCount; + std::unique_ptr context; + std::optional> sharedContextLock; + bool useSharedContext; }; // This per-thread variable tracks if and how a transient @@ -337,7 +337,7 @@ void GlContext::initResource() using GlContextImpl::sharedContext; // Protect from concurrent access - std::scoped_lock lock(mutex); + std::lock_guard lock(mutex); // If this is the very first resource, trigger the global context initialization if (resourceCount == 0) @@ -374,7 +374,7 @@ void GlContext::cleanupResource() using GlContextImpl::sharedContext; // Protect from concurrent access - std::scoped_lock lock(mutex); + std::lock_guard lock(mutex); // Decrement the resources counter --resourceCount; @@ -406,7 +406,7 @@ void GlContext::acquireTransientContext() using GlContextImpl::transientContext; // Protect from concurrent access - std::scoped_lock lock(mutex); + std::lock_guard lock(mutex); // If this is the first TransientContextLock on this thread // construct the state object @@ -425,7 +425,7 @@ void GlContext::releaseTransientContext() using GlContextImpl::transientContext; // Protect from concurrent access - std::scoped_lock lock(mutex); + std::lock_guard lock(mutex); // Make sure a matching acquireTransientContext() was called assert(transientContext); @@ -451,7 +451,7 @@ std::unique_ptr GlContext::create() // Make sure that there's an active context (context creation may need extensions, and thus a valid context) assert(sharedContext != nullptr); - std::scoped_lock lock(mutex); + std::lock_guard lock(mutex); std::unique_ptr context; @@ -484,7 +484,7 @@ std::unique_ptr GlContext::create(const ContextSettings& settings, co // Make sure that there's an active context (context creation may need extensions, and thus a valid context) assert(sharedContext != nullptr); - std::scoped_lock lock(mutex); + std::lock_guard lock(mutex); // If resourceCount is 1 we know that we are inside sf::Context or sf::Window // Only in this situation we allow the user to indirectly re-create the shared context as a core context @@ -535,7 +535,7 @@ std::unique_ptr GlContext::create(const ContextSettings& settings, co // Make sure that there's an active context (context creation may need extensions, and thus a valid context) assert(sharedContext != nullptr); - std::scoped_lock lock(mutex); + std::lock_guard lock(mutex); // If resourceCount is 1 we know that we are inside sf::Context or sf::Window // Only in this situation we allow the user to indirectly re-create the shared context as a core context @@ -586,7 +586,7 @@ bool GlContext::isExtensionAvailable(const char* name) //////////////////////////////////////////////////////////// GlFunctionPointer GlContext::getFunction(const char* name) { - std::scoped_lock lock(GlContextImpl::mutex); + std::lock_guard lock(GlContextImpl::mutex); return ContextType::getFunction(name); } @@ -641,7 +641,7 @@ bool GlContext::setActive(bool active) { if (this != currentContext) { - std::scoped_lock lock(mutex); + std::lock_guard lock(mutex); // Activate the context if (makeCurrent(true)) @@ -665,7 +665,7 @@ bool GlContext::setActive(bool active) { if (this == currentContext) { - std::scoped_lock lock(mutex); + std::lock_guard lock(mutex); // Deactivate the context if (makeCurrent(false)) diff --git a/src/SFML/Window/Unix/Display.cpp b/src/SFML/Window/Unix/Display.cpp index eddb8713..919d4553 100644 --- a/src/SFML/Window/Unix/Display.cpp +++ b/src/SFML/Window/Unix/Display.cpp @@ -55,7 +55,7 @@ namespace sf::priv //////////////////////////////////////////////////////////// Display* openDisplay() { - std::scoped_lock lock(mutex); + std::lock_guard lock(mutex); if (referenceCount == 0) { @@ -78,7 +78,7 @@ Display* openDisplay() //////////////////////////////////////////////////////////// void closeDisplay(Display* display) { - std::scoped_lock lock(mutex); + std::lock_guard lock(mutex); assert(display == sharedDisplay); @@ -90,7 +90,7 @@ void closeDisplay(Display* display) //////////////////////////////////////////////////////////// XIM openXim() { - std::scoped_lock lock(mutex); + std::lock_guard lock(mutex); assert(sharedDisplay != nullptr); @@ -128,7 +128,7 @@ XIM openXim() //////////////////////////////////////////////////////////// void closeXim(XIM xim) { - std::scoped_lock lock(mutex); + std::lock_guard lock(mutex); assert(xim == sharedXIM); diff --git a/src/SFML/Window/Unix/GlxContext.cpp b/src/SFML/Window/Unix/GlxContext.cpp index d59f45a7..bf3c03c3 100644 --- a/src/SFML/Window/Unix/GlxContext.cpp +++ b/src/SFML/Window/Unix/GlxContext.cpp @@ -94,8 +94,8 @@ public: } private: - std::scoped_lock m_lock{glxErrorMutex}; - ::Display* m_display; + std::lock_guard m_lock{glxErrorMutex}; + ::Display* m_display; int (*m_previousHandler)(::Display*, XErrorEvent*); }; } // namespace diff --git a/src/SFML/Window/Unix/WindowImplX11.cpp b/src/SFML/Window/Unix/WindowImplX11.cpp index 3ab400b8..4b502c6a 100644 --- a/src/SFML/Window/Unix/WindowImplX11.cpp +++ b/src/SFML/Window/Unix/WindowImplX11.cpp @@ -763,7 +763,7 @@ WindowImplX11::~WindowImplX11() closeDisplay(m_display); // Remove this window from the global list of windows (required for focus request) - std::scoped_lock lock(allWindowsMutex); + std::lock_guard lock(allWindowsMutex); allWindows.erase(std::find(allWindows.begin(), allWindows.end(), this)); } @@ -1217,7 +1217,7 @@ void WindowImplX11::requestFocus() bool sfmlWindowFocused = false; { - std::scoped_lock lock(allWindowsMutex); + std::lock_guard lock(allWindowsMutex); for (sf::priv::WindowImplX11* windowPtr : allWindows) { if (windowPtr->hasFocus()) @@ -1662,7 +1662,7 @@ void WindowImplX11::initialize() XFlush(m_display); // Add this window to the global list of windows (required for focus request) - std::scoped_lock lock(allWindowsMutex); + std::lock_guard lock(allWindowsMutex); allWindows.push_back(this); } diff --git a/src/SFML/Window/Win32/WglContext.cpp b/src/SFML/Window/Win32/WglContext.cpp index 788f1419..d1382034 100644 --- a/src/SFML/Window/Win32/WglContext.cpp +++ b/src/SFML/Window/Win32/WglContext.cpp @@ -675,7 +675,7 @@ void WglContext::createContext(WglContext* shared) if (sharedContext) { static std::recursive_mutex mutex; - std::scoped_lock lock(mutex); + std::lock_guard lock(mutex); if (WglContextImpl::currentContext == shared) { @@ -747,7 +747,7 @@ void WglContext::createContext(WglContext* shared) { // wglShareLists doesn't seem to be thread-safe static std::recursive_mutex mutex; - std::scoped_lock lock(mutex); + std::lock_guard lock(mutex); if (WglContextImpl::currentContext == shared) {