Skip to content

Commit

Permalink
Use 'std::optional' in 'transientContext'
Browse files Browse the repository at this point in the history
  • Loading branch information
vittorioromeo authored and ChrisThrasher committed Mar 15, 2023
1 parent 33e9665 commit 641cf54
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/SFML/Window/GlContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ struct TransientContext
{
if (resourceCount == 0)
{
context = std::make_unique<sf::Context>();
context.emplace();
}
else if (!currentContext)
{
Expand Down Expand Up @@ -239,14 +239,14 @@ struct TransientContext
// Member data
////////////////////////////////////////////////////////////
unsigned int referenceCount{};
std::unique_ptr<sf::Context> context;
std::optional<sf::Context> context;
std::optional<std::lock_guard<std::recursive_mutex>> 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> transientContext;
thread_local std::optional<TransientContext> transientContext;

// Supported OpenGL extensions
std::vector<std::string> extensions;
Expand Down Expand Up @@ -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<TransientContext>();
if (!transientContext.has_value())
transientContext.emplace();

// Increase the reference count
++transientContext->referenceCount;
Expand All @@ -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;
Expand Down

0 comments on commit 641cf54

Please sign in to comment.