vici: Ensure we have no active users before mangling event client registrations

This commit is contained in:
Martin Willi
2014-05-07 14:13:38 +02:00
parent 65cc8f5581
commit 374511c52c
+25 -3
View File
@@ -129,10 +129,19 @@ static void register_event(private_vici_dispatcher_t *this, char *name,
event_t *event; event_t *event;
this->mutex->lock(this->mutex); this->mutex->lock(this->mutex);
while (TRUE)
{
event = this->events->get(this->events, name); event = this->events->get(this->events, name);
if (event) if (!event)
{
break;
}
if (!event->uses)
{ {
array_insert(event->clients, ARRAY_TAIL, &id); array_insert(event->clients, ARRAY_TAIL, &id);
break;
}
this->cond->wait(this->cond, this->mutex);
} }
this->mutex->unlock(this->mutex); this->mutex->unlock(this->mutex);
@@ -160,8 +169,14 @@ static void unregister_event(private_vici_dispatcher_t *this, char *name,
bool found = FALSE; bool found = FALSE;
this->mutex->lock(this->mutex); this->mutex->lock(this->mutex);
while (TRUE)
{
event = this->events->get(this->events, name); event = this->events->get(this->events, name);
if (event) if (!event)
{
break;
}
if (!event->uses)
{ {
enumerator = array_create_enumerator(event->clients); enumerator = array_create_enumerator(event->clients);
while (enumerator->enumerate(enumerator, &current)) while (enumerator->enumerate(enumerator, &current))
@@ -174,6 +189,9 @@ static void unregister_event(private_vici_dispatcher_t *this, char *name,
} }
} }
enumerator->destroy(enumerator); enumerator->destroy(enumerator);
break;
}
this->cond->wait(this->cond, this->mutex);
} }
this->mutex->unlock(this->mutex); this->mutex->unlock(this->mutex);
@@ -340,11 +358,15 @@ CALLBACK(disconnect, void,
event_t *event; event_t *event;
u_int *current; u_int *current;
/* deregister all clients */ /* deregister client from all events */
this->mutex->lock(this->mutex); this->mutex->lock(this->mutex);
events = this->events->create_enumerator(this->events); events = this->events->create_enumerator(this->events);
while (events->enumerate(events, NULL, &event)) while (events->enumerate(events, NULL, &event))
{ {
while (event->uses)
{
this->cond->wait(this->cond, this->mutex);
}
ids = array_create_enumerator(event->clients); ids = array_create_enumerator(event->clients);
while (ids->enumerate(ids, &current)) while (ids->enumerate(ids, &current))
{ {