[vlc-commits] rwlock: cancellation safety
Rémi Denis-Courmont
git at videolan.org
Mon Sep 10 17:30:24 CEST 2012
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Sep 10 18:28:20 2012 +0300| [debc9d470c2eeb1025c751348bc684655a2b2872] | committer: Rémi Denis-Courmont
rwlock: cancellation safety
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=debc9d470c2eeb1025c751348bc684655a2b2872
---
src/misc/rwlock.h | 6 ++++++
src/posix/thread.c | 2 ++
2 files changed, 8 insertions(+)
diff --git a/src/misc/rwlock.h b/src/misc/rwlock.h
index d4857ad..bb1c27b 100644
--- a/src/misc/rwlock.h
+++ b/src/misc/rwlock.h
@@ -60,7 +60,9 @@ void vlc_rwlock_rdlock (vlc_rwlock_t *lock)
while (lock->state < 0)
{
assert (lock->state == WRITER_BIT);
+ mutex_cleanup_push (&lock->mutex);
vlc_cond_wait (&lock->wait, &lock->mutex);
+ vlc_cleanup_pop ();
}
if (unlikely(lock->state >= READER_MASK))
abort (); /* An overflow is certainly a recursion bug. */
@@ -73,7 +75,11 @@ void vlc_rwlock_wrlock (vlc_rwlock_t *lock)
vlc_mutex_lock (&lock->mutex);
/* Wait until nobody owns the lock in any way. */
while (lock->state != 0)
+ {
+ mutex_cleanup_push (&lock->mutex);
vlc_cond_wait (&lock->wait, &lock->mutex);
+ vlc_cleanup_pop ();
+ }
lock->state = WRITER_BIT;
vlc_mutex_unlock (&lock->mutex);
}
diff --git a/src/posix/thread.c b/src/posix/thread.c
index d5e3263..1fc2b67 100644
--- a/src/posix/thread.c
+++ b/src/posix/thread.c
@@ -558,6 +558,7 @@ void vlc_rwlock_destroy (vlc_rwlock_t *lock)
/**
* Acquires a read/write lock for reading. Recursion is allowed.
+ * @note This function may be a point of cancellation.
*/
void vlc_rwlock_rdlock (vlc_rwlock_t *lock)
{
@@ -567,6 +568,7 @@ void vlc_rwlock_rdlock (vlc_rwlock_t *lock)
/**
* Acquires a read/write lock for writing. Recursion is not allowed.
+ * @note This function may be a point of cancellation.
*/
void vlc_rwlock_wrlock (vlc_rwlock_t *lock)
{
More information about the vlc-commits
mailing list