Module: xenomai-rpm Branch: for-upstream Commit: 5f3b0f1055ef6c1b595de59789146e4b48872e6b URL: http://git.xenomai.org/?p=xenomai-rpm.git;a=commit;h=5f3b0f1055ef6c1b595de59789146e4b48872e6b
Author: Philippe Gerum <r...@xenomai.org> Date: Sun Apr 11 19:36:35 2010 +0200 nucleus: reduce overhead of thread handle lookup --- include/nucleus/registry.h | 24 ++++++++++++++++++++++++ include/nucleus/thread.h | 2 +- ksrc/nucleus/registry.c | 42 ++++++++++-------------------------------- 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/include/nucleus/registry.h b/include/nucleus/registry.h index 56826db..6bd5ec9 100644 --- a/include/nucleus/registry.h +++ b/include/nucleus/registry.h @@ -110,6 +110,8 @@ typedef struct xnpnode { /* Placeholder. */ #endif /* !CONFIG_PROC_FS */ +extern struct xnobject *registry_obj_slots; + /* Public interface. */ int xnregistry_enter(const char *key, @@ -133,6 +135,28 @@ void *xnregistry_fetch(xnhandle_t handle); u_long xnregistry_put(xnhandle_t handle); +static inline struct xnobject *xnregistry_validate(xnhandle_t handle) +{ + struct xnobject *object; + /* + * Careful: a removed object which is still in flight to be + * unexported carries a NULL objaddr, so we have to check this + * as well. + */ + if (likely(handle && handle < CONFIG_XENO_OPT_REGISTRY_NRSLOTS)) { + object = ®istry_obj_slots[handle]; + return object->objaddr ? object : NULL; + } + + return NULL; +} + +static inline void *xnregistry_lookup(xnhandle_t handle) +{ + struct xnobject *object = xnregistry_validate(handle); + return object ? object->objaddr : NULL; +} + #ifdef __cplusplus } #endif diff --git a/include/nucleus/thread.h b/include/nucleus/thread.h index b2baccb..1867915 100644 --- a/include/nucleus/thread.h +++ b/include/nucleus/thread.h @@ -428,7 +428,7 @@ int xnthread_register(struct xnthread *thread, const char *name) static inline struct xnthread *xnthread_lookup(xnhandle_t threadh) { - struct xnthread *thread = xnregistry_fetch(threadh); + struct xnthread *thread = xnregistry_lookup(threadh); return (thread && xnthread_handle(thread) == threadh) ? thread : NULL; } diff --git a/ksrc/nucleus/registry.c b/ksrc/nucleus/registry.c index 9958dd3..4df31ba 100644 --- a/ksrc/nucleus/registry.c +++ b/ksrc/nucleus/registry.c @@ -46,7 +46,7 @@ #define CONFIG_XENO_OPT_DEBUG_REGISTRY 0 #endif -static xnobject_t *registry_obj_slots; +struct xnobject *registry_obj_slots; static xnqueue_t registry_obj_freeq; /* Free objects. */ @@ -232,16 +232,6 @@ void xnregistry_cleanup(void) CONFIG_XENO_OPT_REGISTRY_NRSLOTS * sizeof(xnobject_t)); } -static inline xnobject_t *registry_validate(xnhandle_t handle) -{ - if (handle > 0 && handle < CONFIG_XENO_OPT_REGISTRY_NRSLOTS) { - xnobject_t *object = ®istry_obj_slots[handle]; - return object->objaddr ? object : NULL; - } - - return NULL; -} - #ifdef CONFIG_PROC_FS /* * The following stuff implements the mechanism for delegating @@ -823,9 +813,8 @@ int xnregistry_remove(xnhandle_t handle) xnlock_get_irqsave(&nklock, s); - object = registry_validate(handle); - - if (!object) { + object = xnregistry_validate(handle); + if (object == NULL) { err = -ESRCH; goto unlock_and_exit; } @@ -932,9 +921,8 @@ int xnregistry_remove_safe(xnhandle_t handle, xnticks_t timeout) xnlock_get_irqsave(&nklock, s); - object = registry_validate(handle); - - if (!object) { + object = xnregistry_validate(handle); + if (object == NULL) { err = -ESRCH; goto unlock_and_exit; } @@ -1047,9 +1035,8 @@ void *xnregistry_get(xnhandle_t handle) xnlock_get_irqsave(&nklock, s); - object = registry_validate(handle); - - if (object) { + object = xnregistry_validate(handle); + if (likely(object)) { ++object->safelock; objaddr = object->objaddr; } else @@ -1107,9 +1094,8 @@ u_long xnregistry_put(xnhandle_t handle) xnlock_get_irqsave(&nklock, s); - object = registry_validate(handle); - - if (!object) { + object = xnregistry_validate(handle); + if (object == NULL) { newlock = 0; goto unlock_and_exit; } @@ -1159,18 +1145,10 @@ EXPORT_SYMBOL_GPL(xnregistry_put); void *xnregistry_fetch(xnhandle_t handle) { - xnobject_t *object; - if (handle == XNOBJECT_SELF) return xnpod_primary_p()? xnpod_current_thread() : NULL; - object = registry_validate(handle); - - if (!object) - return NULL; - - return object->objaddr; - + return xnregistry_lookup(handle); } EXPORT_SYMBOL_GPL(xnregistry_fetch); _______________________________________________ Xenomai-git mailing list Xenomai-git@gna.org https://mail.gna.org/listinfo/xenomai-git