Module: xenomai-forge Branch: master Commit: 2fc47236b46afd7c655634cfc9e83e3c1fa0ef68 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=2fc47236b46afd7c655634cfc9e83e3c1fa0ef68
Author: Philippe Gerum <r...@xenomai.org> Date: Mon Nov 28 16:38:49 2011 +0100 lib/cobalt: factor out mutex/cond data accessors --- lib/cobalt/cond.c | 25 +--------------- lib/cobalt/internal.c | 69 +++++++++++++++++------------------------- lib/cobalt/internal.h | 25 +++++++++++++++ lib/copperplate/Makefile.am | 1 + lib/copperplate/Makefile.in | 2 +- 5 files changed, 56 insertions(+), 66 deletions(-) diff --git a/lib/cobalt/cond.c b/lib/cobalt/cond.c index c1639c8..3e18ee7 100644 --- a/lib/cobalt/cond.c +++ b/lib/cobalt/cond.c @@ -19,36 +19,13 @@ #include <errno.h> #include <nucleus/synch.h> #include <cobalt/syscall.h> -#include <kernel/cobalt/mutex.h> -#include <kernel/cobalt/cond.h> #include <asm-generic/bits/current.h> +#include "internal.h" extern int __cobalt_muxid; extern unsigned long xeno_sem_heap[2]; -static inline unsigned long *cond_get_signalsp(struct __shadow_cond *shadow) -{ - if (likely(!shadow->attr.pshared)) - return shadow->pending_signals; - - return (unsigned long *)(xeno_sem_heap[1] - + shadow->pending_signals_offset); -} - -static inline struct mutex_dat * -cond_get_mutex_datp(struct __shadow_cond *shadow) -{ - if (shadow->mutex_datp == (struct mutex_dat *)~0UL) - return NULL; - - if (likely(!shadow->attr.pshared)) - return shadow->mutex_datp; - - return (struct mutex_dat *)(xeno_sem_heap[1] - + shadow->mutex_datp_offset); -} - int __wrap_pthread_condattr_init(pthread_condattr_t *attr) { return -XENOMAI_SKINCALL1(__cobalt_muxid, __cobalt_condattr_init, attr); diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c index d09420c..1e59154 100644 --- a/lib/cobalt/internal.c +++ b/lib/cobalt/internal.c @@ -21,14 +21,15 @@ #include <string.h> #include <errno.h> #include <signal.h> -#include <unistd.h> +#include <signal.h> +#include <limits.h> #include <pthread.h> #include <sys/types.h> #include <semaphore.h> +#include <nucleus/synch.h> #include <cobalt/syscall.h> -#include <kernel/cobalt/mutex.h> -#include <kernel/cobalt/cond.h> #include <asm-generic/bits/current.h> +#include "internal.h" extern int __cobalt_muxid; @@ -47,49 +48,31 @@ int __cobalt_thread_stat(pthread_t tid, struct cobalt_threadstat *stat) __cobalt_thread_getstat, tid, stat); } -static inline unsigned long *cond_get_signalsp(struct __shadow_cond *shadow) -{ - if (likely(!shadow->attr.pshared)) - return shadow->pending_signals; - - return (unsigned long *)(xeno_sem_heap[1] - + shadow->pending_signals_offset); -} - -static inline struct mutex_dat * -cond_get_mutex_datp(struct __shadow_cond *shadow) -{ - if (shadow->mutex_datp == (struct mutex_dat *)~0UL) - return NULL; - - if (likely(!shadow->attr.pshared)) - return shadow->mutex_datp; - - return (struct mutex_dat *)(xeno_sem_heap[1] - + shadow->mutex_datp_offset); -} - int __cobalt_event_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) { struct __shadow_cond *_cnd; struct __shadow_mutex *_mx; + int ret, _ret = 0, oldtype; unsigned int count; - int err, _err = 0; _cnd = &((union __xeno_cond *)cond)->shadow_cond; _mx = &((union __xeno_mutex *)mutex)->shadow_mutex; count = _mx->lockcnt; - err = XENOMAI_SKINCALL5(__cobalt_muxid, - __cobalt_cond_wait_prologue, - _cnd, _mx, &_err, 0, NULL); - while (err == -EINTR) - err = XENOMAI_SKINCALL2(__cobalt_muxid, - __cobalt_cond_wait_epilogue, _cnd, _mx); + pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); + + ret = XENOMAI_SKINCALL5(__cobalt_muxid, + __cobalt_cond_wait_prologue, + _cnd, _mx, &_ret, 0, NULL); + pthread_setcanceltype(oldtype, NULL); + + while (ret == -EINTR) + ret = XENOMAI_SKINCALL2(__cobalt_muxid, + __cobalt_cond_wait_epilogue, _cnd, _mx); _mx->lockcnt = count; - return -err ?: -_err; + return -ret ?: -_ret; } int __cobalt_event_timedwait(pthread_cond_t *cond, @@ -98,23 +81,27 @@ int __cobalt_event_timedwait(pthread_cond_t *cond, { struct __shadow_cond *_cnd; struct __shadow_mutex *_mx; + int ret, _ret = 0, oldtype; unsigned int count; - int err, _err = 0; _cnd = &((union __xeno_cond *)cond)->shadow_cond; _mx = &((union __xeno_mutex *)mutex)->shadow_mutex; count = _mx->lockcnt; - err = XENOMAI_SKINCALL5(__cobalt_muxid, - __cobalt_cond_wait_prologue, - _cnd, _mx, &_err, 1, abstime); - while (err == -EINTR) - err = XENOMAI_SKINCALL2(__cobalt_muxid, - __cobalt_cond_wait_epilogue, _cnd, _mx); + pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); + + ret = XENOMAI_SKINCALL5(__cobalt_muxid, + __cobalt_cond_wait_prologue, + _cnd, _mx, &_ret, 1, abstime); + pthread_setcanceltype(oldtype, NULL); + + while (ret == -EINTR) + ret = XENOMAI_SKINCALL2(__cobalt_muxid, + __cobalt_cond_wait_epilogue, _cnd, _mx); _mx->lockcnt = count; - return -err ?: -_err; + return -ret ?: -_ret; } int __cobalt_event_signal(pthread_cond_t *cond) diff --git a/lib/cobalt/internal.h b/lib/cobalt/internal.h index 7d9b3b6..bfa7e73 100644 --- a/lib/cobalt/internal.h +++ b/lib/cobalt/internal.h @@ -1,6 +1,31 @@ #ifndef XENO_COBALT_INTERNAL_H #define XENO_COBALT_INTERNAL_H +#include <kernel/cobalt/mutex.h> +#include <kernel/cobalt/cond.h> + +static inline unsigned long *cond_get_signalsp(struct __shadow_cond *shadow) +{ + if (likely(!shadow->attr.pshared)) + return shadow->pending_signals; + + return (unsigned long *)(xeno_sem_heap[1] + + shadow->pending_signals_offset); +} + +static inline struct mutex_dat * +cond_get_mutex_datp(struct __shadow_cond *shadow) +{ + if (shadow->mutex_datp == (struct mutex_dat *)~0UL) + return NULL; + + if (likely(!shadow->attr.pshared)) + return shadow->mutex_datp; + + return (struct mutex_dat *)(xeno_sem_heap[1] + + shadow->mutex_datp_offset); +} + void __cobalt_thread_harden(void); int __cobalt_thread_stat(pthread_t tid, diff --git a/lib/copperplate/Makefile.am b/lib/copperplate/Makefile.am index a66ea79..ea02557 100644 --- a/lib/copperplate/Makefile.am +++ b/lib/copperplate/Makefile.am @@ -17,6 +17,7 @@ libcopperplate_la_SOURCES = \ libcopperplate_la_CPPFLAGS = \ @XENO_USER_CFLAGS@ \ + -I$(top_srcdir) \ -I$(top_srcdir)/include libcopperplate_la_LIBADD = diff --git a/lib/copperplate/Makefile.in b/lib/copperplate/Makefile.in index 404b86f..025d75f 100644 --- a/lib/copperplate/Makefile.in +++ b/lib/copperplate/Makefile.in @@ -315,7 +315,7 @@ libcopperplate_la_SOURCES = clockobj.c cluster.c hash.c init.c \ internal.c internal.h syncobj.c semobj.c threadobj.c \ traceobj.c $(am__append_1) $(am__append_3) $(am__append_5) \ $(am__append_6) $(am__append_8) $(am__append_9) -libcopperplate_la_CPPFLAGS = @XENO_USER_CFLAGS@ \ +libcopperplate_la_CPPFLAGS = @XENO_USER_CFLAGS@ -I$(top_srcdir) \ -I$(top_srcdir)/include $(am__append_2) libcopperplate_la_LIBADD = $(am__append_4) $(am__append_7) @XENO_REGISTRY_TRUE@noinst_LTLIBRARIES = libregistry.la _______________________________________________ Xenomai-git mailing list Xenomai-git@gna.org https://mail.gna.org/listinfo/xenomai-git