From 641cf54cc34a91ebf57d43b2400ac6436c47b313 Mon Sep 17 00:00:00 2001 From: Vittorio Romeo Date: Wed, 15 Mar 2023 01:35:07 +0100 Subject: [PATCH] Use 'std::optional' in 'transientContext' --- src/SFML/Window/GlContext.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/SFML/Window/GlContext.cpp b/src/SFML/Window/GlContext.cpp index f5e0e661..cb2b2236 100644 --- a/src/SFML/Window/GlContext.cpp +++ b/src/SFML/Window/GlContext.cpp @@ -203,7 +203,7 @@ struct TransientContext { if (resourceCount == 0) { - context = std::make_unique(); + context.emplace(); } else if (!currentContext) { @@ -239,14 +239,14 @@ struct TransientContext // Member data //////////////////////////////////////////////////////////// unsigned int referenceCount{}; - std::unique_ptr context; + std::optional context; std::optional> sharedContextLock; bool useSharedContext{}; }; // This per-thread variable tracks if and how a transient // context is currently being used on the current thread -thread_local std::unique_ptr transientContext; +thread_local std::optional transientContext; // Supported OpenGL extensions std::vector extensions; @@ -408,8 +408,8 @@ void GlContext::acquireTransientContext() // If this is the first TransientContextLock on this thread // construct the state object - if (!transientContext) - transientContext = std::make_unique(); + if (!transientContext.has_value()) + transientContext.emplace(); // Increase the reference count ++transientContext->referenceCount; @@ -426,7 +426,7 @@ void GlContext::releaseTransientContext() std::lock_guard lock(mutex); // Make sure a matching acquireTransientContext() was called - assert(transientContext); + assert(transientContext.has_value()); // Decrease the reference count --transientContext->referenceCount;