diff options
| author | Patrick Mochel <mochel@osdl.org> | 2003-06-04 19:23:44 -0700 |
|---|---|---|
| committer | Patrick Mochel <mochel@osdl.org> | 2003-06-04 19:23:44 -0700 |
| commit | 29b9acf601b87759547affd1d5c5615ff11fbc92 (patch) | |
| tree | 2ba32a8292190b248ea7ea0f53db9a29dac4edee /lib/kobject.c | |
| parent | 043400bf0e7df24caa8ccd8b9e2067d0facccf8c (diff) | |
[kobject] Remove kobj_lock and use lockless refcounting.
The only thing preventing this from happening earlier was the circular sysfs
registration dependency - it would need to be initialized before it was
registered, but needed to be registered before it was initialized.
With kobjects gone from struct filesystem_type, the dependency no longer
exists and we don't have to special-case the possibility that a kobject will
be passed to kobject_get with a refcount == 0.
Note that a kobject with a count of 0 in that function is still a bug, but
one in the subsystem making the call. We should add a debugging hook to dump
the stack if it does happen.
Diffstat (limited to 'lib/kobject.c')
| -rw-r--r-- | lib/kobject.c | 18 |
1 files changed, 2 insertions, 16 deletions
diff --git a/lib/kobject.c b/lib/kobject.c index ba1cdd69f775..21f876504c5e 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -17,10 +17,6 @@ #include <linux/module.h> #include <linux/stat.h> -/* This lock can be removed entirely when the sysfs_init() code is cleaned up - * to not try to reference itself before it is initialized. */ -static spinlock_t kobj_lock = SPIN_LOCK_UNLOCKED; - /** * populate_dir - populate directory with attributes. * @kobj: object we're working on. @@ -350,14 +346,11 @@ void kobject_unregister(struct kobject * kobj) struct kobject * kobject_get(struct kobject * kobj) { struct kobject * ret = kobj; - unsigned long flags; - spin_lock_irqsave(&kobj_lock, flags); - if (kobj && atomic_read(&kobj->refcount) > 0) + if (kobj) atomic_inc(&kobj->refcount); else ret = NULL; - spin_unlock_irqrestore(&kobj_lock, flags); return ret; } @@ -387,15 +380,8 @@ void kobject_cleanup(struct kobject * kobj) void kobject_put(struct kobject * kobj) { - unsigned long flags; - - local_irq_save(flags); - if (atomic_dec_and_lock(&kobj->refcount, &kobj_lock)) { - spin_unlock_irqrestore(&kobj_lock, flags); + if (atomic_dec_and_test(&kobj->refcount)) kobject_cleanup(kobj); - } else { - local_irq_restore(flags); - } } |
