Module: xenomai-forge Branch: master Commit: b6ad46decf319f819534f49ff1ff11e1c8a9e8f6 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=b6ad46decf319f819534f49ff1ff11e1c8a9e8f6
Author: Philippe Gerum <r...@xenomai.org> Date: Sun Nov 6 18:09:58 2011 +0100 copperplate/threadobj, lib: fix definition and use of in irq/thread predicates --- include/copperplate/threadobj.h | 19 +++++++++---------- lib/alchemy/buffer.c | 8 ++++---- lib/alchemy/cond.c | 4 ++-- lib/alchemy/event.c | 6 +++--- lib/alchemy/heap.c | 8 ++++---- lib/alchemy/mutex.c | 9 +++------ lib/alchemy/queue.c | 6 +++--- lib/alchemy/sem.c | 7 ++----- lib/alchemy/task.c | 10 +++++----- lib/alchemy/testsuite/Makefile | 3 ++- lib/copperplate/cluster.c | 4 ++-- lib/copperplate/semobj.c | 2 +- lib/copperplate/threadobj.c | 3 --- lib/vxworks/intLib.c | 2 +- lib/vxworks/msgQLib.c | 8 ++++---- lib/vxworks/semLib.c | 10 +++++----- lib/vxworks/taskLib.c | 18 +++++++++--------- 17 files changed, 59 insertions(+), 68 deletions(-) diff --git a/include/copperplate/threadobj.h b/include/copperplate/threadobj.h index 2c2d16f..d6be354 100644 --- a/include/copperplate/threadobj.h +++ b/include/copperplate/threadobj.h @@ -160,8 +160,6 @@ extern int threadobj_high_prio; extern int threadobj_irq_prio; -extern int threadobj_async; - #ifdef __cplusplus extern "C" { #endif @@ -245,10 +243,16 @@ static inline struct threadobj *threadobj_current(void) return pthread_getspecific(threadobj_tskey); } -static inline int threadobj_async_p(void) +static inline int threadobj_irq_p(void) +{ + struct threadobj *current = threadobj_current(); + return current == THREADOBJ_IRQCONTEXT; +} + +static inline int threadobj_current_p(void) { - struct threadobj *thobj = threadobj_current(); - return thobj == THREADOBJ_IRQCONTEXT; + struct threadobj *current = threadobj_current(); + return current && current != THREADOBJ_IRQCONTEXT; } static inline int threadobj_lock_sched_once(struct threadobj *thobj) @@ -273,11 +277,6 @@ static inline int threadobj_sleep(struct timespec *ts) return -__RT(clock_nanosleep(CLOCK_COPPERPLATE, TIMER_ABSTIME, ts, NULL)); } -static inline int threadobj_context_p(void) -{ - return !threadobj_async_p() && threadobj_current(); -} - static inline unsigned int threadobj_get_magic(struct threadobj *thobj) { return thobj->magic; diff --git a/lib/alchemy/buffer.c b/lib/alchemy/buffer.c index 2deb205..5ce2686 100644 --- a/lib/alchemy/buffer.c +++ b/lib/alchemy/buffer.c @@ -90,7 +90,7 @@ int rt_buffer_create(RT_BUFFER *bf, const char *name, int sobj_flags = 0; int ret; - if (threadobj_async_p()) + if (threadobj_irq_p()) return -EPERM; if (bufsz == 0) @@ -151,7 +151,7 @@ int rt_buffer_delete(RT_BUFFER *bf) struct service svc; int ret = 0; - if (threadobj_async_p()) + if (threadobj_irq_p()) return -EPERM; COPPERPLATE_PROTECT(svc); @@ -251,7 +251,7 @@ redo: goto done; } - if (threadobj_async_p()) { + if (!threadobj_current_p()) { ret = -EPERM; goto done; } @@ -385,7 +385,7 @@ redo: goto done; } - if (threadobj_async_p()) { + if (!threadobj_current_p()) { ret = -EPERM; goto done; } diff --git a/lib/alchemy/cond.c b/lib/alchemy/cond.c index a8c1651..dbc45cf 100644 --- a/lib/alchemy/cond.c +++ b/lib/alchemy/cond.c @@ -67,7 +67,7 @@ int rt_cond_create(RT_COND *cond, const char *name) pthread_condattr_t cattr; struct service svc; - if (threadobj_async_p()) + if (threadobj_irq_p()) return -EPERM; COPPERPLATE_PROTECT(svc); @@ -105,7 +105,7 @@ int rt_cond_delete(RT_COND *cond) struct service svc; int ret = 0; - if (threadobj_async_p()) + if (threadobj_irq_p()) return -EPERM; COPPERPLATE_PROTECT(svc); diff --git a/lib/alchemy/event.c b/lib/alchemy/event.c index 60a53b8..1af6806 100644 --- a/lib/alchemy/event.c +++ b/lib/alchemy/event.c @@ -88,7 +88,7 @@ int rt_event_create(RT_EVENT *event, const char *name, struct service svc; int sobj_flags = 0; - if (threadobj_async_p()) + if (threadobj_irq_p()) return -EPERM; COPPERPLATE_PROTECT(svc); @@ -129,7 +129,7 @@ int rt_event_delete(RT_EVENT *event) struct service svc; int ret = 0; - if (threadobj_async_p()) + if (threadobj_irq_p()) return -EPERM; COPPERPLATE_PROTECT(svc); @@ -182,7 +182,7 @@ int rt_event_wait_until(RT_EVENT *event, goto done; } - if (threadobj_async_p()) { + if (!threadobj_current_p()) { ret = -EPERM; goto done; } diff --git a/lib/alchemy/heap.c b/lib/alchemy/heap.c index 8456126..d7a622e 100644 --- a/lib/alchemy/heap.c +++ b/lib/alchemy/heap.c @@ -89,7 +89,7 @@ int rt_heap_create(RT_HEAP *heap, struct service svc; int sobj_flags = 0; - if (threadobj_async_p()) + if (threadobj_irq_p()) return -EPERM; if (heapsize == 0) @@ -144,7 +144,7 @@ int rt_heap_delete(RT_HEAP *heap) struct service svc; int ret = 0; - if (threadobj_async_p()) + if (threadobj_irq_p()) return -EPERM; COPPERPLATE_PROTECT(svc); @@ -173,7 +173,7 @@ int rt_heap_alloc(RT_HEAP *heap, void *p = NULL; int ret = 0; - if (threadobj_async_p()) + if (threadobj_irq_p()) return -EPERM; COPPERPLATE_PROTECT(svc); @@ -208,7 +208,7 @@ int rt_heap_alloc(RT_HEAP *heap, goto done; } - if (threadobj_async_p()) { + if (!threadobj_current_p()) { ret = -EPERM; goto done; } diff --git a/lib/alchemy/mutex.c b/lib/alchemy/mutex.c index 35d84b1..2647dab 100644 --- a/lib/alchemy/mutex.c +++ b/lib/alchemy/mutex.c @@ -67,7 +67,7 @@ int rt_mutex_create(RT_MUTEX *mutex, const char *name) pthread_mutexattr_t mattr; struct service svc; - if (threadobj_async_p()) + if (threadobj_irq_p()) return -EPERM; COPPERPLATE_PROTECT(svc); @@ -110,7 +110,7 @@ int rt_mutex_delete(RT_MUTEX *mutex) struct service svc; int ret = 0; - if (threadobj_async_p()) + if (threadobj_irq_p()) return -EPERM; COPPERPLATE_PROTECT(svc); @@ -209,9 +209,6 @@ int rt_mutex_release(RT_MUTEX *mutex) struct service svc; int ret = 0; - if (threadobj_async_p()) - return -EPERM; - COPPERPLATE_PROTECT(svc); mcb = find_alchemy_mutex(mutex, &ret); @@ -232,7 +229,7 @@ int rt_mutex_inquire(RT_MUTEX *mutex, RT_MUTEX_INFO *info) struct service svc; int ret = 0; - if (threadobj_async_p()) + if (threadobj_irq_p()) return -EPERM; COPPERPLATE_PROTECT(svc); diff --git a/lib/alchemy/queue.c b/lib/alchemy/queue.c index 0495532..3178102 100644 --- a/lib/alchemy/queue.c +++ b/lib/alchemy/queue.c @@ -90,7 +90,7 @@ int rt_queue_create(RT_QUEUE *queue, const char *name, struct service svc; int sobj_flags = 0; - if (threadobj_async_p()) + if (threadobj_irq_p()) return -EPERM; if (poolsize == 0) @@ -146,7 +146,7 @@ int rt_queue_delete(RT_QUEUE *queue) struct service svc; int ret = 0; - if (threadobj_async_p()) + if (threadobj_irq_p()) return -EPERM; COPPERPLATE_PROTECT(svc); @@ -357,7 +357,7 @@ ssize_t rt_queue_receive_until(RT_QUEUE *queue, goto done; } - if (threadobj_async_p()) { + if (!threadobj_current_p()) { ret = -EPERM; goto done; } diff --git a/lib/alchemy/sem.c b/lib/alchemy/sem.c index f411550..905b9d2 100644 --- a/lib/alchemy/sem.c +++ b/lib/alchemy/sem.c @@ -72,7 +72,7 @@ int rt_sem_create(RT_SEM *sem, const char *name, struct alchemy_sem *scb; struct service svc; - if (threadobj_async_p()) + if (threadobj_irq_p()) return -EPERM; if (mode & S_PULSE) { @@ -123,7 +123,7 @@ int rt_sem_delete(RT_SEM *sem) struct service svc; int ret = 0; - if (threadobj_async_p()) + if (threadobj_irq_p()) return -EPERM; COPPERPLATE_PROTECT(svc); @@ -148,9 +148,6 @@ int rt_sem_p_until(RT_SEM *sem, RTIME timeout) struct service svc; int ret = 0; - if (threadobj_async_p()) - return -EPERM; - COPPERPLATE_PROTECT(svc); scb = find_alchemy_sem(sem, &ret); diff --git a/lib/alchemy/task.c b/lib/alchemy/task.c index 9404b5b..7fcfc2e 100644 --- a/lib/alchemy/task.c +++ b/lib/alchemy/task.c @@ -315,7 +315,7 @@ int rt_task_delete(RT_TASK *task) struct service svc; int ret; - if (threadobj_async_p()) + if (threadobj_irq_p()) return -EPERM; tcb = find_alchemy_task_or_self(task, &ret); @@ -466,7 +466,7 @@ int rt_task_sleep(RTIME delay) struct timespec ts; struct service svc; - if (threadobj_async_p()) + if (!threadobj_current_p()) return -EPERM; if (delay == 0) @@ -485,7 +485,7 @@ int rt_task_sleep_until(RTIME date) struct service svc; ticks_t now; - if (threadobj_async_p()) + if (!threadobj_current_p()) return -EPERM; if (date == TM_INFINITE) { @@ -601,7 +601,7 @@ out: int rt_task_yield(void) { - if (threadobj_async_p()) + if (!threadobj_current_p()) return -EPERM; threadobj_yield(); @@ -658,7 +658,7 @@ int rt_task_set_mode(int clrmask, int setmask, int *mode_r) struct service svc; int ret = 0; - if (threadobj_async_p()) { + if (threadobj_irq_p()) { clrmask &= ~T_LOCK; setmask &= ~T_LOCK; return (clrmask | setmask) ? -EPERM : 0; diff --git a/lib/alchemy/testsuite/Makefile b/lib/alchemy/testsuite/Makefile index 6880619..5562b49 100644 --- a/lib/alchemy/testsuite/Makefile +++ b/lib/alchemy/testsuite/Makefile @@ -13,7 +13,8 @@ endif TESTS := \ task-1 \ - task-2 + task-2 \ + task-3 CFLAGS := $(shell DESTDIR=$(DESTDIR) $(XENO_CONFIG) --skin=alchemy --cflags) -g LDFLAGS := $(shell DESTDIR=$(DESTDIR) $(XENO_CONFIG) --skin=alchemy --ldflags) diff --git a/lib/copperplate/cluster.c b/lib/copperplate/cluster.c index ece60d0..c084161 100644 --- a/lib/copperplate/cluster.c +++ b/lib/copperplate/cluster.c @@ -292,7 +292,7 @@ int syncluster_findobj(struct syncluster *sc, ret = -EWOULDBLOCK; break; } - if (threadobj_async_p()) { + if (!threadobj_current_p()) { ret = -EPERM; break; } @@ -442,7 +442,7 @@ int pvsyncluster_findobj(struct pvsyncluster *sc, ret = -EWOULDBLOCK; break; } - if (threadobj_async_p()) { + if (!threadobj_current_p()) { ret = -EPERM; break; } diff --git a/lib/copperplate/semobj.c b/lib/copperplate/semobj.c index de7983d..a45b333 100644 --- a/lib/copperplate/semobj.c +++ b/lib/copperplate/semobj.c @@ -215,7 +215,7 @@ int semobj_wait(struct semobj *smobj, struct timespec *timeout) goto done; } - if (threadobj_async_p()) { + if (!threadobj_current_p()) { ret = -EPERM; goto done; } diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c index c13cf54..83ff673 100644 --- a/lib/copperplate/threadobj.c +++ b/lib/copperplate/threadobj.c @@ -58,8 +58,6 @@ int threadobj_high_prio; int threadobj_irq_prio; -int threadobj_async; - static DEFINE_PRIVATE_LIST(thread_list); static pthread_mutex_t list_lock; @@ -1000,7 +998,6 @@ void threadobj_pkg_init(void) { threadobj_irq_prio = __RT(sched_get_priority_max(SCHED_RT)); threadobj_high_prio = threadobj_irq_prio - 1; - threadobj_async = 0; debug("SCHED_RT priorities => [1 .. %d]", threadobj_irq_prio); debug("SCHED_RT.%d reserved for timer context", threadobj_irq_prio); diff --git a/lib/vxworks/intLib.c b/lib/vxworks/intLib.c index 57fbd81..cf07b22 100644 --- a/lib/vxworks/intLib.c +++ b/lib/vxworks/intLib.c @@ -21,5 +21,5 @@ BOOL intContext(void) { - return threadobj_async_p(); + return threadobj_irq_p(); } diff --git a/lib/vxworks/msgQLib.c b/lib/vxworks/msgQLib.c index 53692e6..79ea884 100644 --- a/lib/vxworks/msgQLib.c +++ b/lib/vxworks/msgQLib.c @@ -69,7 +69,7 @@ MSG_Q_ID msgQCreate(int maxMsgs, int maxMsgLength, int options) int sobj_flags = 0; struct service svc; - if (threadobj_async_p()) { + if (threadobj_irq_p()) { errno = S_intLib_NOT_ISR_CALLABLE; return (MSG_Q_ID)0; } @@ -129,7 +129,7 @@ STATUS msgQDelete(MSG_Q_ID msgQId) struct wind_mq *mq; struct service svc; - if (threadobj_async_p()) { + if (threadobj_irq_p()) { errno = S_intLib_NOT_ISR_CALLABLE; return ERROR; } @@ -166,7 +166,7 @@ int msgQReceive(MSG_Q_ID msgQId, char *buffer, UINT maxNBytes, int timeout) struct service svc; int ret; - if (threadobj_async_p()) { + if (threadobj_irq_p()) { errno = S_intLib_NOT_ISR_CALLABLE; return ERROR; } @@ -285,7 +285,7 @@ STATUS msgQSend(MSG_Q_ID msgQId, const char *buffer, UINT bytes, goto fail; } - if (threadobj_async_p()) { + if (threadobj_irq_p()) { errno = S_msgQLib_NON_ZERO_TIMEOUT_AT_INT_LEVEL; goto fail; } diff --git a/lib/vxworks/semLib.c b/lib/vxworks/semLib.c index bab3883..5f8588f 100644 --- a/lib/vxworks/semLib.c +++ b/lib/vxworks/semLib.c @@ -61,7 +61,7 @@ static STATUS xsem_take(struct wind_sem *sem, int timeout) struct service svc; STATUS ret = OK; - if (threadobj_async_p()) + if (threadobj_irq_p()) return S_intLib_NOT_ISR_CALLABLE; COPPERPLATE_PROTECT(svc); @@ -168,7 +168,7 @@ static STATUS xsem_delete(struct wind_sem *sem) struct service svc; int ret = OK; - if (threadobj_async_p()) + if (threadobj_irq_p()) return S_intLib_NOT_ISR_CALLABLE; COPPERPLATE_PROTECT(svc); @@ -226,7 +226,7 @@ static STATUS msem_take(struct wind_sem *sem, int timeout) struct timespec ts; int ret; - if (threadobj_async_p()) + if (threadobj_irq_p()) return S_intLib_NOT_ISR_CALLABLE; current = wind_task_current(); @@ -278,7 +278,7 @@ static STATUS msem_give(struct wind_sem *sem) struct wind_task *current; int ret; - if (threadobj_async_p()) + if (threadobj_irq_p()) return S_intLib_NOT_ISR_CALLABLE; ret = __RT(pthread_mutex_unlock(&sem->u.msem.lock)); @@ -305,7 +305,7 @@ static STATUS msem_delete(struct wind_sem *sem) { int ret; - if (threadobj_async_p()) + if (threadobj_irq_p()) return S_intLib_NOT_ISR_CALLABLE; ret = __RT(pthread_mutex_destroy(&sem->u.msem.lock)); diff --git a/lib/vxworks/taskLib.c b/lib/vxworks/taskLib.c index 9b9d36d..75c37d2 100644 --- a/lib/vxworks/taskLib.c +++ b/lib/vxworks/taskLib.c @@ -418,7 +418,7 @@ STATUS taskInit(WIND_TCB *pTcb, struct service svc; STATUS ret = ERROR; - if (threadobj_async_p()) { + if (threadobj_irq_p()) { errno = S_intLib_NOT_ISR_CALLABLE; return ERROR; } @@ -478,7 +478,7 @@ TASK_ID taskSpawn(const char *name, struct service svc; TASK_ID tid; - if (threadobj_async_p()) { + if (threadobj_irq_p()) { errno = S_intLib_NOT_ISR_CALLABLE; return ERROR; } @@ -523,7 +523,7 @@ static STATUS __taskDelete(TASK_ID tid, int force) struct wind_task *task; int ret; - if (threadobj_async_p()) { + if (threadobj_irq_p()) { errno = S_intLib_NOT_ISR_CALLABLE; return ERROR; } @@ -585,7 +585,7 @@ TASK_ID taskIdSelf(void) { struct wind_task *current; - if (threadobj_async_p()) { + if (threadobj_irq_p()) { errno = S_intLib_NOT_ISR_CALLABLE; return ERROR; } @@ -664,7 +664,7 @@ STATUS taskSafe(void) { struct wind_task *current; - if (threadobj_async_p()) { + if (threadobj_irq_p()) { errno = S_intLib_NOT_ISR_CALLABLE; return ERROR; } @@ -690,7 +690,7 @@ STATUS taskUnsafe(void) struct wind_task *current; int ret; - if (threadobj_async_p()) { + if (threadobj_irq_p()) { errno = S_intLib_NOT_ISR_CALLABLE; return ERROR; } @@ -785,7 +785,7 @@ STATUS taskLock(void) struct wind_task *task; struct service svc; - if (threadobj_async_p()) { + if (threadobj_irq_p()) { errno = S_intLib_NOT_ISR_CALLABLE; return ERROR; } @@ -809,7 +809,7 @@ STATUS taskUnlock(void) struct wind_task *task; struct service svc; - if (threadobj_async_p()) { + if (threadobj_irq_p()) { errno = S_intLib_NOT_ISR_CALLABLE; return ERROR; } @@ -835,7 +835,7 @@ STATUS taskDelay(int ticks) struct service svc; int ret; - if (threadobj_async_p()) { + if (threadobj_irq_p()) { errno = S_intLib_NOT_ISR_CALLABLE; return ERROR; } _______________________________________________ Xenomai-git mailing list Xenomai-git@gna.org https://mail.gna.org/listinfo/xenomai-git