Module: xenomai-forge Branch: next Commit: d8814f00c0d9c1f860272b2be234a3db30cea2e2 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=d8814f00c0d9c1f860272b2be234a3db30cea2e2
Author: Philippe Gerum <r...@xenomai.org> Date: Thu Jun 20 14:21:27 2013 +0200 cobalt/kernel/select: turn queues into regular kernel lists --- include/cobalt/kernel/select.h | 34 +++++++------ kernel/cobalt/select.c | 100 ++++++++++++++++++--------------------- 2 files changed, 64 insertions(+), 70 deletions(-) diff --git a/include/cobalt/kernel/select.h b/include/cobalt/kernel/select.h index 618b245..20398f4 100644 --- a/include/cobalt/kernel/select.h +++ b/include/cobalt/kernel/select.h @@ -22,12 +22,13 @@ * \ingroup select */ -#ifndef _COBALT_KERNEL_XNSELECT_H -#define _COBALT_KERNEL_XNSELECT_H +#ifndef _COBALT_KERNEL_SELECT_H +#define _COBALT_KERNEL_SELECT_H /*! \addtogroup select *@{*/ +#include <cobalt/kernel/list.h> #include <cobalt/kernel/thread.h> #define XNSELECT_READ 0 @@ -41,8 +42,8 @@ struct xnselector { fd_set expected; fd_set pending; } fds [XNSELECT_MAX_TYPES]; - xnholder_t destroy_link; - xnqueue_t bindings; /* only used by xnselector_destroy */ + struct list_head destroy_link; + struct list_head bindings; /* only used by xnselector_destroy */ }; #define __NFDBITS__ (8 * sizeof(unsigned long)) @@ -85,7 +86,7 @@ static inline void __FD_ZERO__(__kernel_fd_set *__p) } struct xnselect { - xnqueue_t bindings; + struct list_head bindings; }; #define DECLARE_XNSELECT(name) struct xnselect name @@ -93,10 +94,10 @@ struct xnselect { struct xnselect_binding { struct xnselector *selector; struct xnselect *fd; - unsigned type; - unsigned bit_index; - xnholder_t link; /* link in selected fds list. */ - xnholder_t slink; /* link in selector list */ + unsigned int type; + unsigned int bit_index; + struct list_head link; /* link in selected fds list. */ + struct list_head slink; /* link in selector list */ }; void xnselect_init(struct xnselect *select_block); @@ -104,11 +105,11 @@ void xnselect_init(struct xnselect *select_block); int xnselect_bind(struct xnselect *select_block, struct xnselect_binding *binding, struct xnselector *selector, - unsigned type, - unsigned bit_index, - unsigned state); + unsigned int type, + unsigned int bit_index, + unsigned int state); -int __xnselect_signal(struct xnselect *select_block, unsigned state); +int __xnselect_signal(struct xnselect *select_block, unsigned int state); /** * Signal a file descriptor state change. @@ -121,10 +122,11 @@ int __xnselect_signal(struct xnselect *select_block, unsigned state); * @retval 0 otherwise. */ static inline int -xnselect_signal(struct xnselect *select_block, unsigned state) +xnselect_signal(struct xnselect *select_block, unsigned int state) { - if (!emptyq_p(&select_block->bindings)) + if (!list_empty(&select_block->bindings)) return __xnselect_signal(select_block, state); + return 0; } @@ -146,4 +148,4 @@ int xnselect_umount(void); /*@}*/ -#endif /* _COBALT_KERNEL_XNSELECT_H */ +#endif /* _COBALT_KERNEL_SELECT_H */ diff --git a/kernel/cobalt/select.c b/kernel/cobalt/select.c index f44a428..b3838c3 100644 --- a/kernel/cobalt/select.c +++ b/kernel/cobalt/select.c @@ -46,19 +46,16 @@ * housekeeping. *@{*/ +#include <linux/types.h> +#include <linux/bitops.h> /* For hweight_long */ #include <cobalt/kernel/heap.h> #include <cobalt/kernel/pod.h> #include <cobalt/kernel/synch.h> #include <cobalt/kernel/select.h> #include <cobalt/kernel/apc.h> -#include <linux/types.h> -#include <linux/bitops.h> /* For hweight_long */ - -static xnqueue_t xnselectors; -static int xnselect_apc; -#define link2binding(baddr, memb) \ - container_of(baddr, struct xnselect_binding, memb) +static LIST_HEAD(selector_list); +static int deletion_apc; /** * Initialize a @a struct @a xnselect structure. @@ -70,7 +67,7 @@ static int xnselect_apc; */ void xnselect_init(struct xnselect *select_block) { - initq(&select_block->bindings); + INIT_LIST_HEAD(&select_block->bindings); } EXPORT_SYMBOL_GPL(xnselect_init); @@ -122,11 +119,9 @@ int xnselect_bind(struct xnselect *select_block, binding->fd = select_block; binding->type = type; binding->bit_index = index; - inith(&binding->link); - inith(&binding->slink); - appendq(&selector->bindings, &binding->slink); - appendq(&select_block->bindings, &binding->link); + list_add_tail(&binding->slink, &selector->bindings); + list_add_tail(&binding->link, &select_block->bindings); __FD_SET__(index, &selector->fds[type].expected); if (state) { __FD_SET__(index, &selector->fds[type].pending); @@ -142,16 +137,11 @@ EXPORT_SYMBOL_GPL(xnselect_bind); /* Must be called with nklock locked irqs off */ int __xnselect_signal(struct xnselect *select_block, unsigned state) { - xnholder_t *holder; - int resched; - - for(resched = 0, holder = getheadq(&select_block->bindings); - holder; holder = nextq(&select_block->bindings, holder)) { - struct xnselect_binding *binding; - struct xnselector *selector; - - binding = link2binding(holder, link); + struct xnselect_binding *binding; + struct xnselector *selector; + int resched = 0; + list_for_each_entry(binding, &select_block->bindings, link) { selector = binding->selector; if (state) { if (!__FD_ISSET__(binding->bit_index, @@ -179,18 +169,19 @@ EXPORT_SYMBOL_GPL(__xnselect_signal); */ void xnselect_destroy(struct xnselect *select_block) { - xnholder_t *holder; + struct xnselect_binding *binding, *tmp; + struct xnselector *selector; int resched = 0; spl_t s; xnlock_get_irqsave(&nklock, s); - while ((holder = getq(&select_block->bindings))) { - struct xnselect_binding *binding; - struct xnselector *selector; - binding = link2binding(holder, link); - selector = binding->selector; + if (list_empty(&select_block->bindings)) + goto out; + list_for_each_entry_safe(binding, tmp, &select_block->bindings, link) { + list_del(&binding->link); + selector = binding->selector; __FD_CLR__(binding->bit_index, &selector->fds[binding->type].expected); if (!__FD_ISSET__(binding->bit_index, @@ -200,15 +191,14 @@ void xnselect_destroy(struct xnselect *select_block) if (xnselect_wakeup(selector)) resched = 1; } - removeq(&selector->bindings, &binding->slink); + list_del(&binding->slink); xnlock_put_irqrestore(&nklock, s); - xnfree(binding); - xnlock_get_irqsave(&nklock, s); } if (resched) xnpod_schedule(); +out: xnlock_put_irqrestore(&nklock, s); } EXPORT_SYMBOL_GPL(xnselect_destroy); @@ -285,14 +275,15 @@ static unsigned fd_set_popcount(fd_set *set, unsigned n) */ int xnselector_init(struct xnselector *selector) { - unsigned i; + unsigned int i; xnsynch_init(&selector->synchbase, XNSYNCH_FIFO, NULL); for (i = 0; i < XNSELECT_MAX_TYPES; i++) { __FD_ZERO__(&selector->fds[i].expected); __FD_ZERO__(&selector->fds[i].pending); } - initq(&selector->bindings); + INIT_LIST_HEAD(&selector->bindings); + return 0; } EXPORT_SYMBOL_GPL(xnselector_init); @@ -399,39 +390,40 @@ void xnselector_destroy(struct xnselector *selector) { spl_t s; - inith(&selector->destroy_link); xnlock_get_irqsave(&nklock, s); - appendq(&xnselectors, &selector->destroy_link); - __xnapc_schedule(xnselect_apc); + list_add_tail(&selector->destroy_link, &selector_list); + __xnapc_schedule(deletion_apc); xnlock_put_irqrestore(&nklock, s); } EXPORT_SYMBOL_GPL(xnselector_destroy); static void xnselector_destroy_loop(void *cookie) { - struct xnselector *selector; - xnholder_t *holder; + struct xnselect_binding *binding, *tmpb; + struct xnselector *selector, *tmps; + struct xnselect *fd; int resched; spl_t s; xnlock_get_irqsave(&nklock, s); - while ((holder = getq(&xnselectors))) { - selector = container_of(holder, struct xnselector, destroy_link); - while ((holder = getq(&selector->bindings))) { - struct xnselect_binding *binding; - struct xnselect *fd; - binding = link2binding(holder, slink); + if (list_empty(&selector_list)) + goto out; + + list_for_each_entry_safe(selector, tmps, &selector_list, destroy_link) { + list_del(&selector->destroy_link); + if (list_empty(&selector->bindings)) + goto release; + list_for_each_entry_safe(binding, tmpb, &selector->bindings, slink) { + list_del(&binding->slink); fd = binding->fd; - removeq(&fd->bindings, &binding->link); + list_del(&binding->link); xnlock_put_irqrestore(&nklock, s); - xnfree(binding); - xnlock_get_irqsave(&nklock, s); } - resched = - xnsynch_destroy(&selector->synchbase) == XNSYNCH_RESCHED; + release: + resched = xnsynch_destroy(&selector->synchbase) == XNSYNCH_RESCHED; xnlock_put_irqrestore(&nklock, s); xnfree(selector); @@ -440,23 +432,23 @@ static void xnselector_destroy_loop(void *cookie) xnlock_get_irqsave(&nklock, s); } +out: xnlock_put_irqrestore(&nklock, s); } int xnselect_mount(void) { - initq(&xnselectors); - xnselect_apc = xnapc_alloc("xnselectors_destroy", - xnselector_destroy_loop, NULL); - if (xnselect_apc < 0) - return xnselect_apc; + deletion_apc = xnapc_alloc("selector_list_destroy", + xnselector_destroy_loop, NULL); + if (deletion_apc < 0) + return deletion_apc; return 0; } int xnselect_umount(void) { - xnapc_free(xnselect_apc); + xnapc_free(deletion_apc); return 0; } _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git