Use chx_running function.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka
2019-11-19 08:40:38 +09:00
parent 2180ed24be
commit c73258138c
3 changed files with 47 additions and 7 deletions

View File

@@ -83,9 +83,6 @@ chx_fatal (uint32_t err_code)
int chx_allow_sleep;
static struct chx_spinlock chx_enable_sleep_lock;
/* RUNNING: the current thread. */
struct chx_thread *running;
struct chx_queue {
struct chx_qh q;
struct chx_spinlock lock;
@@ -391,6 +388,7 @@ void
chx_timer_expired (void)
{
struct chx_thread *tp;
struct chx_thread *running = chx_running ();
uint16_t prio = 0; /* Use uint16_t here. */
chx_spin_lock (&q_timer.lock);
@@ -443,6 +441,8 @@ chx_systick_init (void)
if ((CHX_FLAGS_MAIN & CHOPSTX_SCHED_RR))
{
struct chx_thread *running = chx_running ();
chx_cpu_sched_lock ();
chx_spin_lock (&q_timer.lock);
chx_timer_insert (running, PREEMPTION_USEC);
@@ -481,7 +481,6 @@ chx_init (struct chx_thread *tp)
tp->prio = 0;
tp->parent = NULL;
tp->v = 0;
running = tp;
if (CHX_PRIO_MAIN_INIT >= CHOPSTX_PRIO_INHIBIT_PREEMPTION)
chx_cpu_sched_lock ();
@@ -503,6 +502,7 @@ chx_wakeup (struct chx_pq *pq)
{
int yield = 0;
struct chx_thread *tp;
struct chx_thread *running = chx_running ();
if (pq->flag_is_proxy)
{
@@ -543,6 +543,7 @@ static void __attribute__((noreturn))
chx_exit (void *retval)
{
struct chx_pq *p;
struct chx_thread *running = chx_running ();
chx_cpu_sched_lock ();
if (running->flag_join_req)
@@ -579,6 +580,7 @@ static chopstx_prio_t
chx_mutex_unlock (chopstx_mutex_t *mutex)
{
struct chx_thread *tp;
struct chx_thread *running = chx_running ();
mutex->owner = NULL;
running->mutex_list = mutex->list;
@@ -626,6 +628,7 @@ chopstx_create (uint32_t flags_and_prio,
{
struct chx_thread *tp;
chopstx_prio_t prio = (flags_and_prio & CHOPSTX_PRIO_MASK);
struct chx_thread *running = chx_running ();
tp = chopstx_create_arch (stack_addr, stack_size, thread_entry,
arg);
@@ -671,6 +674,7 @@ chopstx_create (uint32_t flags_and_prio,
static int
chx_snooze (uint32_t state, uint32_t *usec_p)
{
struct chx_thread *running = chx_running ();
uint32_t usec = *usec_p;
uint32_t usec0;
int r;
@@ -793,7 +797,7 @@ requeue (struct chx_thread *tp)
void
chopstx_mutex_lock (chopstx_mutex_t *mutex)
{
struct chx_thread *tp = running;
struct chx_thread *tp = chx_running ();
while (1)
{
@@ -852,6 +856,7 @@ chopstx_mutex_lock (chopstx_mutex_t *mutex)
void
chopstx_mutex_unlock (chopstx_mutex_t *mutex)
{
struct chx_thread *running = chx_running ();
chopstx_prio_t prio;
chx_cpu_sched_lock ();
@@ -889,7 +894,7 @@ chopstx_cond_init (chopstx_cond_t *cond)
void
chopstx_cond_wait (chopstx_cond_t *cond, chopstx_mutex_t *mutex)
{
struct chx_thread *tp = running;
struct chx_thread *tp = chx_running ();
int r;
chopstx_testcancel ();
@@ -1097,6 +1102,8 @@ chopstx_intr_done (chopstx_intr_t *intr)
void
chopstx_cleanup_push (struct chx_cleanup *clp)
{
struct chx_thread *running = chx_running ();
clp->next = running->clp;
running->clp = clp;
}
@@ -1111,6 +1118,7 @@ chopstx_cleanup_push (struct chx_cleanup *clp)
void
chopstx_cleanup_pop (int execute)
{
struct chx_thread *running = chx_running ();
struct chx_cleanup *clp = running->clp;
if (clp)
@@ -1135,6 +1143,7 @@ void
chopstx_exit (void *retval)
{
struct chx_mtx *m, *m_next;
struct chx_thread *running = chx_running ();
struct chx_cleanup *clp = running->clp;
running->clp = NULL;
@@ -1171,6 +1180,7 @@ chopstx_exit (void *retval)
int
chopstx_join (chopstx_t thd, void **ret)
{
struct chx_thread *running = chx_running ();
struct chx_thread *tp = (struct chx_thread *)thd;
int r = 0;
@@ -1274,6 +1284,7 @@ void
chopstx_cancel (chopstx_t thd)
{
struct chx_thread *tp = (struct chx_thread *)thd;
struct chx_thread *running = chx_running ();
chx_cpu_sched_lock ();
tp->flag_got_cancel = 1;
@@ -1330,6 +1341,8 @@ chopstx_cancel (chopstx_t thd)
void
chopstx_testcancel (void)
{
struct chx_thread *running = chx_running ();
if (running->flag_cancelable && running->flag_got_cancel)
chopstx_exit (CHOPSTX_CANCELED);
}
@@ -1346,6 +1359,7 @@ chopstx_testcancel (void)
int
chopstx_setcancelstate (int cancel_disable)
{
struct chx_thread *running = chx_running ();
int old_state = !running->flag_cancelable;
running->flag_cancelable = (cancel_disable == 0);
@@ -1356,6 +1370,8 @@ chopstx_setcancelstate (int cancel_disable)
static void
chx_proxy_init (struct chx_px *px, uint32_t *cp)
{
struct chx_thread *running = chx_running ();
px->next = px->prev = (struct chx_pq *)px;
px->flag_is_proxy = 1;
px->prio = running->prio;
@@ -1387,6 +1403,7 @@ chopstx_poll (uint32_t *usec_p, int n, struct chx_poll_head *const pd_array[])
struct chx_px px[n];
struct chx_poll_head *pd;
int r = 0;
struct chx_thread *running = chx_running ();
chx_dmb ();
chopstx_testcancel ();
@@ -1507,7 +1524,7 @@ chopstx_poll (uint32_t *usec_p, int n, struct chx_poll_head *const pd_array[])
chopstx_prio_t
chopstx_setpriority (chopstx_prio_t prio_new)
{
struct chx_thread *tp = running;
struct chx_thread *tp = chx_running ();
chopstx_prio_t prio_orig, prio_cur;
chx_cpu_sched_lock ();