Introduce g_cancel_events() and use it a couple of places where it makes

sense.
This commit is contained in:
phk 2003-03-23 23:01:40 +00:00
parent 3e8d794231
commit 8e76f1cefa
3 changed files with 26 additions and 0 deletions

View File

@ -324,6 +324,28 @@ g_post_event(enum g_events ev, struct g_class *mp, struct g_geom *gp, struct g_p
wakeup(&g_wait_event);
}
void
g_cancel_event(struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
{
struct g_event *ep, *epn;
mtx_lock(&g_eventlock);
ep = TAILQ_FIRST(&g_events);
for (;ep != NULL;) {
epn = TAILQ_NEXT(ep, events);
if (
(ep->class != NULL && ep->class == mp) ||
(ep->geom != NULL && ep->geom == gp) ||
(ep->provider != NULL && ep->provider == pp) ||
(ep->consumer != NULL && ep->consumer == cp)) {
TAILQ_REMOVE(&g_events, ep, events);
g_free(ep);
}
ep = epn;
}
mtx_unlock(&g_eventlock);
}
int
g_call_me(g_call_me_t *func, void *arg)
{

View File

@ -93,6 +93,7 @@ void g_conftxt(void *);
/* geom_event.c */
void g_event_init(void);
void g_post_event(enum g_events ev, struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp);
void g_cancel_event(struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp);
void g_run_events(void);
void g_stall_events(void);
void g_release_events(void);

View File

@ -126,6 +126,7 @@ g_destroy_geom(struct g_geom *gp)
KASSERT(LIST_EMPTY(&gp->provider),
("g_destroy_geom(%s) with provider(s) [%p]",
gp->name, LIST_FIRST(&gp->consumer)));
g_cancel_event(NULL, gp, NULL, NULL);
LIST_REMOVE(gp, geom);
TAILQ_REMOVE(&geoms, gp, geoms);
g_free(gp->name);
@ -162,6 +163,7 @@ g_destroy_consumer(struct g_consumer *cp)
KASSERT (cp->acr == 0, ("g_destroy_consumer with acr"));
KASSERT (cp->acw == 0, ("g_destroy_consumer with acw"));
KASSERT (cp->ace == 0, ("g_destroy_consumer with ace"));
g_cancel_event(NULL, NULL, NULL, cp);
LIST_REMOVE(cp, consumer);
devstat_remove_entry(cp->stat);
g_free(cp);
@ -216,6 +218,7 @@ g_destroy_provider(struct g_provider *pp)
KASSERT (pp->acr == 0, ("g_destroy_provider with acr"));
KASSERT (pp->acw == 0, ("g_destroy_provider with acw"));
KASSERT (pp->acw == 0, ("g_destroy_provider with ace"));
g_cancel_event(NULL, NULL, pp, NULL);
g_nproviders--;
LIST_REMOVE(pp, provider);
gp = pp->geom;