* Move the driver_t::refs field to kobj_t to replace kobj_t::instances.

* Back out a couple of workarounds for the confusion between
  kobj_t::instances and driver_t::refs.
This commit is contained in:
Doug Rabson 2000-05-01 10:45:15 +00:00
parent 7cb24dbb43
commit 4b4a49fda5
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=59820
4 changed files with 8 additions and 12 deletions

View File

@ -162,7 +162,10 @@ devclass_add_driver(devclass_t dc, driver_t *driver)
bzero(dl, sizeof *dl);
/*
* Compile the driver's methods.
* Compile the driver's methods. Also increase the reference count
* so that the class doesn't get freed when the last instance
* goes. This means we can safely use static methods and avoids a
* double-free in devclass_delete_driver.
*/
kobj_class_compile((kobj_class_t) driver);
@ -986,7 +989,6 @@ device_set_driver(device_t dev, driver_t *driver)
return ENOMEM;
}
bzero(dev->softc, driver->size);
driver->refs++;
} else
kobj_init((kobj_t) dev, &null_class);
return 0;
@ -1843,11 +1845,6 @@ bus_generic_driver_added(device_t dev, driver_t *driver)
{
device_t child;
/*
* Make sure the class has a valid ops table.
*/
kobj_class_compile((kobj_class_t) driver);
DEVICE_IDENTIFY(driver, dev);
for (child = TAILQ_FIRST(&dev->children);
child; child = TAILQ_NEXT(child, link))

View File

@ -174,7 +174,7 @@ kobj_init(kobj_t obj, kobj_class_t cls)
kobj_class_compile(cls);
obj->ops = cls->ops;
cls->instances++;
cls->refs++;
}
void
@ -187,8 +187,8 @@ kobj_delete(kobj_t obj, struct malloc_type *mtype)
* after its last instance is deleted. As an optimisation, we
* should defer this for a short while to avoid thrashing.
*/
cls->instances--;
if (!cls->instances)
cls->refs--;
if (!cls->refs)
kobj_class_free(cls);
obj->ops = 0;

View File

@ -65,7 +65,6 @@ typedef int (*devop_t)(void);
struct driver {
KOBJ_CLASS_FIELDS;
void *priv; /* driver private data */
int refs; /* # devclasses containing driver */
};
typedef enum device_state {

View File

@ -55,7 +55,7 @@ struct kobj_method {
const char *name; /* class name */ \
kobj_method_t *methods; /* method table */ \
size_t size; /* object size */ \
u_int instances; /* instance count */ \
u_int refs; /* reference count */ \
kobj_ops_t ops /* compiled method table */
struct kobj_class {