mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 12:08:36 +08:00
sched: merge waitsem and msgwaitq
This commit is contained in:
parent
4c44c6f709
commit
af72a528f1
10 changed files with 34 additions and 36 deletions
|
@ -608,9 +608,9 @@ struct tcb_s
|
|||
FAR struct dspace_s *dspace; /* Allocated area for .bss and .data */
|
||||
#endif
|
||||
|
||||
/* POSIX Semaphore Control Fields *****************************************/
|
||||
/* POSIX Semaphore and Message Queue Control Fields ***********************/
|
||||
|
||||
sem_t *waitsem; /* Semaphore ID waiting on */
|
||||
FAR void *waitobj; /* Object thread waiting on */
|
||||
|
||||
/* POSIX Signal Control Fields ********************************************/
|
||||
|
||||
|
@ -620,12 +620,6 @@ struct tcb_s
|
|||
sq_queue_t sigpostedq; /* List of posted signals */
|
||||
siginfo_t sigunbinfo; /* Signal info when task unblocked */
|
||||
|
||||
/* POSIX Named Message Queue Fields ***************************************/
|
||||
|
||||
#ifndef CONFIG_DISABLE_MQUEUE
|
||||
FAR struct mqueue_inode_s *msgwaitq; /* Waiting for this message queue */
|
||||
#endif
|
||||
|
||||
/* Robust mutex support ***************************************************/
|
||||
|
||||
#if !defined(CONFIG_DISABLE_PTHREAD) && !defined(CONFIG_PTHREAD_MUTEX_UNSAFE)
|
||||
|
|
|
@ -166,8 +166,8 @@ int nxmq_wait_receive(FAR struct mqueue_inode_s *msgq,
|
|||
{
|
||||
/* Yes.. Block and try again */
|
||||
|
||||
rtcb = this_task();
|
||||
rtcb->msgwaitq = msgq;
|
||||
rtcb = this_task();
|
||||
rtcb->waitobj = msgq;
|
||||
msgq->nwaitnotempty++;
|
||||
|
||||
/* Initialize the 'errcode" used to communication wake-up error
|
||||
|
@ -286,7 +286,7 @@ ssize_t nxmq_do_receive(FAR struct mqueue_inode_s *msgq,
|
|||
*/
|
||||
|
||||
for (btcb = (FAR struct tcb_s *)g_waitingformqnotfull.head;
|
||||
btcb && btcb->msgwaitq != msgq;
|
||||
btcb && btcb->waitobj != msgq;
|
||||
btcb = btcb->flink)
|
||||
{
|
||||
}
|
||||
|
@ -303,7 +303,7 @@ ssize_t nxmq_do_receive(FAR struct mqueue_inode_s *msgq,
|
|||
wd_cancel(&btcb->waitdog);
|
||||
}
|
||||
|
||||
btcb->msgwaitq = NULL;
|
||||
btcb->waitobj = NULL;
|
||||
msgq->nwaitnotfull--;
|
||||
up_unblock_task(btcb);
|
||||
}
|
||||
|
|
|
@ -56,6 +56,8 @@
|
|||
|
||||
void nxmq_recover(FAR struct tcb_s *tcb)
|
||||
{
|
||||
FAR struct mqueue_inode_s *msgq;
|
||||
|
||||
/* If were were waiting for a timed message queue event, then the
|
||||
* timer was canceled and deleted in nxtask_recover() before this
|
||||
* function was called.
|
||||
|
@ -63,12 +65,14 @@ void nxmq_recover(FAR struct tcb_s *tcb)
|
|||
|
||||
/* Was the task waiting for a message queue to become non-empty? */
|
||||
|
||||
msgq = tcb->waitobj;
|
||||
|
||||
if (tcb->task_state == TSTATE_WAIT_MQNOTEMPTY)
|
||||
{
|
||||
/* Decrement the count of waiters */
|
||||
|
||||
DEBUGASSERT(tcb->msgwaitq && tcb->msgwaitq->nwaitnotempty > 0);
|
||||
tcb->msgwaitq->nwaitnotempty--;
|
||||
DEBUGASSERT(msgq && msgq->nwaitnotempty > 0);
|
||||
msgq->nwaitnotempty--;
|
||||
}
|
||||
|
||||
/* Was the task waiting for a message queue to become non-full? */
|
||||
|
@ -77,7 +81,7 @@ void nxmq_recover(FAR struct tcb_s *tcb)
|
|||
{
|
||||
/* Decrement the count of waiters */
|
||||
|
||||
DEBUGASSERT(tcb->msgwaitq && tcb->msgwaitq->nwaitnotfull > 0);
|
||||
tcb->msgwaitq->nwaitnotfull--;
|
||||
DEBUGASSERT(msgq && msgq->nwaitnotfull > 0);
|
||||
msgq->nwaitnotfull--;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -252,8 +252,8 @@ int nxmq_wait_send(FAR struct mqueue_inode_s *msgq, int oflags)
|
|||
* When we are unblocked, we will try again
|
||||
*/
|
||||
|
||||
rtcb = this_task();
|
||||
rtcb->msgwaitq = msgq;
|
||||
rtcb = this_task();
|
||||
rtcb->waitobj = msgq;
|
||||
msgq->nwaitnotfull++;
|
||||
|
||||
/* Initialize the errcode used to communication wake-up error
|
||||
|
@ -396,7 +396,7 @@ int nxmq_do_send(FAR struct mqueue_inode_s *msgq,
|
|||
*/
|
||||
|
||||
for (btcb = (FAR struct tcb_s *)g_waitingformqnotempty.head;
|
||||
btcb && btcb->msgwaitq != msgq;
|
||||
btcb && btcb->waitobj != msgq;
|
||||
btcb = btcb->flink)
|
||||
{
|
||||
}
|
||||
|
@ -410,7 +410,7 @@ int nxmq_do_send(FAR struct mqueue_inode_s *msgq,
|
|||
wd_cancel(&btcb->waitdog);
|
||||
}
|
||||
|
||||
btcb->msgwaitq = NULL;
|
||||
btcb->waitobj = NULL;
|
||||
msgq->nwaitnotempty--;
|
||||
up_unblock_task(btcb);
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ void nxmq_wait_irq(FAR struct tcb_s *wtcb, int errcode)
|
|||
|
||||
/* It is possible that an interrupt/context switch beat us to the punch and
|
||||
* already changed the task's state. NOTE: The operations within the if
|
||||
* are safe because interrupts are always disabled with the msgwaitq,
|
||||
* are safe because interrupts are always disabled with the waitobj,
|
||||
* nwaitnotempty, and nwaitnotfull fields are modified.
|
||||
*/
|
||||
|
||||
|
@ -80,10 +80,10 @@ void nxmq_wait_irq(FAR struct tcb_s *wtcb, int errcode)
|
|||
{
|
||||
/* Get the message queue associated with the waiter from the TCB */
|
||||
|
||||
msgq = wtcb->msgwaitq;
|
||||
msgq = wtcb->waitobj;
|
||||
DEBUGASSERT(msgq);
|
||||
|
||||
wtcb->msgwaitq = NULL;
|
||||
wtcb->waitobj = NULL;
|
||||
|
||||
/* Decrement the count of waiters and cancel the wait */
|
||||
|
||||
|
|
|
@ -140,7 +140,7 @@ int nxsem_post(FAR sem_t *sem)
|
|||
*/
|
||||
|
||||
for (stcb = (FAR struct tcb_s *)g_waitingforsemaphore.head;
|
||||
(stcb && stcb->waitsem != sem);
|
||||
(stcb && stcb->waitobj != sem);
|
||||
stcb = stcb->flink);
|
||||
|
||||
if (stcb != NULL)
|
||||
|
@ -157,7 +157,7 @@ int nxsem_post(FAR sem_t *sem)
|
|||
|
||||
/* It is, let the task take the semaphore */
|
||||
|
||||
stcb->waitsem = NULL;
|
||||
stcb->waitobj = NULL;
|
||||
|
||||
/* Restart the waiting task. */
|
||||
|
||||
|
|
|
@ -72,17 +72,17 @@ void nxsem_recover(FAR struct tcb_s *tcb)
|
|||
* restart the exiting task.
|
||||
*
|
||||
* NOTE: In the case that the task is waiting we can assume: (1) That the
|
||||
* task state is TSTATE_WAIT_SEM and (2) that the 'waitsem' in the TCB is
|
||||
* task state is TSTATE_WAIT_SEM and (2) that the 'waitobj' in the TCB is
|
||||
* non-null. If we get here via pthread_cancel() or via task_delete(),
|
||||
* then the task state should be preserved; it will be altered in other
|
||||
* cases but in those cases waitsem should be NULL anyway (but we do not
|
||||
* cases but in those cases waitobj should be NULL anyway (but we do not
|
||||
* enforce that here).
|
||||
*/
|
||||
|
||||
flags = enter_critical_section();
|
||||
if (tcb->task_state == TSTATE_WAIT_SEM)
|
||||
{
|
||||
sem_t *sem = tcb->waitsem;
|
||||
FAR sem_t *sem = tcb->waitobj;
|
||||
DEBUGASSERT(sem != NULL && sem->semcount < 0);
|
||||
|
||||
/* Restore the correct priority of all threads that hold references
|
||||
|
@ -105,7 +105,7 @@ void nxsem_recover(FAR struct tcb_s *tcb)
|
|||
* semaphore list.
|
||||
*/
|
||||
|
||||
tcb->waitsem = NULL;
|
||||
tcb->waitobj = NULL;
|
||||
}
|
||||
|
||||
/* Release all semphore holders for the task */
|
||||
|
|
|
@ -91,7 +91,7 @@ int nxsem_trywait(FAR sem_t *sem)
|
|||
|
||||
sem->semcount--;
|
||||
nxsem_add_holder(sem);
|
||||
rtcb->waitsem = NULL;
|
||||
rtcb->waitobj = NULL;
|
||||
ret = OK;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -98,7 +98,7 @@ int nxsem_wait(FAR sem_t *sem)
|
|||
|
||||
sem->semcount--;
|
||||
nxsem_add_holder(sem);
|
||||
rtcb->waitsem = NULL;
|
||||
rtcb->waitobj = NULL;
|
||||
ret = OK;
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ int nxsem_wait(FAR sem_t *sem)
|
|||
* semaphore
|
||||
*/
|
||||
|
||||
DEBUGASSERT(rtcb->waitsem == NULL);
|
||||
DEBUGASSERT(rtcb->waitobj == NULL);
|
||||
|
||||
/* Handle the POSIX semaphore (but don't set the owner yet) */
|
||||
|
||||
|
@ -120,7 +120,7 @@ int nxsem_wait(FAR sem_t *sem)
|
|||
|
||||
/* Save the waited on semaphore in the TCB */
|
||||
|
||||
rtcb->waitsem = sem;
|
||||
rtcb->waitobj = sem;
|
||||
|
||||
/* If priority inheritance is enabled, then check the priority of
|
||||
* the holder of the semaphore.
|
||||
|
@ -166,7 +166,7 @@ int nxsem_wait(FAR sem_t *sem)
|
|||
* - nxsem_canceled() was called to restore the priority of all
|
||||
* threads that hold a reference to the semaphore,
|
||||
* - The semaphore count was decremented, and
|
||||
* - tcb->waitsem was nullifed.
|
||||
* - tcb->waitobj was nullifed.
|
||||
*
|
||||
* It is necessary to do these things in sem_waitirq.c because a
|
||||
* long time may elapse between the time that the signal was issued
|
||||
|
|
|
@ -80,7 +80,7 @@ void nxsem_wait_irq(FAR struct tcb_s *wtcb, int errcode)
|
|||
|
||||
if (wtcb->task_state == TSTATE_WAIT_SEM)
|
||||
{
|
||||
sem_t *sem = wtcb->waitsem;
|
||||
FAR sem_t *sem = wtcb->waitobj;
|
||||
DEBUGASSERT(sem != NULL && sem->semcount < 0);
|
||||
|
||||
/* Restore the correct priority of all threads that hold references
|
||||
|
@ -99,7 +99,7 @@ void nxsem_wait_irq(FAR struct tcb_s *wtcb, int errcode)
|
|||
|
||||
/* Indicate that the semaphore wait is over. */
|
||||
|
||||
wtcb->waitsem = NULL;
|
||||
wtcb->waitobj = NULL;
|
||||
|
||||
/* Mark the errno value for the thread. */
|
||||
|
||||
|
|
Loading…
Reference in a new issue