summaryrefslogtreecommitdiff
path: root/libs/pbd3
diff options
context:
space:
mode:
authorJesse Chappell <jesse@essej.net>2006-01-06 04:59:17 +0000
committerJesse Chappell <jesse@essej.net>2006-01-06 04:59:17 +0000
commitbd21c474e547d49338ea0efd452895de1e147cd5 (patch)
tree2993bc781777530afc180313c9f69cc898f851e0 /libs/pbd3
parent18844bac7aa0747453ed4d04c4a462f2044a43bb (diff)
committed RWlock fixes to libardour. added hw monitoring fixes from nick_m. minor alsa midi fix and update rate settings.
git-svn-id: svn://localhost/trunk/ardour2@244 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/pbd3')
-rw-r--r--libs/pbd3/pbd/lockmonitor.h131
1 files changed, 131 insertions, 0 deletions
diff --git a/libs/pbd3/pbd/lockmonitor.h b/libs/pbd3/pbd/lockmonitor.h
index 8fad66f83e..c91a041e9b 100644
--- a/libs/pbd3/pbd/lockmonitor.h
+++ b/libs/pbd3/pbd/lockmonitor.h
@@ -57,6 +57,31 @@ class NonBlockingLock : public Lock {
int unlock() { return pthread_mutex_unlock (&_mutex); }
};
+class RWLock {
+ public:
+ RWLock() { pthread_rwlock_init (&_mutex, 0); }
+ virtual ~RWLock() { pthread_rwlock_destroy(&_mutex); }
+
+ virtual int write_lock () { return pthread_rwlock_wrlock (&_mutex); }
+ virtual int read_lock () { return pthread_rwlock_rdlock (&_mutex); }
+ virtual int unlock() { return pthread_rwlock_unlock (&_mutex); }
+
+ pthread_rwlock_t *mutex() { return &_mutex; }
+
+ protected:
+ pthread_rwlock_t _mutex;
+};
+
+class NonBlockingRWLock : public RWLock {
+ public:
+ NonBlockingRWLock() {}
+ ~NonBlockingRWLock(){}
+
+ int write_trylock () { return pthread_rwlock_trywrlock (&_mutex); }
+ int read_trylock () { return pthread_rwlock_tryrdlock (&_mutex); }
+};
+
+
class LockMonitor
{
public:
@@ -189,6 +214,112 @@ class SpinLockMonitor
#endif
};
+
+class RWLockMonitor
+{
+ public:
+ RWLockMonitor (RWLock& lck, bool write, unsigned long l, const char *f)
+ : lock (lck)
+#ifdef DEBUG_LOCK_MONITOR
+ , line (l), file (f)
+#endif
+ {
+
+#ifdef DEBUG_LOCK_MONITOR
+ unsigned long long when;
+ when = get_cycles();
+ cerr << when << " lock " << &lock << " at " << line << " in " << file << endl;
+#endif
+ if (write) {
+ lock.write_lock ();
+ } else {
+ lock.read_lock ();
+ }
+#ifdef DEBUG_LOCK_MONITOR
+ when = get_cycles();
+ cerr << '\t' << when
+ << " locked: "
+ << &lock << " at "
+ << line << " in " << file << endl;
+#endif
+ }
+
+ ~RWLockMonitor () {
+ lock.unlock ();
+#ifdef DEBUG_LOCK_MONITOR
+ unsigned long long when;
+ when = get_cycles();
+ cerr << '\t' << when << ' '
+ << " UNLOCKED "
+ << &lock << " at "
+ << line << " in " << file << endl;
+#endif
+ }
+ private:
+ RWLock& lock;
+#ifdef DEBUG_LOCK_MONITOR
+ unsigned long line;
+ const char * file;
+#endif
+};
+
+class TentativeRWLockMonitor
+{
+ public:
+ TentativeRWLockMonitor (NonBlockingRWLock& lck, bool write, unsigned long l, const char *f)
+ : lock (lck)
+#ifdef DEBUG_LOCK_MONITOR
+ , line (l), file (f)
+#endif
+ {
+
+#ifdef DEBUG_LOCK_MONITOR
+ unsigned long long when;
+ when = get_cycles();
+ cerr << when << " tentative lock " << &lock << " at " << line << " in " << file << endl;
+#endif
+ if (write) {
+ _locked = (lock.write_trylock() == 0);
+ } else {
+ _locked = (lock.read_trylock() == 0);
+ }
+
+#ifdef DEBUG_LOCK_MONITOR
+ when = get_cycles();
+ cerr << '\t' << when << ' '
+ << _locked
+ << " lock: "
+ << &lock << " at "
+ << line << " in " << file << endl;
+#endif
+ }
+
+ ~TentativeRWLockMonitor () {
+ if (_locked) {
+ lock.unlock ();
+#ifdef DEBUG_LOCK_MONITOR
+ unsigned long long when;
+ when = get_cycles();
+ cerr << '\t' << when << ' '
+ << " UNLOCKED "
+ << &lock << " at "
+ << line << " in " << file << endl;
+#endif
+ }
+ }
+
+ bool locked() { return _locked; }
+
+ private:
+ NonBlockingRWLock& lock;
+ bool _locked;
+#ifdef DEBUG_LOCK_MONITOR
+ unsigned long line;
+ const char * file;
+#endif
+};
+
+
} /* namespace */
#endif /* __pbd_lockmonitor_h__*/