Turn the hardwired NEW_CLASS event into a g_call_me() event.

This commit is contained in:
Poul-Henning Kamp 2003-04-23 19:34:38 +00:00
parent b5cba4167f
commit 9972896c00
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=113927
3 changed files with 34 additions and 22 deletions

View file

@ -142,8 +142,7 @@ g_destroy_event(struct g_event *ep)
static void
g_do_event(struct g_event *ep)
{
struct g_class *mp, *mp2;
struct g_geom *gp;
struct g_class *mp;
struct g_consumer *cp, *cp2;
struct g_provider *pp;
int i;
@ -155,23 +154,6 @@ g_do_event(struct g_event *ep)
ep->func(ep->arg, 0);
g_topology_assert();
break;
case EV_NEW_CLASS:
if (g_shutdown)
break;
mp2 = ep->ref[0];
if (mp2->taste == NULL)
break;
LIST_FOREACH(mp, &g_classes, class) {
if (mp2 == mp)
continue;
LIST_FOREACH(gp, &mp->geom, geom) {
LIST_FOREACH(pp, &gp->provider, provider) {
mp2->taste(mp2, pp, 0);
g_topology_assert();
}
}
}
break;
case EV_NEW_PROVIDER:
if (g_shutdown)
break;

View file

@ -59,7 +59,6 @@ extern int g_debugflags;
* an internal eventqueue.
*/
enum g_events {
EV_NEW_CLASS, /* class */
EV_NEW_PROVIDER, /* provider */
EV_SPOILED, /* provider, consumer */
EV_CALL_ME, /* func, arg */

View file

@ -60,6 +60,37 @@ char *g_wait_event, *g_wait_up, *g_wait_down, *g_wait_sim;
static int g_ignition;
/*
* This event offers a new class a chance to taste all preexisting providers.
*/
static void
g_new_class_event(void *arg, int flag)
{
struct g_class *mp2, *mp;
struct g_geom *gp;
struct g_provider *pp;
g_topology_assert();
if (flag == EV_CANCEL)
return;
if (g_shutdown)
return;
mp2 = arg;
if (mp2->taste == NULL)
return;
LIST_FOREACH(mp, &g_classes, class) {
if (mp2 == mp)
continue;
LIST_FOREACH(gp, &mp->geom, geom) {
LIST_FOREACH(pp, &gp->provider, provider) {
mp2->taste(mp2, pp, 0);
g_topology_assert();
}
}
}
}
void
g_add_class(struct g_class *mp)
{
@ -73,8 +104,8 @@ g_add_class(struct g_class *mp)
g_trace(G_T_TOPOLOGY, "g_add_class(%s)", mp->name);
LIST_INIT(&mp->geom);
LIST_INSERT_HEAD(&g_classes, mp, class);
if (g_nproviders > 0)
g_post_event(EV_NEW_CLASS, mp, NULL);
if (g_nproviders > 0 && mp->taste != NULL)
g_call_me(g_new_class_event, mp, mp, NULL);
g_topology_unlock();
}