diff liboctave/util/oct-mutex.h @ 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 27e4ec3b0b49
children ef4d915df748
line wrap: on
line diff
--- 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
+