aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-10-13 05:55:58 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-10-13 05:55:58 +0000
commite2e9b46618a384d46faace0f16c27008bd818608 (patch)
treeac7fdadcf5abd86ebf53e78f199ce676fa19b32b
parentc388cc80b200f6e13d633f05d283642400c029fb (diff)
downloadpaludis-e2e9b46618a384d46faace0f16c27008bd818608.tar.gz
paludis-e2e9b46618a384d46faace0f16c27008bd818608.tar.xz
Add Lock::acquire_then_release_old
-rw-r--r--paludis/util/mutex.cc13
-rw-r--r--paludis/util/mutex.hh10
2 files changed, 22 insertions, 1 deletions
diff --git a/paludis/util/mutex.cc b/paludis/util/mutex.cc
index 315b091..076b8a8 100644
--- a/paludis/util/mutex.cc
+++ b/paludis/util/mutex.cc
@@ -58,6 +58,14 @@ Lock::~Lock()
pthread_mutex_unlock(_mutex->posix_mutex());
}
+void
+Lock::acquire_then_release_old(Mutex & m)
+{
+ pthread_mutex_lock(m.posix_mutex());
+ pthread_mutex_unlock(_mutex->posix_mutex());
+ _mutex = &m;
+}
+
TryLock::TryLock(Mutex & m) :
_mutex(&m)
{
@@ -91,6 +99,11 @@ Lock::Lock(Mutex &)
{
}
+void
+Lock::acquire_then_release_old(Mutex &)
+{
+}
+
Lock::~Lock()
{
}
diff --git a/paludis/util/mutex.hh b/paludis/util/mutex.hh
index fa1af2c..edbb441 100644
--- a/paludis/util/mutex.hh
+++ b/paludis/util/mutex.hh
@@ -85,7 +85,7 @@ namespace paludis
Lock & operator= (const Lock &);
#ifdef PALUDIS_ENABLE_THREADS
- Mutex * const _mutex;
+ Mutex * _mutex;
#endif
public:
@@ -96,6 +96,14 @@ namespace paludis
~Lock();
///\}
+
+ /**
+ * Acquire a lock on the provided Mutex, and then release our
+ * previously owned lock.
+ *
+ * Use with caution -- this is a good way of creating deadlocks.
+ */
+ void acquire_then_release_old(Mutex &);
};
/**