Changed from std::scoped_lock to std::lock_guard

This commit is contained in:
Jim-Marsden 2023-01-10 20:43:38 -08:00 committed by Chris Thrasher
parent cdce9f7147
commit b2009e2fca
22 changed files with 112 additions and 112 deletions

View File

@ -224,7 +224,7 @@ int main()
if (prerequisitesSupported) if (prerequisitesSupported)
{ {
{ {
std::scoped_lock lock(workQueueMutex); std::lock_guard lock(workQueueMutex);
// Don't bother updating/drawing the VertexBuffer while terrain is being regenerated // Don't bother updating/drawing the VertexBuffer while terrain is being regenerated
if (!pendingWorkCount) if (!pendingWorkCount)
@ -267,7 +267,7 @@ int main()
// Shut down our thread pool // Shut down our thread pool
{ {
std::scoped_lock lock(workQueueMutex); std::lock_guard lock(workQueueMutex);
workPending = false; workPending = false;
} }
@ -581,7 +581,7 @@ void threadFunction()
// Check if there are new work items in the queue // Check if there are new work items in the queue
{ {
std::scoped_lock lock(workQueueMutex); std::lock_guard lock(workQueueMutex);
if (!workPending) if (!workPending)
return; return;
@ -604,7 +604,7 @@ void threadFunction()
processWorkItem(vertices, workItem); processWorkItem(vertices, workItem);
{ {
std::scoped_lock lock(workQueueMutex); std::lock_guard lock(workQueueMutex);
--pendingWorkCount; --pendingWorkCount;
} }
@ -626,7 +626,7 @@ void generateTerrain(sf::Vertex* buffer)
for (;;) for (;;)
{ {
{ {
std::scoped_lock lock(workQueueMutex); std::lock_guard lock(workQueueMutex);
if (workQueue.empty()) if (workQueue.empty())
break; break;
@ -637,7 +637,7 @@ void generateTerrain(sf::Vertex* buffer)
// Queue all the new work items // Queue all the new work items
{ {
std::scoped_lock lock(workQueueMutex); std::lock_guard lock(workQueueMutex);
for (unsigned int i = 0; i < blockCount; ++i) for (unsigned int i = 0; i < blockCount; ++i)
{ {

View File

@ -81,7 +81,7 @@ private:
// Copy samples into a local buffer to avoid synchronization problems // Copy samples into a local buffer to avoid synchronization problems
// (don't forget that we run in two separate threads) // (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<std::vector<std::int16_t>::difference_type>(m_offset), m_tempBuffer.assign(m_samples.begin() + static_cast<std::vector<std::int16_t>::difference_type>(m_offset),
m_samples.end()); m_samples.end());
} }
@ -130,8 +130,8 @@ private:
// Don't forget that the other thread can access the sample array at any time // 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) // (so we protect any operation on it with the mutex)
{ {
std::scoped_lock lock(m_mutex); std::lock_guard lock(m_mutex);
std::size_t oldSize = m_samples.size(); std::size_t oldSize = m_samples.size();
m_samples.resize(oldSize + sampleCount); m_samples.resize(oldSize + sampleCount);
std::memcpy(&(m_samples[oldSize]), std::memcpy(&(m_samples[oldSize]),
static_cast<const char*>(packet.getData()) + 1, static_cast<const char*>(packet.getData()) + 1,

View File

@ -51,7 +51,7 @@ namespace sf
AlResource::AlResource() AlResource::AlResource()
{ {
// Protect from concurrent access // 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 this is the very first resource, trigger the global device initialization
if (count == 0) if (count == 0)
@ -66,7 +66,7 @@ AlResource::AlResource()
AlResource::~AlResource() AlResource::~AlResource()
{ {
// Protect from concurrent access // Protect from concurrent access
std::scoped_lock lock(mutex); std::lock_guard lock(mutex);
// Decrement the resources counter // Decrement the resources counter
--count; --count;

View File

@ -176,7 +176,7 @@ void Music::setLoopPoints(TimeSpan timePoints)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool Music::onGetData(SoundStream::Chunk& data) 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::size_t toFill = m_samples.size();
std::uint64_t currentOffset = m_file.getSampleOffset(); std::uint64_t currentOffset = m_file.getSampleOffset();
@ -202,7 +202,7 @@ bool Music::onGetData(SoundStream::Chunk& data)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Music::onSeek(Time timeOffset) void Music::onSeek(Time timeOffset)
{ {
std::scoped_lock lock(m_mutex); std::lock_guard lock(m_mutex);
m_file.seek(timeOffset); m_file.seek(timeOffset);
} }
@ -211,8 +211,8 @@ void Music::onSeek(Time timeOffset)
std::int64_t Music::onLoop() std::int64_t Music::onLoop()
{ {
// Called by underlying SoundStream so we can determine where to loop. // Called by underlying SoundStream so we can determine where to loop.
std::scoped_lock lock(m_mutex); std::lock_guard lock(m_mutex);
std::uint64_t currentOffset = m_file.getSampleOffset(); std::uint64_t currentOffset = m_file.getSampleOffset();
if (getLoop() && (m_loopSpan.length != 0) && (currentOffset == m_loopSpan.offset + m_loopSpan.length)) 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 // Looping is enabled, and either we're at the loop end, or we're at the EOF

View File

@ -67,7 +67,7 @@ void SoundStream::initialize(unsigned int channelCount, unsigned int sampleRate)
m_samplesProcessed = 0; m_samplesProcessed = 0;
{ {
std::scoped_lock lock(m_threadMutex); std::lock_guard lock(m_threadMutex);
m_isStreaming = false; m_isStreaming = false;
} }
@ -99,7 +99,7 @@ void SoundStream::play()
Status threadStartState = Stopped; Status threadStartState = Stopped;
{ {
std::scoped_lock lock(m_threadMutex); std::lock_guard lock(m_threadMutex);
isStreaming = m_isStreaming; isStreaming = m_isStreaming;
threadStartState = m_threadStartState; threadStartState = m_threadStartState;
@ -109,7 +109,7 @@ void SoundStream::play()
if (isStreaming && (threadStartState == Paused)) if (isStreaming && (threadStartState == Paused))
{ {
// If the sound is paused, resume it // If the sound is paused, resume it
std::scoped_lock lock(m_threadMutex); std::lock_guard lock(m_threadMutex);
m_threadStartState = Playing; m_threadStartState = Playing;
alCheck(alSourcePlay(m_source)); alCheck(alSourcePlay(m_source));
return; return;
@ -136,7 +136,7 @@ void SoundStream::pause()
{ {
// Handle pause() being called before the thread has started // Handle pause() being called before the thread has started
{ {
std::scoped_lock lock(m_threadMutex); std::lock_guard lock(m_threadMutex);
if (!m_isStreaming) if (!m_isStreaming)
return; return;
@ -181,7 +181,7 @@ SoundStream::Status SoundStream::getStatus() const
// To compensate for the lag between play() and alSourceplay() // To compensate for the lag between play() and alSourceplay()
if (status == Stopped) if (status == Stopped)
{ {
std::scoped_lock lock(m_threadMutex); std::lock_guard lock(m_threadMutex);
if (m_isStreaming) if (m_isStreaming)
status = m_threadStartState; status = m_threadStartState;
@ -265,7 +265,7 @@ void SoundStream::streamData()
bool requestStop = false; bool requestStop = false;
{ {
std::scoped_lock lock(m_threadMutex); std::lock_guard lock(m_threadMutex);
// Check if the thread was launched Stopped // Check if the thread was launched Stopped
if (m_threadStartState == Stopped) if (m_threadStartState == Stopped)
@ -287,7 +287,7 @@ void SoundStream::streamData()
alCheck(alSourcePlay(m_source)); alCheck(alSourcePlay(m_source));
{ {
std::scoped_lock lock(m_threadMutex); std::lock_guard lock(m_threadMutex);
// Check if the thread was launched Paused // Check if the thread was launched Paused
if (m_threadStartState == Paused) if (m_threadStartState == Paused)
@ -297,7 +297,7 @@ void SoundStream::streamData()
for (;;) for (;;)
{ {
{ {
std::scoped_lock lock(m_threadMutex); std::lock_guard lock(m_threadMutex);
if (!m_isStreaming) if (!m_isStreaming)
break; break;
} }
@ -313,7 +313,7 @@ void SoundStream::streamData()
else else
{ {
// End streaming // End streaming
std::scoped_lock lock(m_threadMutex); std::lock_guard lock(m_threadMutex);
m_isStreaming = false; m_isStreaming = false;
} }
} }
@ -357,7 +357,7 @@ void SoundStream::streamData()
<< "and initialize() has been called correctly" << std::endl; << "and initialize() has been called correctly" << std::endl;
// Abort streaming (exit main loop) // Abort streaming (exit main loop)
std::scoped_lock lock(m_threadMutex); std::lock_guard lock(m_threadMutex);
m_isStreaming = false; m_isStreaming = false;
requestStop = true; requestStop = true;
break; break;
@ -380,7 +380,7 @@ void SoundStream::streamData()
if (alGetLastError() != AL_NO_ERROR) if (alGetLastError() != AL_NO_ERROR)
{ {
// Abort streaming (exit main loop) // Abort streaming (exit main loop)
std::scoped_lock lock(m_threadMutex); std::lock_guard lock(m_threadMutex);
m_isStreaming = false; m_isStreaming = false;
break; break;
} }
@ -500,7 +500,7 @@ void SoundStream::clearQueue()
void SoundStream::launchStreamingThread(Status threadStartState) void SoundStream::launchStreamingThread(Status threadStartState)
{ {
{ {
std::scoped_lock lock(m_threadMutex); std::lock_guard lock(m_threadMutex);
m_isStreaming = true; m_isStreaming = true;
m_threadStartState = threadStartState; m_threadStartState = threadStartState;
} }
@ -515,7 +515,7 @@ void SoundStream::awaitStreamingThread()
{ {
// Request the thread to join // Request the thread to join
{ {
std::scoped_lock lock(m_threadMutex); std::lock_guard lock(m_threadMutex);
m_isStreaming = false; m_isStreaming = false;
} }

View File

@ -55,7 +55,7 @@ std::recursive_mutex mutex;
// tracking the currently active RenderTarget within a given context // tracking the currently active RenderTarget within a given context
std::uint64_t getUniqueId() 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" 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 // 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(); std::uint64_t contextId = Context::getActiveContextId();

View File

@ -84,7 +84,7 @@ void destroyStaleFBOs()
// Callback that is called every time a context is destroyed // Callback that is called every time a context is destroyed
void contextDestroyCallback(void* /*arg*/) void contextDestroyCallback(void* /*arg*/)
{ {
std::scoped_lock lock(mutex); std::lock_guard lock(mutex);
std::uint64_t contextId = sf::Context::getActiveContextId(); std::uint64_t contextId = sf::Context::getActiveContextId();
@ -117,7 +117,7 @@ namespace sf::priv
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
RenderTextureImplFBO::RenderTextureImplFBO() RenderTextureImplFBO::RenderTextureImplFBO()
{ {
std::scoped_lock lock(mutex); std::lock_guard lock(mutex);
// Register the context destruction callback // Register the context destruction callback
registerContextDestroyCallback(contextDestroyCallback, nullptr); registerContextDestroyCallback(contextDestroyCallback, nullptr);
@ -133,7 +133,7 @@ RenderTextureImplFBO::~RenderTextureImplFBO()
{ {
TransientContextLock contextLock; TransientContextLock contextLock;
std::scoped_lock lock(mutex); std::lock_guard lock(mutex);
// Remove the frame buffer mapping from the set of all active mappings // Remove the frame buffer mapping from the set of all active mappings
frameBuffers.erase(&m_frameBuffers); 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 // Insert the FBO into our map
m_frameBuffers.emplace(Context::getActiveContextId(), frameBuffer); 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 // Insert the FBO into our map
m_multisampleFrameBuffers.emplace(Context::getActiveContextId(), multisampleFrameBuffer); 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 // If none is found, there is no FBO corresponding to the
// currently active context so we will have to create a new FBO // 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<std::uint64_t, unsigned int>::iterator it; std::unordered_map<std::uint64_t, unsigned int>::iterator it;
@ -624,7 +624,7 @@ void RenderTextureImplFBO::updateTexture(unsigned int)
{ {
std::uint64_t contextId = Context::getActiveContextId(); std::uint64_t contextId = Context::getActiveContextId();
std::scoped_lock lock(mutex); std::lock_guard lock(mutex);
auto frameBufferIt = m_frameBuffers.find(contextId); auto frameBufferIt = m_frameBuffers.find(contextId);
auto multisampleIt = m_multisampleFrameBuffers.find(contextId); auto multisampleIt = m_multisampleFrameBuffers.find(contextId);

View File

@ -745,7 +745,7 @@ void Shader::bind(const Shader* shader)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool Shader::isAvailable() bool Shader::isAvailable()
{ {
std::scoped_lock lock(isAvailableMutex); std::lock_guard lock(isAvailableMutex);
static bool checked = false; static bool checked = false;
static bool available = false; static bool available = false;
@ -770,7 +770,7 @@ bool Shader::isAvailable()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool Shader::isGeometryAvailable() bool Shader::isGeometryAvailable()
{ {
std::scoped_lock lock(isAvailableMutex); std::lock_guard lock(isAvailableMutex);
static bool checked = false; static bool checked = false;
static bool available = false; static bool available = false;

View File

@ -52,7 +52,7 @@ std::recursive_mutex maximumSizeMutex;
// is used for states cache (see RenderTarget) // is used for states cache (see RenderTarget)
std::uint64_t getUniqueId() 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" 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() unsigned int Texture::getMaximumSize()
{ {
std::scoped_lock lock(TextureImpl::maximumSizeMutex); std::lock_guard lock(TextureImpl::maximumSizeMutex);
static bool checked = false; static bool checked = false;
static GLint size = 0; static GLint size = 0;

View File

@ -336,7 +336,7 @@ VertexBuffer::Usage VertexBuffer::getUsage() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool VertexBuffer::isAvailable() bool VertexBuffer::isAvailable()
{ {
std::scoped_lock lock(VertexBufferImpl::isAvailableMutex); std::lock_guard lock(VertexBufferImpl::isAvailableMutex);
static bool checked = false; static bool checked = false;
static bool available = false; static bool available = false;

View File

@ -94,7 +94,7 @@ ActivityStates* retrieveStates(ANativeActivity* activity)
static void initializeMain(ActivityStates* states) static void initializeMain(ActivityStates* states)
{ {
// Protect from concurrent access // 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 // Prepare and share the looper to be read later
ALooper* looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); ALooper* looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS);
@ -118,7 +118,7 @@ static void initializeMain(ActivityStates* states)
static void terminateMain(ActivityStates* states) static void terminateMain(ActivityStates* states)
{ {
// Protect from concurrent access // 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 // The main thread has finished, we must explicitly ask the activity to finish
states->mainOver = true; states->mainOver = true;
@ -139,7 +139,7 @@ void* main(ActivityStates* states)
terminateMain(states); terminateMain(states);
{ {
std::scoped_lock lock(states->mutex); std::lock_guard lock(states->mutex);
states->terminated = true; states->terminated = true;
} }
@ -261,7 +261,7 @@ static void onResume(ANativeActivity* activity)
{ {
// Retrieve our activity states from the activity instance // Retrieve our activity states from the activity instance
sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity); sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity);
std::scoped_lock lock(states->mutex); std::lock_guard lock(states->mutex);
if (states->fullscreen) if (states->fullscreen)
goToFullscreenMode(activity); goToFullscreenMode(activity);
@ -279,7 +279,7 @@ static void onPause(ANativeActivity* activity)
{ {
// Retrieve our activity states from the activity instance // Retrieve our activity states from the activity instance
sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity); 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 // Send an event to warn people the activity has been paused
sf::Event event; sf::Event event;
@ -303,7 +303,7 @@ static void onDestroy(ANativeActivity* activity)
// Send an event to warn people the activity is being destroyed // 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 // If the main thread hasn't yet finished, send the event and wait for
// it to finish. // it to finish.
@ -345,7 +345,7 @@ static void onDestroy(ANativeActivity* activity)
static void onNativeWindowCreated(ANativeActivity* activity, ANativeWindow* window) static void onNativeWindowCreated(ANativeActivity* activity, ANativeWindow* window)
{ {
sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity); sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity);
std::scoped_lock lock(states->mutex); std::lock_guard lock(states->mutex);
// Update the activity states // Update the activity states
states->window = window; states->window = window;
@ -370,7 +370,7 @@ static void onNativeWindowCreated(ANativeActivity* activity, ANativeWindow* wind
static void onNativeWindowDestroyed(ANativeActivity* activity, ANativeWindow* /* window */) static void onNativeWindowDestroyed(ANativeActivity* activity, ANativeWindow* /* window */)
{ {
sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity); sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity);
std::scoped_lock lock(states->mutex); std::lock_guard lock(states->mutex);
// Update the activity states // Update the activity states
states->window = nullptr; states->window = nullptr;
@ -411,7 +411,7 @@ static void onInputQueueCreated(ANativeActivity* activity, AInputQueue* queue)
// Attach the input 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); AInputQueue_attachLooper(queue, states->looper, 1, states->processEvent, nullptr);
states->inputQueue = queue; states->inputQueue = queue;
@ -427,7 +427,7 @@ static void onInputQueueDestroyed(ANativeActivity* activity, AInputQueue* queue)
// Detach the input queue // Detach the input queue
{ {
std::scoped_lock lock(states->mutex); std::lock_guard lock(states->mutex);
AInputQueue_detachLooper(queue); AInputQueue_detachLooper(queue);
states->inputQueue = nullptr; states->inputQueue = nullptr;
@ -448,7 +448,7 @@ static void onContentRectChanged(ANativeActivity* activity, const ARect* /* rect
{ {
// Retrieve our activity states from the activity instance // Retrieve our activity states from the activity instance
sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity); 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 // Make sure the window still exists before we access the dimensions on it
if (states->window != nullptr) if (states->window != nullptr)

View File

@ -38,8 +38,8 @@ namespace sf::priv
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
ResourceStream::ResourceStream(const std::filesystem::path& filename) : m_file(nullptr) ResourceStream::ResourceStream(const std::filesystem::path& filename) : m_file(nullptr)
{ {
ActivityStates& states = getActivity(); ActivityStates& states = getActivity();
std::scoped_lock lock(states.mutex); std::lock_guard lock(states.mutex);
m_file = AAssetManager_open(states.activity->assetManager, filename.c_str(), AASSET_MODE_UNKNOWN); m_file = AAssetManager_open(states.activity->assetManager, filename.c_str(), AASSET_MODE_UNKNOWN);
} }

View File

@ -49,8 +49,8 @@ void InputImpl::setVirtualKeyboardVisible(bool visible)
{ {
// todo: Check if the window is active // todo: Check if the window is active
ActivityStates& states = getActivity(); ActivityStates& states = getActivity();
std::scoped_lock lock(states.mutex); std::lock_guard lock(states.mutex);
// Initializes JNI // Initializes JNI
jint lFlags = 0; jint lFlags = 0;
@ -133,8 +133,8 @@ bool InputImpl::isMouseButtonPressed(Mouse::Button button)
{ {
ALooper_pollAll(0, nullptr, nullptr, nullptr); ALooper_pollAll(0, nullptr, nullptr, nullptr);
ActivityStates& states = getActivity(); ActivityStates& states = getActivity();
std::scoped_lock lock(states.mutex); std::lock_guard lock(states.mutex);
return states.isButtonPressed[button]; return states.isButtonPressed[button];
} }
@ -145,8 +145,8 @@ Vector2i InputImpl::getMousePosition()
{ {
ALooper_pollAll(0, nullptr, nullptr, nullptr); ALooper_pollAll(0, nullptr, nullptr, nullptr);
ActivityStates& states = getActivity(); ActivityStates& states = getActivity();
std::scoped_lock lock(states.mutex); std::lock_guard lock(states.mutex);
return states.mousePosition; return states.mousePosition;
} }
@ -178,8 +178,8 @@ bool InputImpl::isTouchDown(unsigned int finger)
{ {
ALooper_pollAll(0, nullptr, nullptr, nullptr); ALooper_pollAll(0, nullptr, nullptr, nullptr);
ActivityStates& states = getActivity(); ActivityStates& states = getActivity();
std::scoped_lock lock(states.mutex); std::lock_guard lock(states.mutex);
return states.touchEvents.find(static_cast<int>(finger)) != states.touchEvents.end(); return states.touchEvents.find(static_cast<int>(finger)) != states.touchEvents.end();
} }
@ -190,8 +190,8 @@ Vector2i InputImpl::getTouchPosition(unsigned int finger)
{ {
ALooper_pollAll(0, nullptr, nullptr, nullptr); ALooper_pollAll(0, nullptr, nullptr, nullptr);
ActivityStates& states = getActivity(); ActivityStates& states = getActivity();
std::scoped_lock lock(states.mutex); std::lock_guard lock(states.mutex);
return states.touchEvents.find(static_cast<int>(finger))->second; return states.touchEvents.find(static_cast<int>(finger))->second;
} }

View File

@ -52,7 +52,7 @@ VideoMode VideoModeImpl::getDesktopMode()
{ {
// Get the activity states // Get the activity states
priv::ActivityStates& states = priv::getActivity(); priv::ActivityStates& states = priv::getActivity();
std::scoped_lock lock(states.mutex); std::lock_guard lock(states.mutex);
return VideoMode(Vector2u(states.screenSize)); return VideoMode(Vector2u(states.screenSize));
} }

View File

@ -62,8 +62,8 @@ WindowImplAndroid::WindowImplAndroid(VideoMode mode,
const ContextSettings& /* settings */) : const ContextSettings& /* settings */) :
m_size(mode.size) m_size(mode.size)
{ {
ActivityStates& states = getActivity(); ActivityStates& states = getActivity();
std::scoped_lock lock(states.mutex); std::lock_guard lock(states.mutex);
if (style & Style::Fullscreen) if (style & Style::Fullscreen)
states.fullscreen = true; states.fullscreen = true;
@ -88,8 +88,8 @@ WindowImplAndroid::~WindowImplAndroid()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
WindowHandle WindowImplAndroid::getSystemHandle() const WindowHandle WindowImplAndroid::getSystemHandle() const
{ {
ActivityStates& states = getActivity(); ActivityStates& states = getActivity();
std::scoped_lock lock(states.mutex); std::lock_guard lock(states.mutex);
return states.window; return states.window;
} }
@ -101,8 +101,8 @@ void WindowImplAndroid::processEvents()
// Process incoming OS events // Process incoming OS events
ALooper_pollAll(0, nullptr, nullptr, nullptr); ALooper_pollAll(0, nullptr, nullptr, nullptr);
ActivityStates& states = getActivity(); ActivityStates& states = getActivity();
std::scoped_lock lock(states.mutex); std::lock_guard lock(states.mutex);
if (m_windowBeingCreated) if (m_windowBeingCreated)
{ {
@ -239,8 +239,8 @@ void WindowImplAndroid::forwardEvent(const Event& event)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
int WindowImplAndroid::processEvent(int /* fd */, int /* events */, void* /* data */) int WindowImplAndroid::processEvent(int /* fd */, int /* events */, void* /* data */)
{ {
ActivityStates& states = getActivity(); ActivityStates& states = getActivity();
std::scoped_lock lock(states.mutex); std::lock_guard lock(states.mutex);
AInputEvent* _event = nullptr; AInputEvent* _event = nullptr;
@ -693,8 +693,8 @@ Keyboard::Key WindowImplAndroid::androidKeyToSF(std::int32_t key)
int WindowImplAndroid::getUnicode(AInputEvent* event) int WindowImplAndroid::getUnicode(AInputEvent* event)
{ {
// Retrieve activity states // Retrieve activity states
ActivityStates& states = getActivity(); ActivityStates& states = getActivity();
std::scoped_lock lock(states.mutex); std::lock_guard lock(states.mutex);
// Initializes JNI // Initializes JNI
jint lResult; jint lResult;

View File

@ -352,7 +352,7 @@ void processSlots()
bool eventProcess(sf::Event& event) bool eventProcess(sf::Event& event)
{ {
std::scoped_lock lock(inputMutex); std::lock_guard lock(inputMutex);
// Ensure that we are initialized // Ensure that we are initialized
initFileDescriptors(); initFileDescriptors();
@ -565,7 +565,7 @@ namespace sf::priv
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool InputImpl::isKeyPressed(Keyboard::Key key) bool InputImpl::isKeyPressed(Keyboard::Key key)
{ {
std::scoped_lock lock(inputMutex); std::lock_guard lock(inputMutex);
if ((key < 0) || (key >= static_cast<int>(keyMap.size()))) if ((key < 0) || (key >= static_cast<int>(keyMap.size())))
return false; return false;
@ -584,7 +584,7 @@ void InputImpl::setVirtualKeyboardVisible(bool /*visible*/)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool InputImpl::isMouseButtonPressed(Mouse::Button button) bool InputImpl::isMouseButtonPressed(Mouse::Button button)
{ {
std::scoped_lock lock(inputMutex); std::lock_guard lock(inputMutex);
if ((button < 0) || (button >= static_cast<int>(mouseMap.size()))) if ((button < 0) || (button >= static_cast<int>(mouseMap.size())))
return false; return false;
@ -596,7 +596,7 @@ bool InputImpl::isMouseButtonPressed(Mouse::Button button)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vector2i InputImpl::getMousePosition() Vector2i InputImpl::getMousePosition()
{ {
std::scoped_lock lock(inputMutex); std::lock_guard lock(inputMutex);
return mousePos; return mousePos;
} }
@ -611,7 +611,7 @@ Vector2i InputImpl::getMousePosition(const WindowBase& /*relativeTo*/)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void InputImpl::setMousePosition(const Vector2i& position) void InputImpl::setMousePosition(const Vector2i& position)
{ {
std::scoped_lock lock(inputMutex); std::lock_guard lock(inputMutex);
mousePos = position; mousePos = position;
} }
@ -659,7 +659,7 @@ Vector2i InputImpl::getTouchPosition(unsigned int finger, const WindowBase& /*re
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool InputImpl::checkEvent(sf::Event& event) bool InputImpl::checkEvent(sf::Event& event)
{ {
std::scoped_lock lock(inputMutex); std::lock_guard lock(inputMutex);
if (!eventQueue.empty()) if (!eventQueue.empty())
{ {
event = eventQueue.front(); event = eventQueue.front();
@ -693,7 +693,7 @@ bool InputImpl::checkEvent(sf::Event& event)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void InputImpl::setTerminalConfig() void InputImpl::setTerminalConfig()
{ {
std::scoped_lock lock(inputMutex); std::lock_guard lock(inputMutex);
initFileDescriptors(); initFileDescriptors();
tcgetattr(STDIN_FILENO, &newTerminalConfig); // get current terminal config tcgetattr(STDIN_FILENO, &newTerminalConfig); // get current terminal config
@ -710,7 +710,7 @@ void InputImpl::setTerminalConfig()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void InputImpl::restoreTerminalConfig() void InputImpl::restoreTerminalConfig()
{ {
std::scoped_lock lock(inputMutex); std::lock_guard lock(inputMutex);
initFileDescriptors(); initFileDescriptors();
tcsetattr(STDIN_FILENO, TCSANOW, &oldTerminalConfig); // restore terminal config tcsetattr(STDIN_FILENO, TCSANOW, &oldTerminalConfig); // restore terminal config

View File

@ -59,7 +59,7 @@ EGLDisplay getInitializedDisplay()
// On Android, its native activity handles this for us // On Android, its native activity handles this for us
sf::priv::ActivityStates& states = sf::priv::getActivity(); sf::priv::ActivityStates& states = sf::priv::getActivity();
std::scoped_lock lock(states.mutex); std::lock_guard lock(states.mutex);
return states.display; return states.display;
@ -133,8 +133,8 @@ EglContext::EglContext(EglContext* shared,
#ifdef SFML_SYSTEM_ANDROID #ifdef SFML_SYSTEM_ANDROID
// On Android, we must save the created context // On Android, we must save the created context
ActivityStates& states = getActivity(); ActivityStates& states = getActivity();
std::scoped_lock lock(states.mutex); std::lock_guard lock(states.mutex);
states.context = this; states.context = this;

View File

@ -241,10 +241,10 @@ struct TransientContext
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned int referenceCount; unsigned int referenceCount;
std::unique_ptr<sf::Context> context; std::unique_ptr<sf::Context> context;
std::optional<std::scoped_lock<std::recursive_mutex>> sharedContextLock; std::optional<std::lock_guard<std::recursive_mutex>> sharedContextLock;
bool useSharedContext; bool useSharedContext;
}; };
// This per-thread variable tracks if and how a transient // This per-thread variable tracks if and how a transient
@ -337,7 +337,7 @@ void GlContext::initResource()
using GlContextImpl::sharedContext; using GlContextImpl::sharedContext;
// Protect from concurrent access // 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 this is the very first resource, trigger the global context initialization
if (resourceCount == 0) if (resourceCount == 0)
@ -374,7 +374,7 @@ void GlContext::cleanupResource()
using GlContextImpl::sharedContext; using GlContextImpl::sharedContext;
// Protect from concurrent access // Protect from concurrent access
std::scoped_lock lock(mutex); std::lock_guard lock(mutex);
// Decrement the resources counter // Decrement the resources counter
--resourceCount; --resourceCount;
@ -406,7 +406,7 @@ void GlContext::acquireTransientContext()
using GlContextImpl::transientContext; using GlContextImpl::transientContext;
// Protect from concurrent access // Protect from concurrent access
std::scoped_lock lock(mutex); std::lock_guard lock(mutex);
// If this is the first TransientContextLock on this thread // If this is the first TransientContextLock on this thread
// construct the state object // construct the state object
@ -425,7 +425,7 @@ void GlContext::releaseTransientContext()
using GlContextImpl::transientContext; using GlContextImpl::transientContext;
// Protect from concurrent access // Protect from concurrent access
std::scoped_lock lock(mutex); std::lock_guard lock(mutex);
// Make sure a matching acquireTransientContext() was called // Make sure a matching acquireTransientContext() was called
assert(transientContext); assert(transientContext);
@ -451,7 +451,7 @@ std::unique_ptr<GlContext> GlContext::create()
// Make sure that there's an active context (context creation may need extensions, and thus a valid context) // Make sure that there's an active context (context creation may need extensions, and thus a valid context)
assert(sharedContext != nullptr); assert(sharedContext != nullptr);
std::scoped_lock lock(mutex); std::lock_guard lock(mutex);
std::unique_ptr<GlContext> context; std::unique_ptr<GlContext> context;
@ -484,7 +484,7 @@ std::unique_ptr<GlContext> GlContext::create(const ContextSettings& settings, co
// Make sure that there's an active context (context creation may need extensions, and thus a valid context) // Make sure that there's an active context (context creation may need extensions, and thus a valid context)
assert(sharedContext != nullptr); 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 // 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 // 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> GlContext::create(const ContextSettings& settings, co
// Make sure that there's an active context (context creation may need extensions, and thus a valid context) // Make sure that there's an active context (context creation may need extensions, and thus a valid context)
assert(sharedContext != nullptr); 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 // 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 // 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) GlFunctionPointer GlContext::getFunction(const char* name)
{ {
std::scoped_lock lock(GlContextImpl::mutex); std::lock_guard lock(GlContextImpl::mutex);
return ContextType::getFunction(name); return ContextType::getFunction(name);
} }
@ -641,7 +641,7 @@ bool GlContext::setActive(bool active)
{ {
if (this != currentContext) if (this != currentContext)
{ {
std::scoped_lock lock(mutex); std::lock_guard lock(mutex);
// Activate the context // Activate the context
if (makeCurrent(true)) if (makeCurrent(true))
@ -665,7 +665,7 @@ bool GlContext::setActive(bool active)
{ {
if (this == currentContext) if (this == currentContext)
{ {
std::scoped_lock lock(mutex); std::lock_guard lock(mutex);
// Deactivate the context // Deactivate the context
if (makeCurrent(false)) if (makeCurrent(false))

View File

@ -55,7 +55,7 @@ namespace sf::priv
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Display* openDisplay() Display* openDisplay()
{ {
std::scoped_lock lock(mutex); std::lock_guard lock(mutex);
if (referenceCount == 0) if (referenceCount == 0)
{ {
@ -78,7 +78,7 @@ Display* openDisplay()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void closeDisplay(Display* display) void closeDisplay(Display* display)
{ {
std::scoped_lock lock(mutex); std::lock_guard lock(mutex);
assert(display == sharedDisplay); assert(display == sharedDisplay);
@ -90,7 +90,7 @@ void closeDisplay(Display* display)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
XIM openXim() XIM openXim()
{ {
std::scoped_lock lock(mutex); std::lock_guard lock(mutex);
assert(sharedDisplay != nullptr); assert(sharedDisplay != nullptr);
@ -128,7 +128,7 @@ XIM openXim()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void closeXim(XIM xim) void closeXim(XIM xim)
{ {
std::scoped_lock lock(mutex); std::lock_guard lock(mutex);
assert(xim == sharedXIM); assert(xim == sharedXIM);

View File

@ -94,8 +94,8 @@ public:
} }
private: private:
std::scoped_lock<std::recursive_mutex> m_lock{glxErrorMutex}; std::lock_guard<std::recursive_mutex> m_lock{glxErrorMutex};
::Display* m_display; ::Display* m_display;
int (*m_previousHandler)(::Display*, XErrorEvent*); int (*m_previousHandler)(::Display*, XErrorEvent*);
}; };
} // namespace } // namespace

View File

@ -763,7 +763,7 @@ WindowImplX11::~WindowImplX11()
closeDisplay(m_display); closeDisplay(m_display);
// Remove this window from the global list of windows (required for focus request) // 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)); allWindows.erase(std::find(allWindows.begin(), allWindows.end(), this));
} }
@ -1217,7 +1217,7 @@ void WindowImplX11::requestFocus()
bool sfmlWindowFocused = false; bool sfmlWindowFocused = false;
{ {
std::scoped_lock lock(allWindowsMutex); std::lock_guard lock(allWindowsMutex);
for (sf::priv::WindowImplX11* windowPtr : allWindows) for (sf::priv::WindowImplX11* windowPtr : allWindows)
{ {
if (windowPtr->hasFocus()) if (windowPtr->hasFocus())
@ -1662,7 +1662,7 @@ void WindowImplX11::initialize()
XFlush(m_display); XFlush(m_display);
// Add this window to the global list of windows (required for focus request) // 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); allWindows.push_back(this);
} }

View File

@ -675,7 +675,7 @@ void WglContext::createContext(WglContext* shared)
if (sharedContext) if (sharedContext)
{ {
static std::recursive_mutex mutex; static std::recursive_mutex mutex;
std::scoped_lock lock(mutex); std::lock_guard lock(mutex);
if (WglContextImpl::currentContext == shared) if (WglContextImpl::currentContext == shared)
{ {
@ -747,7 +747,7 @@ void WglContext::createContext(WglContext* shared)
{ {
// wglShareLists doesn't seem to be thread-safe // wglShareLists doesn't seem to be thread-safe
static std::recursive_mutex mutex; static std::recursive_mutex mutex;
std::scoped_lock lock(mutex); std::lock_guard lock(mutex);
if (WglContextImpl::currentContext == shared) if (WglContextImpl::currentContext == shared)
{ {