[Aptitude-svn-commit] r4036 - in branches/aptitude-0.3/aptitude: . src/generic

Daniel Burrows dburrows at costa.debian.org
Fri Sep 2 19:48:31 UTC 2005


Author: dburrows
Date: Fri Sep  2 19:48:28 2005
New Revision: 4036

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/generic/threads.h
Log:
Recursive mutex support.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Fri Sep  2 19:48:28 2005
@@ -1,3 +1,10 @@
+2005-09-02  Daniel Burrows  <dburrows at debian.org>
+
+	* src/generic/threads.h:
+
+	  Support mutex attributes and add a recursive mutex type (for
+	  static initialization).
+
 2005-09-01  Daniel Burrows  <dburrows at debian.org>
 
 	* src/generic/threads.h:

Modified: branches/aptitude-0.3/aptitude/src/generic/threads.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/threads.h	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/threads.h	Fri Sep  2 19:48:28 2005
@@ -233,6 +233,43 @@
     mutex(const mutex &other);
     mutex &operator=(const mutex &other);
   public:
+    /** A mutex attributes object. */
+    class attr
+    {
+      pthread_mutexattr_t attrs;
+
+      friend class mutex;
+
+    public:
+      attr()
+      {
+	pthread_mutexattr_init(&attrs);
+      }
+
+      attr(int kind)
+      {
+	pthread_mutexattr_init(&attrs);
+	pthread_mutexattr_settype(&attrs, kind);
+      }
+
+      ~attr()
+      {
+	pthread_mutexattr_destroy(&attrs);
+      }
+
+      int settype(int kind)
+      {
+	return pthread_mutexattr_settype(&attrs, kind);
+      }
+
+      int gettype()
+      {
+	int rval;
+	pthread_mutexattr_gettype(&attrs, &rval);
+	return rval;
+      }
+    };
+
     /** Represents a lock on a mutex.  Can be released and re-asserted
      *  as desired; when the lock goes out of scope, it will
      *  automatically be released if necessary.
@@ -332,12 +369,29 @@
       pthread_mutex_init(&m, NULL);
     }
 
+    mutex(const attr &a)
+    {
+      pthread_mutex_init(&m, &a.attrs);
+    }
+
     ~mutex()
     {
       pthread_mutex_destroy(&m);
     }
   };
 
+  /** A mutex that is initialized to be recursive.  Used because
+   *  apparently C++ global constructors can't take arguments.
+   */
+  class recursive_mutex : public mutex
+  {
+  public:
+    recursive_mutex()
+      :mutex(attr(PTHREAD_MUTEX_RECURSIVE))
+    {
+    }
+  };
+
   /** A abstraction over conditions.  When a condition variable is
    *  destroyed, any threads that are still blocked on it are woken
    *  up.



More information about the Aptitude-svn-commit mailing list