Changed from std::scoped_lock to std::lock_guard
This commit is contained in:
parent
cdce9f7147
commit
b2009e2fca
@ -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)
|
||||
{
|
||||
|
@ -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<std::vector<std::int16_t>::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<const char*>(packet.getData()) + 1,
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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<std::uint64_t, unsigned int>::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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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<int>(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<int>(finger))->second;
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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<int>(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<int>(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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -241,10 +241,10 @@ struct TransientContext
|
||||
///////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int referenceCount;
|
||||
std::unique_ptr<sf::Context> context;
|
||||
std::optional<std::scoped_lock<std::recursive_mutex>> sharedContextLock;
|
||||
bool useSharedContext;
|
||||
unsigned int referenceCount;
|
||||
std::unique_ptr<sf::Context> context;
|
||||
std::optional<std::lock_guard<std::recursive_mutex>> 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> 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<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)
|
||||
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> 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))
|
||||
|
@ -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);
|
||||
|
||||
|
@ -94,8 +94,8 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
std::scoped_lock<std::recursive_mutex> m_lock{glxErrorMutex};
|
||||
::Display* m_display;
|
||||
std::lock_guard<std::recursive_mutex> m_lock{glxErrorMutex};
|
||||
::Display* m_display;
|
||||
int (*m_previousHandler)(::Display*, XErrorEvent*);
|
||||
};
|
||||
} // namespace
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user