*/
void uk_rwlock_wunlock(struct uk_rwlock *rwl);
-/**
- * Upgrade the given read lock to a write lock
- *
- * @param rwl
- * Reader-writer lock to upgrade. The current thread must hold the lock
- * for reading
- */
-void uk_rwlock_upgrade(struct uk_rwlock *rwl);
-
-/**
- * Downgrade the given write lock to a read lock
- *
- * @param rwl
- * Reader-writer lock to downgrade. The current thread must hold the lock
- * for writing
- */
-void uk_rwlock_downgrade(struct uk_rwlock *rwl);
-
#ifdef __cplusplus
}
uk_waitq_wake_up_one(&rwl->exclusive);
}
-void uk_rwlock_upgrade(struct uk_rwlock *rwl)
-{
- UK_ASSERT(rwl);
-
- uk_spin_lock(&rwl->sl);
- if (rwl->nactive == 1) {
- /* We are the only active reader. Just upgrade to writer */
- rwl->nactive = -1;
- } else {
- /* There are other readers. Wait until these have left */
- UK_ASSERT(rwl->nactive > 1);
-
- /*
- * Indicate that we are waiting for write access and remove
- * this thread from the active readers.
- */
- rwl->npending_writes++;
- rwl->nactive--;
-
- uk_waitq_wait_event_locked(&rwl->shared,
- rwl->nactive == 0,
- uk_spin_lock,
- uk_spin_unlock,
- &rwl->sl);
-
- UK_ASSERT(rwl->npending_writes > 0);
- UK_ASSERT(rwl->nactive == 0);
-
- /* We are now the writer. Remove the satisfied request and mark
- * the lock for write access.
- */
- rwl->npending_writes--;
- rwl->nactive = -1;
- }
- uk_spin_unlock(&rwl->sl);
-}
-
-void uk_rwlock_downgrade(struct uk_rwlock *rwl)
-{
- int wake_readers;
-
- UK_ASSERT(rwl);
-
- uk_spin_lock(&rwl->sl);
- UK_ASSERT(rwl->nactive == -1);
-
- /* We are the writer. Downgrade the lock to read access by
- * transforming to a reader. If there are other readers waiting, wake
- * them up.
- */
- rwl->nactive = 1;
- wake_readers = (rwl->npending_reads > 0);
- uk_spin_unlock(&rwl->sl);
-
- if (wake_readers)
- uk_waitq_wake_up(&rwl->shared);
-}