changeset 23057:bb7513d73673

move mutex classes inside octave namespace * oct-mutex.h, oct-mutex.cc (mutex, base_mutex, autolock, thread): Move classes inside octave namespace and rename from octave_mutex, octave_base_mutex, octave_autolock, and octave_thread, respectively. Change all uses.
author John W. Eaton <jwe@octave.org>
date Tue, 17 Jan 2017 11:19:44 -0500
parents 422757f6ddbc
children 5839d16828cb
files libgui/graphics/ObjectProxy.cc libinterp/corefcn/graphics.cc libinterp/corefcn/graphics.in.h libinterp/corefcn/interpreter.cc libinterp/corefcn/octave-link.cc libinterp/corefcn/octave-link.h liboctave/util/cmd-edit.cc liboctave/util/oct-mutex.cc liboctave/util/oct-mutex.h
diffstat 9 files changed, 246 insertions(+), 219 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/graphics/ObjectProxy.cc	Tue Jan 17 10:33:03 2017 -0500
+++ b/libgui/graphics/ObjectProxy.cc	Tue Jan 17 11:19:44 2017 -0500
@@ -84,7 +84,7 @@
   void
   ObjectProxy::update (int pId)
   {
-    if (octave_thread::is_octave_thread ())
+    if (octave::thread::is_thread ())
       emit sendUpdate (pId);
     else if (m_object)
       m_object->slotUpdate (pId);
--- a/libinterp/corefcn/graphics.cc	Tue Jan 17 10:33:03 2017 -0500
+++ b/libinterp/corefcn/graphics.cc	Tue Jan 17 11:19:44 2017 -0500
@@ -9690,7 +9690,7 @@
 gh_manager::do_execute_listener (const graphics_handle& h,
                                  const octave_value& l)
 {
-  if (octave_thread::is_octave_thread ())
+  if (octave::thread::is_thread ())
     gh_manager::execute_callback (h, l, octave_value ());
   else
     {
--- a/libinterp/corefcn/graphics.in.h	Tue Jan 17 10:33:03 2017 -0500
+++ b/libinterp/corefcn/graphics.in.h	Tue Jan 17 11:19:44 2017 -0500
@@ -6363,14 +6363,14 @@
   }
 
 public:
-  class auto_lock : public octave_autolock
+  class auto_lock : public octave::autolock
   {
   public:
     auto_lock (bool wait = true)
-      : octave_autolock (instance_ok ()
-                         ? instance->graphics_lock
-                         : octave_mutex (),
-                         wait)
+      : octave::autolock (instance_ok ()
+                          ? instance->graphics_lock
+                          : octave::mutex (),
+                          wait)
     { }
 
     // No copying!
@@ -6408,7 +6408,7 @@
   std::list<graphics_handle> figure_list;
 
   // The lock for accessing the graphics sytsem.
-  octave_mutex graphics_lock;
+  octave::mutex graphics_lock;
 
   // The list of events queued by graphics toolkits.
   std::list<graphics_event> event_queue;
--- a/libinterp/corefcn/interpreter.cc	Tue Jan 17 10:33:03 2017 -0500
+++ b/libinterp/corefcn/interpreter.cc	Tue Jan 17 11:19:44 2017 -0500
@@ -540,7 +540,7 @@
 
     string_vector all_args = options.all_args ();
 
-    octave_thread::init ();
+    octave::thread::init ();
 
     set_default_prompts ();
 
--- a/libinterp/corefcn/octave-link.cc	Tue Jan 17 10:33:03 2017 -0500
+++ b/libinterp/corefcn/octave-link.cc	Tue Jan 17 11:19:44 2017 -0500
@@ -50,7 +50,7 @@
 octave_link *octave_link::instance = 0;
 
 octave_link::octave_link (void)
-  : event_queue_mutex (new octave_mutex ()), gui_event_queue (),
+  : event_queue_mutex (new octave::mutex ()), gui_event_queue (),
     debugging (false), link_enabled (true)
 {
   octave::command_editor::add_event_hook (octave_readline_hook);
--- a/libinterp/corefcn/octave-link.h	Tue Jan 17 10:33:03 2017 -0500
+++ b/libinterp/corefcn/octave-link.h	Tue Jan 17 11:19:44 2017 -0500
@@ -29,9 +29,10 @@
 
 #include <string>
 
+#include "oct-mutex.h"
+
 #include "event-queue.h"
 
-class octave_mutex;
 class string_vector;
 class workspace_element;
 
@@ -365,7 +366,7 @@
 protected:
 
   // Semaphore to lock access to the event queue.
-  octave_mutex *event_queue_mutex;
+  octave::mutex *event_queue_mutex;
 
   // Event Queue.
   event_queue gui_event_queue;
--- a/liboctave/util/cmd-edit.cc	Tue Jan 17 10:33:03 2017 -0500
+++ b/liboctave/util/cmd-edit.cc	Tue Jan 17 11:19:44 2017 -0500
@@ -61,7 +61,7 @@
 
   std::set<command_editor::event_hook_fcn> command_editor::event_hook_set;
 
-  static octave_mutex event_hook_lock;
+  static octave::mutex event_hook_lock;
 
 #if defined (USE_READLINE)
 
@@ -1538,7 +1538,7 @@
   void
   command_editor::add_event_hook (event_hook_fcn f)
   {
-    octave_autolock guard (event_hook_lock);
+    autolock guard (event_hook_lock);
 
     if (instance_ok ())
       {
@@ -1551,7 +1551,7 @@
   void
   command_editor::remove_event_hook (event_hook_fcn f)
   {
-    octave_autolock guard (event_hook_lock);
+    autolock guard (event_hook_lock);
 
     if (instance_ok ())
       {
--- a/liboctave/util/oct-mutex.cc	Tue Jan 17 10:33:03 2017 -0500
+++ b/liboctave/util/oct-mutex.cc	Tue Jan 17 11:19:44 2017 -0500
@@ -33,144 +33,146 @@
 #  include <pthread.h>
 #endif
 
-void
-octave_base_mutex::lock (void)
-{
-  (*current_liboctave_error_handler) ("mutex not supported on this platform");
-}
-
-void
-octave_base_mutex::unlock (void)
+namespace octave
 {
-  (*current_liboctave_error_handler) ("mutex not supported on this platform");
-}
+  void
+  base_mutex::lock (void)
+  {
+    (*current_liboctave_error_handler) ("mutex not supported on this platform");
+  }
 
-bool
-octave_base_mutex::try_lock (void)
-{
-  (*current_liboctave_error_handler) ("mutex not supported on this platform");
+  void
+  base_mutex::unlock (void)
+  {
+    (*current_liboctave_error_handler) ("mutex not supported on this platform");
+  }
 
-  return false;
-}
+  bool
+  base_mutex::try_lock (void)
+  {
+    (*current_liboctave_error_handler) ("mutex not supported on this platform");
+
+    return false;
+  }
 
 #if defined (OCTAVE_USE_WINDOWS_API)
 
-class
-octave_w32_mutex : public octave_base_mutex
-{
-public:
-  octave_w32_mutex (void)
-    : octave_base_mutex ()
+  class
+  w32_mutex : public base_mutex
   {
-    InitializeCriticalSection (&cs);
-  }
+  public:
+    w32_mutex (void)
+      : base_mutex ()
+    {
+      InitializeCriticalSection (&cs);
+    }
+
+    ~w32_mutex (void)
+    {
+      DeleteCriticalSection (&cs);
+    }
+
+    void lock (void)
+    {
+      EnterCriticalSection (&cs);
+    }
 
-  ~octave_w32_mutex (void)
+    void unlock (void)
+    {
+      LeaveCriticalSection (&cs);
+    }
+
+    bool try_lock (void)
+    {
+      return (TryEnterCriticalSection (&cs) != 0);
+    }
+
+  private:
+    CRITICAL_SECTION cs;
+  };
+
+  static DWORD thread_id = 0;
+
+  void
+  thread::init (void)
   {
-    DeleteCriticalSection (&cs);
-  }
-
-  void lock (void)
-  {
-    EnterCriticalSection (&cs);
+    thread_id = GetCurrentThreadId ();
   }
 
-  void unlock (void)
+  bool
+  thread::is_thread (void)
   {
-    LeaveCriticalSection (&cs);
-  }
-
-  bool try_lock (void)
-  {
-    return (TryEnterCriticalSection (&cs) != 0);
+    return (GetCurrentThreadId () == thread_id);
   }
 
-private:
-  CRITICAL_SECTION cs;
-};
-
-static DWORD octave_thread_id = 0;
-
-void
-octave_thread::init (void)
-{
-  octave_thread_id = GetCurrentThreadId ();
-}
-
-bool
-octave_thread::is_octave_thread (void)
-{
-  return (GetCurrentThreadId () == octave_thread_id);
-}
-
 #elif defined (HAVE_PTHREAD_H)
 
-class
-octave_pthread_mutex : public octave_base_mutex
-{
-public:
-  octave_pthread_mutex (void)
-    : octave_base_mutex (), pm ()
+  class
+  pthread_mutex : public base_mutex
   {
-    pthread_mutexattr_t attr;
+  public:
+    pthread_mutex (void)
+      : base_mutex (), pm ()
+    {
+      pthread_mutexattr_t attr;
+
+      pthread_mutexattr_init (&attr);
+      pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
+      pthread_mutex_init (&pm, &attr);
+      pthread_mutexattr_destroy (&attr);
+    }
+
+    ~pthread_mutex (void)
+    {
+      pthread_mutex_destroy (&pm);
+    }
 
-    pthread_mutexattr_init (&attr);
-    pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
-    pthread_mutex_init (&pm, &attr);
-    pthread_mutexattr_destroy (&attr);
-  }
+    void lock (void)
+    {
+      pthread_mutex_lock (&pm);
+    }
+
+    void unlock (void)
+    {
+      pthread_mutex_unlock (&pm);
+    }
 
-  ~octave_pthread_mutex (void)
+    bool try_lock (void)
+    {
+      return (pthread_mutex_trylock (&pm) == 0);
+    }
+
+  private:
+    pthread_mutex_t pm;
+  };
+
+  static pthread_t thread_id = 0;
+
+  void
+  thread::init (void)
   {
-    pthread_mutex_destroy (&pm);
-  }
-
-  void lock (void)
-  {
-    pthread_mutex_lock (&pm);
+    thread_id = pthread_self ();
   }
 
-  void unlock (void)
+  bool
+  thread::is_thread (void)
   {
-    pthread_mutex_unlock (&pm);
-  }
-
-  bool try_lock (void)
-  {
-    return (pthread_mutex_trylock (&pm) == 0);
+    return (pthread_equal (thread_id, pthread_self ()) != 0);
   }
 
-private:
-  pthread_mutex_t pm;
-};
-
-static pthread_t octave_thread_id = 0;
-
-void
-octave_thread::init (void)
-{
-  octave_thread_id = pthread_self ();
-}
-
-bool
-octave_thread::is_octave_thread (void)
-{
-  return (pthread_equal (octave_thread_id, pthread_self ()) != 0);
-}
-
 #endif
 
-static octave_base_mutex *
-init_rep (void)
-{
+  static octave::base_mutex *
+  init_rep (void)
+  {
 #if defined (OCTAVE_USE_WINDOWS_API)
-  return new octave_w32_mutex ();
+    return new octave::w32_mutex ();
 #elif defined (HAVE_PTHREAD_H)
-  return new octave_pthread_mutex ();
+    return new octave::pthread_mutex ();
 #else
-  return new octave_base_mutex ();
+    return new octave::base_mutex ();
 #endif
-}
+  }
 
-octave_mutex::octave_mutex (void) : rep (init_rep ()) { }
-
+  mutex::mutex (void) : rep (init_rep ()) { }
+}
--- a/liboctave/util/oct-mutex.h	Tue Jan 17 10:33:03 2017 -0500
+++ b/liboctave/util/oct-mutex.h	Tue Jan 17 11:19:44 2017 -0500
@@ -27,128 +27,152 @@
 
 #include "oct-refcount.h"
 
-class octave_mutex;
-
-class
-octave_base_mutex
+namespace octave
 {
-public:
-  friend class octave_mutex;
-
-  octave_base_mutex (void) : count (1) { }
+  class mutex;
 
-  virtual ~octave_base_mutex (void) = default;
-
-  virtual void lock (void);
-
-  virtual void unlock (void);
+  class
+  base_mutex
+  {
+  public:
+    friend class mutex;
 
-  virtual bool try_lock (void);
+    base_mutex (void) : count (1) { }
 
-private:
-  octave::refcount<int> count;
-};
+    virtual ~base_mutex (void) = default;
+
+    virtual void lock (void);
 
-class
-OCTAVE_API
-octave_mutex
-{
-public:
-  octave_mutex (void);
+    virtual void unlock (void);
+
+    virtual bool try_lock (void);
 
-  octave_mutex (const octave_mutex& m)
-    : rep (m.rep)
-  {
-    rep->count++;
-  }
+  private:
+    octave::refcount<int> count;
+  };
 
-  ~octave_mutex (void)
+  class
+  OCTAVE_API
+  mutex
   {
-    if (--rep->count == 0)
-      delete rep;
-  }
+  public:
+    mutex (void);
 
-  octave_mutex& operator = (const octave_mutex& m)
-  {
-    if (rep != m.rep)
+    mutex (const mutex& m)
+      : rep (m.rep)
       {
-        if (--rep->count == 0)
-          delete rep;
-
-        rep = m.rep;
         rep->count++;
       }
 
-    return *this;
-  }
-
-  void lock (void)
-  {
-    rep->lock ();
-  }
-
-  void unlock (void)
-  {
-    rep->unlock ();
-  }
+    ~mutex (void)
+      {
+        if (--rep->count == 0)
+          delete rep;
+      }
 
-  bool try_lock (void)
-  {
-    return rep->try_lock ();
-  }
-
-protected:
-  octave_base_mutex *rep;
-};
+    mutex& operator = (const mutex& m)
+      {
+        if (rep != m.rep)
+          {
+            if (--rep->count == 0)
+              delete rep;
 
-class
-octave_autolock
-{
-public:
-  octave_autolock (const octave_mutex& m, bool block = true)
-    : mutex (m), lock_result (false)
-  {
-    if (block)
-      {
-        mutex.lock ();
-        lock_result = true;
+            rep = m.rep;
+            rep->count++;
+          }
+
+        return *this;
       }
-    else
-      lock_result = mutex.try_lock ();
-  }
+
+    void lock (void)
+    {
+      rep->lock ();
+    }
 
-  // No copying.
+    void unlock (void)
+    {
+      rep->unlock ();
+    }
 
-  octave_autolock (const octave_autolock&) = delete;
+    bool try_lock (void)
+    {
+      return rep->try_lock ();
+    }
+
+  protected:
+    base_mutex *rep;
+  };
 
-  octave_autolock& operator = (const octave_autolock&) = delete;
-
-  ~octave_autolock (void)
+  class
+  autolock
   {
-    if (lock_result)
-      mutex.unlock ();
-  }
+  public:
+    autolock (const mutex& m, bool block = true)
+      : m_mutex (m), m_lock_result (false)
+    {
+      if (block)
+        {
+          m_mutex.lock ();
+          m_lock_result = true;
+        }
+      else
+        m_lock_result = m_mutex.try_lock ();
+    }
 
-  bool ok (void) const { return lock_result; }
+    // No copying.
+
+    autolock (const autolock&) = delete;
+
+    autolock& operator = (const autolock&) = delete;
 
-  operator bool (void) const { return ok (); }
+    ~autolock (void)
+    {
+      if (m_lock_result)
+        m_mutex.unlock ();
+    }
 
-private:
+    bool ok (void) const { return m_lock_result; }
 
-  octave_mutex mutex;
+    operator bool (void) const { return ok (); }
+
+  private:
 
-  bool lock_result;
-};
+    mutex m_mutex;
+
+    bool m_lock_result;
+  };
+
 
-class
-OCTAVE_API
-octave_thread
-{
-public:
-  static void init (void);
+  class
+  OCTAVE_API
+  thread
+  {
+  public:
+
+    static void init (void);
+
+    static bool is_thread (void);
 
-  static bool is_octave_thread (void);
-};
+    OCTAVE_DEPRECATED ("use 'octave::is_thread' instead")
+    static bool is_octave_thread (void) { return is_thread (); }
+  };
+}
+
+#if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
+
+OCTAVE_DEPRECATED ("use 'octave::mutex' instead")
+typedef octave::mutex octave_mutex;
+
+OCTAVE_DEPRECATED ("use 'octave::base_mutex' instead")
+typedef octave::base_mutex octave_base_mutex;
+
+OCTAVE_DEPRECATED ("use 'octave::autolock' instead")
+typedef octave::autolock octave_autolock;
+
+OCTAVE_DEPRECATED ("use 'octave::thread' instead")
+typedef octave::thread octave_thread;
 
 #endif
 
+#endif
+