From 1b269aa139ba66288cc2c3f1b463c73821343262 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 2 Oct 2007 16:52:18 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@29 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- src/chevents.c | 5 +++-- src/chlists.c | 6 ++---- src/chschd.c | 18 +++++++++--------- src/include/events.h | 5 +++-- src/include/scheduler.h | 10 +++------- src/include/threads.h | 8 +++----- 6 files changed, 23 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/chevents.c b/src/chevents.c index 4dcf37a22..9094f45cd 100644 --- a/src/chevents.c +++ b/src/chevents.c @@ -140,11 +140,12 @@ void chEvtSendI(EventSource *esp) { * @return the event identifier * @note Only a single event is served in the function, the one with the * lowest event id. The function is meant to be invoked into a loop so - * that all events are received and served.
+ * that all events are received and served.
* This means that Event Listeners with a lower event identifier have * an higher priority. */ -t_eventid chEvtWait(t_eventmask ewmask, t_evhandler handlers[]) { +t_eventid chEvtWait(t_eventmask ewmask, + t_evhandler handlers[]) { t_eventid i; t_eventmask m; diff --git a/src/chlists.c b/src/chlists.c index d01c8c37c..7994f8ac6 100644 --- a/src/chlists.c +++ b/src/chlists.c @@ -31,10 +31,8 @@ */ void fifo_insert(Thread *tp, ThreadsQueue *tqp) { - tp->p_next = (Thread *)tqp; - tp->p_prev = tqp->p_prev; - tqp->p_prev->p_next = tp; - tqp->p_prev = tp; + tp->p_prev = (tp->p_next = (Thread *)tqp)->p_prev; + tp->p_prev->p_next = tqp->p_prev = tp; } /* diff --git a/src/chschd.c b/src/chschd.c index 81031f8c4..254f87937 100644 --- a/src/chschd.c +++ b/src/chschd.c @@ -27,12 +27,12 @@ /** @cond never*/ static ReadyList rlist; +static t_cnt preempt; #ifndef CH_CURRP_REGISTER_CACHE Thread *currp; #endif -static t_cnt preempt; #ifdef CH_USE_SYSTEMTIME t_time stime; #endif @@ -45,8 +45,8 @@ t_time stime; */ void chSchInit(void) { - rlist.p_next = rlist.p_prev = (Thread *)&rlist; - rlist.p_prio = ABSPRIO; + fifo_init(&rlist.r_queue); + rlist.r_prio = ABSPRIO; preempt = CH_TIME_QUANTUM; #ifdef CH_USE_SYSTEMTIME stime = 0; @@ -68,7 +68,7 @@ Thread *chSchReadyI(Thread *tp) { tp->p_state = PRREADY; tp->p_rdymsg = RDY_OK; - cp = rlist.p_prev; + cp = rlist.r_queue.p_prev; while (cp->p_prio < prio) cp = cp->p_prev; // Insertion on p_next @@ -84,7 +84,7 @@ Thread *chSchReadyI(Thread *tp) { static void nextready(void) { Thread *otp = currp; - (currp = fifo_remove((ThreadsQueue *)&rlist))->p_state = PRCURR; + (currp = fifo_remove(&rlist.r_queue))->p_state = PRCURR; preempt = CH_TIME_QUANTUM; chSysSwitchI(&otp->p_ctx, &currp->p_ctx); } @@ -136,7 +136,7 @@ void chSchWakeupI(Thread *tp, t_msg msg) { */ void chSchRescheduleI(void) { - if (isempty(&rlist) || firstprio(&rlist) <= currp->p_prio) + if (isempty(&rlist.r_queue) || firstprio(&rlist.r_queue) <= currp->p_prio) return; chSchDoRescheduleI(); @@ -159,15 +159,15 @@ void chSchDoRescheduleI(void) { */ BOOL chSchRescRequiredI(void) { - if (isempty(&rlist)) + if (isempty(&rlist.r_queue)) return FALSE; if (preempt) { - if (firstprio(&rlist) <= currp->p_prio) + if (firstprio(&rlist.r_queue) <= currp->p_prio) return FALSE; } else { /* Time quantum elapsed. */ - if (firstprio(&rlist) < currp->p_prio) + if (firstprio(&rlist.r_queue) < currp->p_prio) return FALSE; } return TRUE; diff --git a/src/include/events.h b/src/include/events.h index c5dfe7438..322f7ec7d 100644 --- a/src/include/events.h +++ b/src/include/events.h @@ -70,7 +70,7 @@ typedef struct EventSource { * @note Can be called with interrupts disabled or enabled. */ #define chEvtIsListening(esp) \ - ((esp) != (EventSource *)(esp)->es_next) + ((esp) != (EventSource *)(esp)->es_next) /** Event Handler callback function.*/ @@ -81,7 +81,8 @@ void chEvtUnregister(EventSource *esp, EventListener *elp); void chEvtClear(t_eventmask mask); void chEvtSend(EventSource *esp); void chEvtSendI(EventSource *esp); -t_eventid chEvtWait(t_eventmask ewmask, t_evhandler handlers[]); +t_eventid chEvtWait(t_eventmask ewmask, + t_evhandler handlers[]); #ifdef CH_USE_EVENTS_TIMEOUT t_eventid chEvtWaitTimeout(t_eventmask ewmask, t_evhandler handlers[], diff --git a/src/include/scheduler.h b/src/include/scheduler.h index 2efabbcd2..6a3f7f8f8 100644 --- a/src/include/scheduler.h +++ b/src/include/scheduler.h @@ -32,18 +32,14 @@ /** Returned if the thread was made ready because a reset.*/ #define RDY_RESET -2 -#define firstprio(qp) ((qp)->p_next->p_prio) +#define firstprio(rlp) ((rlp)->p_next->p_prio) /** * Ready list header. */ typedef struct { - /** Highest priority \p Thread in the list.*/ - Thread *p_next; - /** Lowest priority \p Thread in the list.*/ - Thread *p_prev; - /** Alwas set to \p MAXPRIO.*/ - t_prio p_prio; + ThreadsQueue r_queue; + t_prio r_prio; } ReadyList; /* diff --git a/src/include/threads.h b/src/include/threads.h index beb41aae7..12737de2e 100644 --- a/src/include/threads.h +++ b/src/include/threads.h @@ -78,7 +78,7 @@ struct Thread { * systems, be caruful in doing so. */ #ifdef CH_USE_WAITEXIT - /** The queue of the threads waiting for this thread termination.*/ + /** The list of the threads waiting for this thread termination.*/ ThreadsList p_waiting; #endif #ifdef CH_USE_EXIT_EVENT @@ -151,10 +151,8 @@ typedef t_msg (*t_tfunc)(void *); #ifdef CH_OPTIMIZE_SPEED static INLINE void fifo_insert(Thread *tp, ThreadsQueue *tqp) { - tp->p_next = (Thread *)tqp; - tp->p_prev = tqp->p_prev; - tqp->p_prev->p_next = tp; - tqp->p_prev = tp; + tp->p_prev = (tp->p_next = (Thread *)tqp)->p_prev; + tp->p_prev->p_next = tqp->p_prev = tp; } static INLINE Thread *fifo_remove(ThreadsQueue *tqp) { -- cgit v1.2.3