[glibmm] Use thread_local instead of Glib::Threads::Private.



commit 48f07f6fdca5511546afc4bc5917616e1fa1886a
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Nov 27 09:36:37 2015 +0100

    Use thread_local instead of Glib::Threads::Private.
    
    See https://bugzilla.gnome.org/show_bug.cgi?id=757674#c15

 glib/glibmm/dispatcher.cc       |   13 ++++++-------
 glib/glibmm/exceptionhandler.cc |    9 ++++-----
 2 files changed, 10 insertions(+), 12 deletions(-)
---
diff --git a/glib/glibmm/dispatcher.cc b/glib/glibmm/dispatcher.cc
index 198d525..3137270 100644
--- a/glib/glibmm/dispatcher.cc
+++ b/glib/glibmm/dispatcher.cc
@@ -18,7 +18,6 @@
  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#include <glibmm/threads.h>
 #include <glibmm/dispatcher.h>
 #include <glibmm/exceptionhandler.h>
 #include <glibmm/fileutils.h>
@@ -144,7 +143,7 @@ protected:
   explicit DispatchNotifier(const Glib::RefPtr<MainContext>& context);
 
 private:
-  static Glib::Threads::Private<DispatchNotifier> thread_specific_instance_;
+  static thread_local DispatchNotifier* thread_specific_instance_;
 
   std::set<const Dispatcher*>   deleted_dispatchers_;
 
@@ -167,7 +166,7 @@ private:
 /**** Glib::DispatchNotifier ***********************************************/
 
 // static
-Glib::Threads::Private<DispatchNotifier> DispatchNotifier::thread_specific_instance_;
+thread_local DispatchNotifier* DispatchNotifier::thread_specific_instance_ = nullptr;
 
 DispatchNotifier::DispatchNotifier(const Glib::RefPtr<MainContext>& context)
 :
@@ -270,12 +269,12 @@ void DispatchNotifier::create_pipe()
 DispatchNotifier* DispatchNotifier::reference_instance
   (const Glib::RefPtr<MainContext>& context, const Dispatcher* dispatcher)
 {
-  DispatchNotifier* instance = thread_specific_instance_.get();
+  DispatchNotifier* instance = thread_specific_instance_;
 
   if(!instance)
   {
     instance = new DispatchNotifier(context);
-    thread_specific_instance_.replace(instance);
+    thread_specific_instance_ = instance;
   }
   else
   {
@@ -303,7 +302,7 @@ DispatchNotifier* DispatchNotifier::reference_instance
 void DispatchNotifier::unreference_instance(
   DispatchNotifier* notifier, const Dispatcher* dispatcher)
 {
-  DispatchNotifier* const instance = thread_specific_instance_.get();
+  DispatchNotifier* const instance = thread_specific_instance_;
 
   // Yes, the notifier argument is only used to check for sanity.
   g_return_if_fail(instance == notifier);
@@ -321,7 +320,7 @@ void DispatchNotifier::unreference_instance(
     g_return_if_fail(instance->ref_count_ == 0); // could be < 0 if messed up
 
     // This causes deletion of the notifier object.
-    thread_specific_instance_.replace(nullptr);
+    thread_specific_instance_ = nullptr;
   }
 }
 
diff --git a/glib/glibmm/exceptionhandler.cc b/glib/glibmm/exceptionhandler.cc
index df0b53e..faad2a0 100644
--- a/glib/glibmm/exceptionhandler.cc
+++ b/glib/glibmm/exceptionhandler.cc
@@ -20,7 +20,6 @@
  */
 
 #include <glibmmconfig.h>
-#include <glibmm/threads.h>
 #include <glibmm/error.h>
 #include <glibmm/exceptionhandler.h>
 #include <glib.h>
@@ -35,7 +34,7 @@ typedef sigc::signal<void> HandlerList;
 
 // Each thread has its own list of exception handlers
 // to avoid thread synchronization problems.
-static Glib::Threads::Private<HandlerList> thread_specific_handler_list;
+static thread_local HandlerList* thread_specific_handler_list = nullptr;
 
 
 static void glibmm_exception_warning(const GError* error)
@@ -86,12 +85,12 @@ namespace Glib
 
 sigc::connection add_exception_handler(const sigc::slot<void>& slot)
 {
-  HandlerList* handler_list = thread_specific_handler_list.get();
+  HandlerList* handler_list = thread_specific_handler_list;
 
   if(!handler_list)
   {
     handler_list = new HandlerList();
-    thread_specific_handler_list.set(handler_list);
+    thread_specific_handler_list = handler_list;
   }
 
   handler_list->slots().push_front(slot);
@@ -114,7 +113,7 @@ void exception_handlers_invoke() noexcept
   // handled.  If there are no more handlers in the list and the exception
   // is still unhandled, call glibmm_unexpected_exception().
 
-  if(HandlerList *const handler_list = thread_specific_handler_list.get())
+  if(HandlerList *const handler_list = thread_specific_handler_list)
   {
     HandlerList::iterator pslot = handler_list->slots().begin();
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]