/*
+ * Copyright (C) 2011 Tobias Brunner
* Copyright (C) 2006 Martin Willi
* Hochschule fuer Technik Rapperswil
*
#include <threading/thread.h>
#include <threading/thread_value.h>
-#include <threading/condvar.h>
#include <threading/mutex.h>
typedef struct private_bus_t private_bus_t;
*/
listener_t *listener;
- /**
- * is this a active listen() call with a blocking thread
- */
- bool blocker;
-
/**
* are we currently calling this listener
*/
int calling;
-
- /**
- * condvar where active listeners wait
- */
- condvar_t *condvar;
};
/**
* create a listener entry
*/
-static entry_t *entry_create(listener_t *listener, bool blocker)
+static entry_t *entry_create(listener_t *listener)
{
- entry_t *this = malloc_thing(entry_t);
-
- this->listener = listener;
- this->blocker = blocker;
- this->calling = 0;
- this->condvar = condvar_create(CONDVAR_TYPE_DEFAULT);
+ entry_t *this;
+ INIT(this,
+ .listener = listener,
+ );
return this;
}
*/
static void entry_destroy(entry_t *entry)
{
- entry->condvar->destroy(entry->condvar);
free(entry);
}
private_bus_t *this, listener_t *listener)
{
this->mutex->lock(this->mutex);
- this->listeners->insert_last(this->listeners, entry_create(listener, FALSE));
+ this->listeners->insert_last(this->listeners, entry_create(listener));
this->mutex->unlock(this->mutex);
}
if (!entry->listener->log(entry->listener, data->group, data->level,
data->thread, data->ike_sa, data->format, args))
{
- if (entry->blocker)
- {
- entry->blocker = FALSE;
- entry->condvar->signal(entry->condvar);
- entry->calling--;
- }
- else
- {
- entry_destroy(entry);
- }
+ entry_destroy(entry);
va_end(args);
return TRUE;
}
static void unregister_listener(private_bus_t *this, entry_t *entry,
enumerator_t *enumerator)
{
- if (entry->blocker)
- {
- entry->blocker = FALSE;
- entry->condvar->signal(entry->condvar);
- }
- else
- {
- entry_destroy(entry);
- }
this->listeners->remove_at(this->listeners, enumerator);
+ entry_destroy(entry);
}
METHOD(bus_t, alert, void,