Hi Alan,
Instead of having SMP-specific code and doing a sequence of (on SMP):
test if count is 0
take a spinlock
test if count is still 0
we could make use of the atomic primitive
atomic_dec_and_lock()
and do it in one go, which is cleaner, imho.
Regards,
Tigran
--- linux.kernel/user.c Mon Nov 27 12:01:34 2000
+++ work/kernel/user.c Mon Nov 27 12:03:20 2000
@@ -74,27 +74,12 @@
}
}
-/*
- * For SMP, we need to re-test the user struct counter
- * after having acquired the spinlock. This allows us to do
- * the common case (not freeing anything) without having
- * any locking.
- */
-#ifdef CONFIG_SMP
- #define uid_hash_free(up) (!atomic_read(&(up)->__count))
-#else
- #define uid_hash_free(up) (1)
-#endif
-
void free_uid(struct user_struct *up)
{
if (up) {
- if (atomic_dec_and_test(&up->__count)) {
- spin_lock(&uidhash_lock);
- if (uid_hash_free(up)) {
- uid_hash_remove(up);
- kmem_cache_free(uid_cachep, up);
- }
+ if (atomic_dec_and_lock(&up->__count, &uidhash_lock)) {
+ uid_hash_remove(up);
+ kmem_cache_free(uid_cachep, up);
spin_unlock(&uidhash_lock);
}
}