Simplify rwlock implementation.

Remove RW_COUNT() from the rwlock implementation.  The idea was that it
could be used as a generic wrapper for getting at the internal state
of a rwlock.  While a good idea it's proven problematic to keep it
correct for multiple archs and internal implementation changes.  In
short it hasn't been worth the trouble.

With that and simplicity in mind things have been updated to use the
rwsem_is_locked() function instead of RW_COUNT for the RW_*_HELD()
functions.  As for rw_upgrade() it remains only implemented for
the generic rwsem implemenation.  It remains to be determined if its
worth the effort of adding a custom implementation for each arch.
This commit is contained in:
Brian Behlendorf
2010-05-20 14:20:34 -07:00
parent 23d91792ef
commit 32f5faff69
2 changed files with 36 additions and 43 deletions
+12 -4
View File
@@ -571,7 +571,7 @@ static int
splat_rwlock_test6(struct file *file, void *arg)
{
rw_priv_t *rwp;
int rc = -EINVAL;
int rc;
rwp = (rw_priv_t *)kmalloc(sizeof(*rwp), GFP_KERNEL);
if (rwp == NULL)
@@ -584,15 +584,18 @@ splat_rwlock_test6(struct file *file, void *arg)
splat_vprint(file, SPLAT_RWLOCK_TEST6_NAME,
"rwlock should be read lock: %d\n",
RW_READ_HELD(&rwp->rw_rwlock));
rc = -ENOLCK;
goto out;
}
/* With one reader upgrade should never fail */
#if defined(CONFIG_RWSEM_GENERIC_SPINLOCK)
/* With one reader upgrade should never fail. */
rc = rw_tryupgrade(&rwp->rw_rwlock);
if (!rc) {
splat_vprint(file, SPLAT_RWLOCK_TEST6_NAME,
"rwlock contended preventing upgrade: %ld\n",
(long int)RW_COUNT(&rwp->rw_rwlock));
"rwlock failed upgrade from reader: %d\n",
RW_READ_HELD(&rwp->rw_rwlock));
rc = -ENOLCK;
goto out;
}
@@ -607,6 +610,11 @@ splat_rwlock_test6(struct file *file, void *arg)
rc = 0;
splat_vprint(file, SPLAT_RWLOCK_TEST6_NAME, "%s",
"rwlock properly upgraded\n");
#else
rc = 0;
splat_vprint(file, SPLAT_RWLOCK_TEST6_NAME, "%s",
"rw_tryupgrade() is disabled for this arch\n");
#endif
out:
rw_exit(&rwp->rw_rwlock);
rw_destroy(&rwp->rw_rwlock);