From 6ca28bbf8523713e34ed2a7378e21f23cf64e298 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 18 Jan 2012 11:35:03 -0500 Subject: Organize workers in free and busy lists This avoids going through an array to chase free threads, so that assigning work is O(1) instead of O(n). Will also make easier to later change the number of available workers dynamically. --- proxy/src/gp_utils.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'proxy/src/gp_utils.h') diff --git a/proxy/src/gp_utils.h b/proxy/src/gp_utils.h index 47d766d..38ca400 100644 --- a/proxy/src/gp_utils.h +++ b/proxy/src/gp_utils.h @@ -33,6 +33,31 @@ #define _(STRING) gettext(STRING) +/* add element to list head */ +#define LIST_ADD(list, elem) do { \ + elem->prev = NULL; \ + elem->next = list; \ + if (list) { \ + list->prev = elem; \ + } \ + list = elem; \ +} while (0) + +/* remove element from list */ +#define LIST_DEL(list, elem) do { \ + if (elem->next) { \ + elem->next->prev = elem->prev; \ + } \ + if (elem->prev) { \ + elem->prev->next = elem->next; \ + } \ + if (list == elem) { \ + list = elem->next; \ + } \ + elem->prev = NULL; \ + elem->next = NULL; \ +} while (0) + struct gp_config { char *config_file; /* gssproxy configuration file */ bool daemonize; /* let gssproxy daemonize */ -- cgit