1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

removed nested functions to enable compilation with Clang

This commit is contained in:
Steffen Vogel 2016-01-14 22:52:08 +01:00
parent b4f787b2c0
commit e59c2d7894
5 changed files with 37 additions and 29 deletions

View file

@ -88,6 +88,9 @@ struct hook {
hook_cb_t cb; /**< The hook callback function as a function pointer. */
};
/** Sort hook list according to the their priority. See hook::priority. */
int hooks_sort_priority(const void *a, const void *b);
/** The following prototypes are example hooks
*
* @addtogroup hooks_examples Examples for hook functions

View file

@ -134,4 +134,7 @@ const char * path_name(struct path *p);
*/
int path_run_hook(struct path *p, enum hook_type t);
/** Check if node is used as source or destination of a path. */
int path_uses_node(struct path *p, struct node *n);
#endif /** _PATH_H_ @} */

View file

@ -13,6 +13,25 @@
#include "list.h"
/* Compare functions */
static int cmp_lookup(const void *a, const void *b) {
const struct {
char *name;
} *obj = a;
return strcmp(obj->name, b);
}
int cmp_contains(const void *a, const void *b) {
return a == b ? 0 : 1;
}
int cmp_sort(const void *a, const void *b, void *thunk) {
cmp_cb_t cmp = (cmp_cb_t) thunk;
return cmp(*(void **) a, *(void **) b);
}
void list_init(struct list *l, dtor_cb_t dtor)
{
pthread_mutex_init(&l->lock, NULL);
@ -80,24 +99,12 @@ void list_remove(struct list *l, void *p)
void * list_lookup(struct list *l, const char *name)
{
int cmp_helper(const void *a, const void *b) {
const struct {
char *name;
} *obj = a;
return strcmp(obj->name, b);
}
return list_search(l, cmp_helper, (void *) name);
return list_search(l, cmp_lookup, (void *) name);
}
int list_contains(struct list *l, void *p)
{
int cmp_helper(const void *a, const void *b) {
return a == b ? 0 : 1;
}
return list_count(l, cmp_helper, p);
{
return list_count(l, cmp_contains, p);
}
int list_count(struct list *l, cmp_cb_t cmp, void *ctx)
@ -118,9 +125,10 @@ int list_count(struct list *l, cmp_cb_t cmp, void *ctx)
void * list_search(struct list *l, cmp_cb_t cmp, void *ctx)
{
void *e;
pthread_mutex_lock(&l->lock);
void *e;
list_foreach(e, l) {
if (!cmp(e, ctx))
goto out;
@ -135,13 +143,9 @@ out: pthread_mutex_unlock(&l->lock);
void list_sort(struct list *l, cmp_cb_t cmp)
{
int cmp_helper(const void *a, const void *b) {
return cmp(*(void **) a, *(void **) b);
}
pthread_mutex_lock(&l->lock);
qsort(l->array, l->length, sizeof(void *), cmp_helper);
qsort_r(l->array, l->length, sizeof(void *), cmp_sort, (void *) cmp);
pthread_mutex_unlock(&l->lock);
}

View file

@ -134,9 +134,7 @@ int path_start(struct path *p)
path_name(p), pool_length(&p->pool), pool_stride(&p->pool), list_length(&p->hooks), p->rate);
/* We sort the hooks according to their priority before starting the path */
list_sort(&p->hooks, ({int cmp(const void *a, const void *b) {
return ((struct hook *) a)->priority - ((struct hook *) b)->priority;
}; &cmp; }));
list_sort(&p->hooks, hooks_sort_priority);
if (path_run_hook(p, HOOK_PATH_START))
return -1;
@ -227,3 +225,7 @@ void path_destroy(struct path *p)
free(p->_name);
free(p);
}
int path_uses_node(struct path *p, struct node *n) {
return (p->in == n) || list_contains(&p->destinations, n) ? 0 : 1;
}

View file

@ -167,11 +167,7 @@ int main(int argc, char *argv[])
info("Starting nodes");
list_foreach(struct node *n, &nodes) { INDENT
int used_by_path(struct path *p, struct node *n) {
return (p->in == n) || list_contains(&p->destinations, n) ? 0 : 1;
}
int refs = list_count(&paths, (cmp_cb_t) used_by_path, n);
int refs = list_count(&paths, (cmp_cb_t) path_uses_node, n);
if (refs > 0)
node_start(n);
else