Backport struct chx_qh changes from master.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
16
ChangeLog
16
ChangeLog
@@ -1,3 +1,19 @@
|
|||||||
|
2022-04-08 NIIBE Yutaka <gniibe@fsij.org>
|
||||||
|
|
||||||
|
Backport the changes from master.
|
||||||
|
* chopstx.h (struct chx_qh): Change the type for next and prev.
|
||||||
|
* chopstx.c (FOR_QUEUE): New macro.
|
||||||
|
(ll_empty): Follow the change of struct chx_qh.
|
||||||
|
(ll_insert): Change the type of the first argument.
|
||||||
|
(ll_pop): Follow the change of struct chx_qh.
|
||||||
|
(ll_prio_push): Use FOR_QUEUE macro. Follow the change of
|
||||||
|
ll_insert.
|
||||||
|
(ll_prio_enqueue, chx_timer_insert): Likewise.
|
||||||
|
(chx_timer_dequeue, chx_init, chx_exit): Likewise.
|
||||||
|
(chopstx_mutex_init, chopstx_cond_init): Likewise.
|
||||||
|
* chopstx-cortex-m.c (chx_handle_intr): Use FOR_QUEUE macro.
|
||||||
|
* chopstx-gnu-linux.c (chx_handle_intr): Use FOR_QUEUE macro.
|
||||||
|
|
||||||
2021-10-12 NIIBE Yutaka <gniibe@fsij.org>
|
2021-10-12 NIIBE Yutaka <gniibe@fsij.org>
|
||||||
|
|
||||||
* VERSION: 1.20.
|
* VERSION: 1.20.
|
||||||
|
|||||||
@@ -276,7 +276,7 @@ chx_handle_intr (void)
|
|||||||
|
|
||||||
chx_disable_intr (irq_num);
|
chx_disable_intr (irq_num);
|
||||||
chx_spin_lock (&q_intr.lock);
|
chx_spin_lock (&q_intr.lock);
|
||||||
for (p = q_intr.q.next; p != (struct chx_pq *)&q_intr.q; p = p->next)
|
FOR_QUEUE (p, (&q_intr.q), struct chx_pq *)
|
||||||
if (p->v == irq_num)
|
if (p->v == irq_num)
|
||||||
{ /* should be one at most. */
|
{ /* should be one at most. */
|
||||||
struct chx_px *px = (struct chx_px *)p;
|
struct chx_px *px = (struct chx_px *)p;
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ chx_handle_intr (uint32_t irq_num)
|
|||||||
|
|
||||||
chx_disable_intr (irq_num);
|
chx_disable_intr (irq_num);
|
||||||
chx_spin_lock (&q_intr.lock);
|
chx_spin_lock (&q_intr.lock);
|
||||||
for (p = q_intr.q.next; p != (struct chx_pq *)&q_intr.q; p = p->next)
|
FOR_QUEUE (p, (&q_intr.q), struct chx_pq *)
|
||||||
if (p->v == irq_num)
|
if (p->v == irq_num)
|
||||||
{ /* should be one at most. */
|
{ /* should be one at most. */
|
||||||
struct chx_px *px = (struct chx_px *)p;
|
struct chx_px *px = (struct chx_px *)p;
|
||||||
|
|||||||
55
chopstx.c
55
chopstx.c
@@ -88,6 +88,9 @@ struct chx_queue {
|
|||||||
struct chx_spinlock lock;
|
struct chx_spinlock lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Forward declaration. */
|
||||||
|
struct chx_pq;
|
||||||
|
|
||||||
/* READY: priority queue. */
|
/* READY: priority queue. */
|
||||||
static struct chx_queue q_ready;
|
static struct chx_queue q_ready;
|
||||||
|
|
||||||
@@ -173,6 +176,10 @@ struct chx_thread { /* inherits PQ */
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* Macro to loop over queue. */
|
||||||
|
#define FOR_QUEUE(var, queue, var_type) \
|
||||||
|
for (var = (var_type)queue->next; var != (var_type)queue; var = var->next)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Double linked list handling.
|
* Double linked list handling.
|
||||||
*/
|
*/
|
||||||
@@ -180,7 +187,7 @@ struct chx_thread { /* inherits PQ */
|
|||||||
static int
|
static int
|
||||||
ll_empty (struct chx_qh *q)
|
ll_empty (struct chx_qh *q)
|
||||||
{
|
{
|
||||||
return q == (struct chx_qh *)q->next;
|
return q == q->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct chx_pq *
|
static struct chx_pq *
|
||||||
@@ -193,24 +200,22 @@ ll_dequeue (struct chx_pq *pq)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ll_insert (struct chx_pq *pq0, struct chx_qh *q)
|
ll_insert (struct chx_qh *q0, struct chx_qh *q)
|
||||||
{
|
{
|
||||||
struct chx_pq *pq = (struct chx_pq *)q;
|
q0->next = q;
|
||||||
|
q0->prev = q->prev;
|
||||||
pq0->next = (struct chx_pq *)pq;
|
q->prev->next = q0;
|
||||||
pq0->prev = pq->prev;
|
q->prev = q0;
|
||||||
pq->prev->next = (struct chx_pq *)pq0;
|
|
||||||
pq->prev = pq0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static struct chx_pq *
|
static struct chx_pq *
|
||||||
ll_pop (struct chx_qh *q)
|
ll_pop (struct chx_qh *q)
|
||||||
{
|
{
|
||||||
if (q == (struct chx_qh *)q->next)
|
if (q == q->next)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return ll_dequeue (q->next);
|
return ll_dequeue ((struct chx_pq *)q->next);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -218,12 +223,12 @@ ll_prio_push (struct chx_pq *pq0, struct chx_qh *q0)
|
|||||||
{
|
{
|
||||||
struct chx_pq *p;
|
struct chx_pq *p;
|
||||||
|
|
||||||
for (p = q0->next; p != (struct chx_pq *)q0; p = p->next)
|
FOR_QUEUE (p, q0, struct chx_pq *)
|
||||||
if (p->prio <= pq0->prio)
|
if (p->prio <= pq0->prio)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
pq0->parent = q0;
|
pq0->parent = q0;
|
||||||
ll_insert (pq0, (struct chx_qh *)p);
|
ll_insert ((struct chx_qh *)pq0, (struct chx_qh *)p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -231,12 +236,12 @@ ll_prio_enqueue (struct chx_pq *pq0, struct chx_qh *q0)
|
|||||||
{
|
{
|
||||||
struct chx_pq *p;
|
struct chx_pq *p;
|
||||||
|
|
||||||
for (p = q0->next; p != (struct chx_pq *)q0; p = p->next)
|
FOR_QUEUE (p, q0, struct chx_pq *)
|
||||||
if (p->prio < pq0->prio)
|
if (p->prio < pq0->prio)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
pq0->parent = q0;
|
pq0->parent = q0;
|
||||||
ll_insert (pq0, (struct chx_qh *)p);
|
ll_insert ((struct chx_qh *)pq0, (struct chx_qh *)p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -323,12 +328,12 @@ chx_timer_insert (struct chx_thread *tp, uint32_t usec)
|
|||||||
uint32_t ticks = usec_to_ticks (usec);
|
uint32_t ticks = usec_to_ticks (usec);
|
||||||
uint32_t next_ticks = chx_systick_get ();
|
uint32_t next_ticks = chx_systick_get ();
|
||||||
|
|
||||||
for (p = q_timer.q.next; p != (struct chx_pq *)&q_timer.q; p = p->next)
|
FOR_QUEUE (p, (&q_timer.q), struct chx_pq *)
|
||||||
{
|
{
|
||||||
if (ticks < next_ticks)
|
if (ticks < next_ticks)
|
||||||
{
|
{
|
||||||
tp->parent = &q_timer.q;
|
tp->parent = &q_timer.q;
|
||||||
ll_insert ((struct chx_pq *)tp, (struct chx_qh *)p);
|
ll_insert ((struct chx_qh *)tp, (struct chx_qh *)p);
|
||||||
chx_set_timer ((struct chx_thread *)tp->prev, ticks);
|
chx_set_timer ((struct chx_thread *)tp->prev, ticks);
|
||||||
chx_set_timer (tp, (next_ticks - ticks));
|
chx_set_timer (tp, (next_ticks - ticks));
|
||||||
break;
|
break;
|
||||||
@@ -343,7 +348,7 @@ chx_timer_insert (struct chx_thread *tp, uint32_t usec)
|
|||||||
if (p == (struct chx_pq *)&q_timer.q)
|
if (p == (struct chx_pq *)&q_timer.q)
|
||||||
{
|
{
|
||||||
tp->parent = &q_timer.q;
|
tp->parent = &q_timer.q;
|
||||||
ll_insert ((struct chx_pq *)tp, (struct chx_qh *)p);
|
ll_insert ((struct chx_qh *)tp, (struct chx_qh *)p);
|
||||||
chx_set_timer ((struct chx_thread *)tp->prev, ticks);
|
chx_set_timer ((struct chx_thread *)tp->prev, ticks);
|
||||||
chx_set_timer (tp, 1); /* Non-zero for the last entry. */
|
chx_set_timer (tp, 1); /* Non-zero for the last entry. */
|
||||||
}
|
}
|
||||||
@@ -372,7 +377,7 @@ chx_timer_dequeue (struct chx_thread *tp)
|
|||||||
{
|
{
|
||||||
struct chx_pq *p;
|
struct chx_pq *p;
|
||||||
|
|
||||||
for (p = q_timer.q.next; p != (struct chx_pq *)tp; p = p->next)
|
FOR_QUEUE (p, (&q_timer.q), struct chx_pq *)
|
||||||
ticks_remained += p->v;
|
ticks_remained += p->v;
|
||||||
|
|
||||||
tp_prev->v += tp->v;
|
tp_prev->v += tp->v;
|
||||||
@@ -460,13 +465,13 @@ chx_init (struct chx_thread *tp)
|
|||||||
chx_init_arch (tp);
|
chx_init_arch (tp);
|
||||||
chx_spin_init (&chx_enable_sleep_lock);
|
chx_spin_init (&chx_enable_sleep_lock);
|
||||||
|
|
||||||
q_ready.q.next = q_ready.q.prev = (struct chx_pq *)&q_ready.q;
|
q_ready.q.next = q_ready.q.prev = &q_ready.q;
|
||||||
chx_spin_init (&q_ready.lock);
|
chx_spin_init (&q_ready.lock);
|
||||||
q_timer.q.next = q_timer.q.prev = (struct chx_pq *)&q_timer.q;
|
q_timer.q.next = q_timer.q.prev = &q_timer.q;
|
||||||
chx_spin_init (&q_timer.lock);
|
chx_spin_init (&q_timer.lock);
|
||||||
q_join.q.next = q_join.q.prev = (struct chx_pq *)&q_join.q;
|
q_join.q.next = q_join.q.prev = &q_join.q;
|
||||||
chx_spin_init (&q_join.lock);
|
chx_spin_init (&q_join.lock);
|
||||||
q_intr.q.next = q_intr.q.prev = (struct chx_pq *)&q_intr.q;
|
q_intr.q.next = q_intr.q.prev = &q_intr.q;
|
||||||
chx_spin_init (&q_intr.lock);
|
chx_spin_init (&q_intr.lock);
|
||||||
tp->next = tp->prev = (struct chx_pq *)tp;
|
tp->next = tp->prev = (struct chx_pq *)tp;
|
||||||
tp->mutex_list = NULL;
|
tp->mutex_list = NULL;
|
||||||
@@ -549,7 +554,7 @@ chx_exit (void *retval)
|
|||||||
if (running->flag_join_req)
|
if (running->flag_join_req)
|
||||||
{ /* wake up a thread which requests to join */
|
{ /* wake up a thread which requests to join */
|
||||||
chx_spin_lock (&q_join.lock);
|
chx_spin_lock (&q_join.lock);
|
||||||
for (p = q_join.q.next; p != (struct chx_pq *)&q_join.q; p = p->next)
|
FOR_QUEUE (p, (&q_join.q), struct chx_pq *)
|
||||||
if (p->v == (uintptr_t)running)
|
if (p->v == (uintptr_t)running)
|
||||||
{ /* should be one at most. */
|
{ /* should be one at most. */
|
||||||
ll_dequeue (p);
|
ll_dequeue (p);
|
||||||
@@ -744,7 +749,7 @@ void
|
|||||||
chopstx_mutex_init (chopstx_mutex_t *mutex)
|
chopstx_mutex_init (chopstx_mutex_t *mutex)
|
||||||
{
|
{
|
||||||
chx_spin_init (&mutex->lock);
|
chx_spin_init (&mutex->lock);
|
||||||
mutex->q.next = mutex->q.prev = (struct chx_pq *)&mutex->q;
|
mutex->q.next = mutex->q.prev = &mutex->q;
|
||||||
mutex->list = NULL;
|
mutex->list = NULL;
|
||||||
mutex->owner = NULL;
|
mutex->owner = NULL;
|
||||||
}
|
}
|
||||||
@@ -880,7 +885,7 @@ void
|
|||||||
chopstx_cond_init (chopstx_cond_t *cond)
|
chopstx_cond_init (chopstx_cond_t *cond)
|
||||||
{
|
{
|
||||||
chx_spin_init (&cond->lock);
|
chx_spin_init (&cond->lock);
|
||||||
cond->q.next = cond->q.prev = (struct chx_pq *)&cond->q;
|
cond->q.next = cond->q.prev = &cond->q;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user