@@ -46,16 +46,14 @@ void Registry::registerContext(const glbinding::ContextHandle contextId, const g
4646 globjects::debug () << " OpenGL context " << contextId << " is already registered" ;
4747 }
4848
49- g_mutex.lock ();
49+ std::lock_guard<std::recursive_mutex> lock (g_mutex);
50+
5051 auto it = s_registries.find (sharedContextId);
5152 assert (it != s_registries.end ());
52- g_mutex.unlock ();
5353
5454 Registry * registry = new Registry (it->second );
5555
56- g_mutex.lock ();
5756 s_registries[contextId] = registry;
58- g_mutex.unlock ();
5957
6058 t_currentRegistry = registry;
6159 // registry->initialize();
@@ -73,13 +71,11 @@ void Registry::setCurrentContext(const glbinding::ContextHandle contextId)
7371
7472bool Registry::isCurrentContext (glbinding::ContextHandle contextId)
7573{
76- g_mutex. lock ();
74+ std::lock_guard<std::recursive_mutex> lock (g_mutex );
7775
7876 const auto it = s_registries.find (contextId);
7977 const auto result = it != s_registries.end () && it->second == t_currentRegistry;
8078
81- g_mutex.unlock ();
82-
8379 return result;
8480}
8581
@@ -92,13 +88,13 @@ void Registry::deregisterContext(const glbinding::ContextHandle contextId)
9288 return ;
9389 }
9490
95- g_mutex.lock ();
96- delete s_registries[contextId];
97- g_mutex.unlock ();
91+ {
92+ std::lock_guard<std::recursive_mutex> lock (g_mutex);
9893
99- g_mutex.lock ();
100- s_registries[contextId] = nullptr ;
101- g_mutex.unlock ();
94+ delete s_registries[contextId];
95+
96+ s_registries[contextId] = nullptr ;
97+ }
10298
10399 t_currentRegistry = nullptr ;
104100}
@@ -112,33 +108,28 @@ Registry & Registry::current()
112108
113109bool Registry::isContextRegistered (const glbinding::ContextHandle contextId)
114110{
115- g_mutex.lock ();
111+ std::lock_guard<std::recursive_mutex> lock (g_mutex);
112+
116113 bool found = s_registries.find (contextId) != s_registries.end ();
117- g_mutex.unlock ();
118114
119115 return found;
120116}
121117
122118void Registry::setCurrentRegistry (const glbinding::ContextHandle contextId)
123119{
124- g_mutex.lock ();
120+ std::lock_guard<std::recursive_mutex> lock (g_mutex);
121+
125122 auto it = s_registries.find (contextId);
126123
127124 if (it != s_registries.end ())
128125 {
129126 t_currentRegistry = it->second ;
130-
131- g_mutex.unlock ();
132127 }
133128 else
134129 {
135- g_mutex.unlock ();
136-
137130 Registry * registry = new Registry ();
138131
139- g_mutex.lock ();
140132 s_registries[contextId] = registry;
141- g_mutex.unlock ();
142133
143134 t_currentRegistry = registry;
144135 registry->initialize ();
0 commit comments