From 0ae3b2681fd3428baffc06cefadc40a90dcd5da4 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka <gniibe@fsij.org> Date: Wed, 5 Jun 2013 15:25:39 +0900 Subject: chopstx_usec_wait_internal with pointer --- ChangeLog | 1 + chopstx.c | 32 +++++++++++++++++++++++--------- chopstx.h | 4 +++- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8afd432..3a590cf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ (chopstx_create): Change API. (chopstx_wakeup_usec_wait): New. (chopstx_usec_wait): Accept wakeup to break. + (chopstx_usec_wait_internal): New. 2013-06-04 Niibe Yutaka <gniibe@fsij.org> diff --git a/chopstx.c b/chopstx.c index 8edca0d..dfb655a 100644 --- a/chopstx.c +++ b/chopstx.c @@ -844,25 +844,39 @@ chopstx_create (uint32_t flags_and_prio, void -chopstx_usec_wait (uint32_t usec) +chopstx_usec_wait_internal (uint32_t *arg) { - while (usec) - { - uint32_t usec0 = (usec > 200*1000) ? 200*1000: usec; - register int r8 asm ("r8") = 0; + register uint32_t *usec_p asm ("r8") = arg; + uint32_t usec; + uint32_t usec0 = 0; + while (1) + { chx_cpu_sched_lock (); + *usec_p -= usec0; + usec = *usec_p; + if (usec == 0) + break; + usec0 = (usec > 200*1000) ? 200*1000: usec; if (running->flag_sched_rr) chx_timer_dequeue (running); chx_spin_lock (&q_timer.lock); chx_timer_insert (running, usec0); chx_spin_unlock (&q_timer.lock); - asm ("" : "=r" (r8) : "r" (r8)); + asm ("" : "=r" (usec_p) : "r" (usec_p)); chx_sched (CHX_SLEEP); - if (r8) /* awakened */ + + if (!usec_p) /* awakened */ break; - usec -= usec0; } + + chx_cpu_sched_unlock (); +} + +void +chopstx_usec_wait (uint32_t usec) +{ + chopstx_usec_wait_internal (&usec); } @@ -1215,7 +1229,7 @@ chopstx_wakeup_usec_wait (chopstx_t thd) chx_cpu_sched_lock (); if (tp->state == THREAD_WAIT_TIME) { - tp->tc.reg[REG_EXIT] = 1; + tp->tc.reg[REG_EXIT] = 0; chx_timer_dequeue (tp); chx_ready_enqueue (tp); if (tp->prio > running->prio) diff --git a/chopstx.h b/chopstx.h index 98c0531..ed632b3 100644 --- a/chopstx.h +++ b/chopstx.h @@ -39,7 +39,9 @@ chopstx_create (uint32_t flags_and_prio, #define CHOPSTX_SCHED_RR 0x20000 -void chopstx_usec_wait (uint32_t useconds); +void chopstx_usec_wait_internal (uint32_t *arg); + +void chopstx_usec_wait (uint32_t usec); struct chx_spinlock { /* nothing for uniprocessor. */ -- cgit v1.2.3