Module: xenomai-forge Branch: master Commit: 146b9b3363638077af22cbb758000284c3968b64 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=146b9b3363638077af22cbb758000284c3968b64
Author: Philippe Gerum <r...@xenomai.org> Date: Fri Nov 11 18:22:52 2011 +0100 copperplate/threadobj, lib: remove deprecated wait_u The use of the built in wait_u field within the base thread object is discouraged, and deprecated by the threadobj_prepare_wait/threadobj_get_wait constructs. We convert the remaining wait_u users to threadobj_prepare_wait() and remove the wait_u field from the threadobj definition. --- include/copperplate/threadobj.h | 6 ------ lib/psos/queue.c | 38 +++++++++++++++++++++++--------------- lib/psos/queue.h | 5 +++++ lib/psos/rn.c | 19 ++++++++++++------- lib/psos/rn.h | 5 +++++ lib/psos/task.c | 4 ++++ lib/vxworks/msgQLib.c | 30 ++++++++++++++++++------------ lib/vxworks/msgQLib.h | 5 +++++ lib/vxworks/taskLib.c | 2 ++ 9 files changed, 74 insertions(+), 40 deletions(-) diff --git a/include/copperplate/threadobj.h b/include/copperplate/threadobj.h index 286df4d..c2bf675 100644 --- a/include/copperplate/threadobj.h +++ b/include/copperplate/threadobj.h @@ -128,12 +128,6 @@ struct threadobj { struct holder wait_link; int wait_status; int wait_prio; - union { - struct { - void *ptr; - size_t size; - } buffer; - } wait_u; /* XXX: deprecated by wait_union */ void (*wait_hook)(struct threadobj *thobj, int status); void *wait_union; size_t wait_size; diff --git a/lib/psos/queue.c b/lib/psos/queue.c index 6ad22f4..f17aff7 100644 --- a/lib/psos/queue.c +++ b/lib/psos/queue.c @@ -235,6 +235,7 @@ u_long q_vident(const char *name, u_long node, u_long *qid_r) static u_long __q_send_inner(struct psos_queue *q, unsigned long flags, u_long *buffer, u_long bytes) { + struct psos_queue_wait *wait; struct threadobj *thobj; struct msgholder *msg; u_long maxbytes; @@ -242,12 +243,13 @@ static u_long __q_send_inner(struct psos_queue *q, unsigned long flags, thobj = syncobj_peek_at_pend(&q->sobj); if (thobj && threadobj_local_p(thobj)) { /* Fast path: direct copy to the receiver's buffer. */ - maxbytes = thobj->wait_u.buffer.size; + wait = threadobj_get_wait(thobj); + maxbytes = wait->size; if (bytes > maxbytes) bytes = maxbytes; if (bytes > 0) - memcpy(thobj->wait_u.buffer.ptr, buffer, bytes); - thobj->wait_u.buffer.size = bytes; + memcpy(wait->ptr, buffer, bytes); + wait->size = bytes; goto done; } @@ -270,13 +272,15 @@ static u_long __q_send_inner(struct psos_queue *q, unsigned long flags, else list_append(&msg->link, &q->msg_list); - if (thobj) + if (thobj) { /* * We could not copy the message directly to the * remote buffer, tell the thread to pull it from the * pool. */ - thobj->wait_u.buffer.size = -1; + wait = threadobj_get_wait(thobj); + wait->size = -1UL; + } done: if (thobj) syncobj_wakeup_waiter(&q->sobj, thobj); @@ -399,14 +403,14 @@ u_long q_vbroadcast(u_long qid, void *msgbuf, u_long msglen, u_long *count_r) static u_long __q_receive(u_long qid, u_long flags, u_long timeout, void *buffer, u_long msglen, u_long *msglen_r) { + struct psos_queue_wait *wait = NULL; struct timespec ts, *timespec; struct msgholder *msg = NULL; - struct threadobj *current; struct syncstate syns; + unsigned long nbytes; struct psos_queue *q; struct service svc; int ret = SUCCESS; - u_long nbytes; q = get_queue_from_id(qid, &ret); if (q == NULL) @@ -423,7 +427,6 @@ static u_long __q_receive(u_long qid, u_long flags, u_long timeout, ret = (flags & Q_VARIABLE) ? ERR_NOTVARQ: ERR_VARQ; goto fail; } - retry: if (!list_empty(&q->msg_list)) { q->msgcount--; @@ -448,20 +451,22 @@ retry: } else timespec = NULL; - current = threadobj_current(); - current->wait_u.buffer.ptr = buffer; - current->wait_u.buffer.size = msglen; + wait = threadobj_prepare_wait(struct psos_queue_wait); + wait->ptr = buffer; + wait->size = msglen; ret = syncobj_pend(&q->sobj, timespec, &syns); - if (ret == -EIDRM) - return ERR_QKILLD; + if (ret == -EIDRM) { + ret = ERR_QKILLD; + goto out; + } if (ret == -ETIMEDOUT) { ret = ERR_TIMEOUT; goto fail; } - nbytes = current->wait_u.buffer.size; - if (nbytes < 0) /* No direct copy? */ + nbytes = wait->size; + if (nbytes == -1UL) /* No direct copy? */ goto retry; done: if (msglen_r) @@ -469,6 +474,9 @@ done: fail: syncobj_unlock(&q->sobj, &syns); out: + if (wait) + threadobj_finish_wait(); + COPPERPLATE_UNPROTECT(svc); return ret; diff --git a/lib/psos/queue.h b/lib/psos/queue.h index 4543b5b..dd60971 100644 --- a/lib/psos/queue.h +++ b/lib/psos/queue.h @@ -41,6 +41,11 @@ struct psos_queue { struct clusterobj cobj; }; +struct psos_queue_wait { + size_t size; + void *ptr; +}; + extern struct cluster psos_queue_table; #endif /* _PSOS_QUEUE_H */ diff --git a/lib/psos/rn.c b/lib/psos/rn.c index 09c3962..145345b 100644 --- a/lib/psos/rn.c +++ b/lib/psos/rn.c @@ -212,8 +212,8 @@ u_long rn_ident(const char *name, u_long *rnid_r) u_long rn_getseg(u_long rnid, u_long size, u_long flags, u_long timeout, void **segaddr) { + struct psos_rn_wait *wait = NULL; struct timespec ts, *timespec; - struct threadobj *current; struct syncstate syns; struct psos_rn *rn; struct service svc; @@ -258,9 +258,9 @@ starve: } else timespec = NULL; - current = threadobj_current(); - current->wait_u.buffer.ptr = NULL; - current->wait_u.buffer.size = size; + wait = threadobj_prepare_wait(struct psos_rn_wait); + wait->ptr = NULL; + wait->size = size; ret = syncobj_pend(&rn->sobj, timespec, &syns); if (ret == -ETIMEDOUT) @@ -274,10 +274,13 @@ starve: goto out; } - *segaddr = current->wait_u.buffer.ptr; + *segaddr = wait->ptr; done: syncobj_unlock(&rn->sobj, &syns); out: + if (wait) + threadobj_finish_wait(); + COPPERPLATE_UNPROTECT(svc); return ret; @@ -286,6 +289,7 @@ out: u_long rn_retseg(u_long rnid, void *segaddr) { struct threadobj *thobj, *tmp; + struct psos_rn_wait *wait; struct syncstate syns; struct psos_rn *rn; struct service svc; @@ -312,14 +316,15 @@ u_long rn_retseg(u_long rnid, void *segaddr) goto done; syncobj_for_each_waiter_safe(&rn->sobj, thobj, tmp) { - size = thobj->wait_u.buffer.size; + wait = threadobj_get_wait(thobj); + size = wait->size; if (rn->usedmem + size > rn->length) continue; seg = heapobj_alloc(&rn->hobj, size); if (seg) { rn->busynr++; rn->usedmem += heapobj_validate(&rn->hobj, seg); - thobj->wait_u.buffer.ptr = seg; + wait->ptr = seg; syncobj_wakeup_waiter(&rn->sobj, thobj); } } diff --git a/lib/psos/rn.h b/lib/psos/rn.h index 671cc89..56b9ee6 100644 --- a/lib/psos/rn.h +++ b/lib/psos/rn.h @@ -39,6 +39,11 @@ struct psos_rn { struct pvclusterobj cobj; }; +struct psos_rn_wait { + size_t size; + void *ptr; +}; + extern struct pvcluster psos_rn_table; #endif /* _PSOS_RN_H */ diff --git a/lib/psos/task.c b/lib/psos/task.c index 734a9fd..2c54faa 100644 --- a/lib/psos/task.c +++ b/lib/psos/task.c @@ -36,8 +36,12 @@ #include "internal.h" #include "task.h" #include "tm.h" +#include "queue.h" +#include "rn.h" union psos_wait_union { + struct psos_queue_wait queue_wait; + struct psos_rn_wait rn_wait; }; struct cluster psos_task_table; diff --git a/lib/vxworks/msgQLib.c b/lib/vxworks/msgQLib.c index d1838b7..dff542e 100644 --- a/lib/vxworks/msgQLib.c +++ b/lib/vxworks/msgQLib.c @@ -157,9 +157,9 @@ STATUS msgQDelete(MSG_Q_ID msgQId) int msgQReceive(MSG_Q_ID msgQId, char *buffer, UINT maxNBytes, int timeout) { + struct wind_queue_wait *wait = NULL; struct timespec ts, *timespec; struct msgholder *msg = NULL; - struct threadobj *current; UINT nbytes = (UINT)ERROR; struct syncstate syns; struct wind_mq *mq; @@ -209,10 +209,9 @@ retry: } else timespec = NULL; - current = threadobj_current(); - assert(current != NULL); - current->wait_u.buffer.ptr = buffer; - current->wait_u.buffer.size = maxNBytes; + wait = threadobj_prepare_wait(struct wind_queue_wait); + wait->ptr = buffer; + wait->size = maxNBytes; ret = syncobj_pend(&mq->sobj, timespec, &syns); if (ret == -EIDRM) { @@ -223,13 +222,16 @@ retry: errno = S_objLib_OBJ_TIMEOUT; goto done; } - nbytes = current->wait_u.buffer.size; - if (nbytes < 0) /* No direct copy? */ + nbytes = wait->size; + if (nbytes == -1L) /* No direct copy? */ goto retry; syncobj_signal_drain(&mq->sobj); done: syncobj_unlock(&mq->sobj, &syns); + if (wait) + threadobj_finish_wait(); + COPPERPLATE_UNPROTECT(svc); return nbytes; @@ -239,6 +241,7 @@ STATUS msgQSend(MSG_Q_ID msgQId, const char *buffer, UINT bytes, int timeout, int prio) { struct timespec ts, *timespec; + struct wind_queue_wait *wait; struct threadobj *thobj; struct msgholder *msg; struct syncstate syns; @@ -268,12 +271,13 @@ STATUS msgQSend(MSG_Q_ID msgQId, const char *buffer, UINT bytes, thobj = syncobj_peek_at_pend(&mq->sobj); if (thobj && threadobj_local_p(thobj)) { /* Fast path: direct copy to the receiver's buffer. */ - maxbytes = thobj->wait_u.buffer.size; + wait = threadobj_get_wait(thobj); + maxbytes = wait->size; if (bytes > maxbytes) bytes = maxbytes; if (bytes > 0) - memcpy(thobj->wait_u.buffer.ptr, buffer, bytes); - thobj->wait_u.buffer.size = bytes; + memcpy(wait->ptr, buffer, bytes); + wait->size = bytes; goto done; } @@ -331,13 +335,15 @@ enqueue: else list_prepend(&msg->link, &mq->msg_list); - if (thobj) + if (thobj) { /* * We could not copy the message directly to the * remote buffer, tell the thread to pull it from the * pool. */ - thobj->wait_u.buffer.size = -1; + wait = threadobj_get_wait(thobj); + wait->size = -1UL; + } done: if (thobj) /* Wakeup waiter. */ syncobj_wakeup_waiter(&mq->sobj, thobj); diff --git a/lib/vxworks/msgQLib.h b/lib/vxworks/msgQLib.h index 844f8ff..542c7db 100644 --- a/lib/vxworks/msgQLib.h +++ b/lib/vxworks/msgQLib.h @@ -37,4 +37,9 @@ struct wind_mq { struct list msg_list; }; +struct wind_queue_wait { + size_t size; + void *ptr; +}; + #endif /* _VXWORKS_MSGQLIB_H */ diff --git a/lib/vxworks/taskLib.c b/lib/vxworks/taskLib.c index 71771b5..4813c4d 100644 --- a/lib/vxworks/taskLib.c +++ b/lib/vxworks/taskLib.c @@ -28,6 +28,7 @@ #include <sched.h> #include "taskLib.h" #include "tickLib.h" +#include "msgQLib.h" #include "copperplate/init.h" #include "copperplate/heapobj.h" #include "copperplate/threadobj.h" @@ -37,6 +38,7 @@ #include "vxworks/errnoLib.h" union wind_wait_union { + struct wind_queue_wait queue_wait; }; struct cluster wind_task_table; _______________________________________________ Xenomai-git mailing list Xenomai-git@gna.org https://mail.gna.org/listinfo/xenomai-git