Added support for asynchronous jobs queues to OSLIB.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@13205 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
Giovanni Di Sirio 2019-12-03 09:40:30 +00:00
parent a1f7bbd4b6
commit 2f2b7d22fd
5 changed files with 35 additions and 17 deletions

View File

@ -70,7 +70,7 @@ int main(void) {
*/ */
while (true) { while (true) {
if (palReadLine(LINE_JOY_CENTER)) { if (palReadLine(LINE_JOY_CENTER)) {
// test_execute((BaseSequentialStream *)&SD2, &rt_test_suite); test_execute((BaseSequentialStream *)&SD2, &rt_test_suite);
test_execute((BaseSequentialStream *)&SD2, &oslib_test_suite); test_execute((BaseSequentialStream *)&SD2, &oslib_test_suite);
} }
chThdSleepMilliseconds(500); chThdSleepMilliseconds(500);

View File

@ -42,11 +42,6 @@
/* Module constants. */ /* Module constants. */
/*===========================================================================*/ /*===========================================================================*/
/**
* @brief Job identifier that does nothing except cycle the dispatcher.
*/
#define JOB_NULL ((msg_t)0)
/** /**
* @brief Dispatcher return code in case of a @p JOB_NUL has been received. * @brief Dispatcher return code in case of a @p JOB_NUL has been received.
*/ */
@ -340,8 +335,11 @@ static inline msg_t chJobDispatch(jobs_queue_t *jqp) {
/* Waiting for a job.*/ /* Waiting for a job.*/
msg = chMBFetchTimeout(&jqp->mbx, &jmsg, TIME_INFINITE); msg = chMBFetchTimeout(&jqp->mbx, &jmsg, TIME_INFINITE);
if (msg == MSG_OK) { if (msg == MSG_OK) {
if (jmsg != JOB_NULL) { job_descriptor_t *jp = (job_descriptor_t *)jmsg;
job_descriptor_t *jp = (job_descriptor_t *)jmsg;
chDbgAssert(jp != NULL, "is NULL");
if (jp->jobfunc != NULL) {
/* Invoking the job function.*/ /* Invoking the job function.*/
jp->jobfunc(jp->jobarg); jp->jobfunc(jp->jobarg);
@ -374,8 +372,11 @@ static inline msg_t chJobDispatchTimeout(jobs_queue_t *jqp,
/* Waiting for a job or a timeout.*/ /* Waiting for a job or a timeout.*/
msg = chMBFetchTimeout(&jqp->mbx, &jmsg, timeout); msg = chMBFetchTimeout(&jqp->mbx, &jmsg, timeout);
if (msg == MSG_OK) { if (msg == MSG_OK) {
if (jmsg != JOB_NULL) { job_descriptor_t *jp = (job_descriptor_t *)jmsg;
job_descriptor_t *jp = (job_descriptor_t *)jmsg;
chDbgAssert(jp != NULL, "is NULL");
if (jp->jobfunc != NULL) {
/* Invoking the job function.*/ /* Invoking the job function.*/
jp->jobfunc(jp->jobarg); jp->jobfunc(jp->jobarg);

View File

@ -74,6 +74,7 @@
***************************************************************************** *****************************************************************************
*** Next *** *** Next ***
- LIB: Added support for asynchronous jobs queues to OSLIB.
- LIB: Added support for delegate threads to OSLIB. - LIB: Added support for delegate threads to OSLIB.
- NIL: Improvements to messages, new functions chMsgWaitS(), - NIL: Improvements to messages, new functions chMsgWaitS(),
chMsgWaitTimeoutS(), chMsgWaitTimeout(). chMsgWaitTimeoutS(), chMsgWaitTimeout().

View File

@ -1151,15 +1151,23 @@ for (i = 0; i < 8; i++) {
</step> </step>
<step> <step>
<description> <description>
<value>Sending null jobs to make thread exit.</value> <value>Sending two null jobs to make threads exit.</value>
</description> </description>
<tags> <tags>
<value></value> <value></value>
</tags> </tags>
<code> <code>
<value><![CDATA[ <value><![CDATA[
chJobPost(&jq, JOB_NULL); job_descriptor_t *jdp;
chJobPost(&jq, JOB_NULL);
jdp = chJobGet(&jq);
jdp->jobfunc = NULL;
jdp->jobarg = NULL;
chJobPost(&jq, jdp);
jdp = chJobGet(&jq);
jdp->jobfunc = NULL;
jdp->jobarg = NULL;
chJobPost(&jq, jdp);
(void) chThdWait(tp1); (void) chThdWait(tp1);
(void) chThdWait(tp2); (void) chThdWait(tp2);
test_assert_sequence("abcdefgh", "unexpected tokens"); test_assert_sequence("abcdefgh", "unexpected tokens");

View File

@ -84,7 +84,7 @@ static THD_FUNCTION(Thread1, arg) {
* - [4.1.1] Initializing the Jobs Queue object. * - [4.1.1] Initializing the Jobs Queue object.
* - [4.1.2] Starting the dispatcher threads. * - [4.1.2] Starting the dispatcher threads.
* - [4.1.3] Sending jobs with various timings. * - [4.1.3] Sending jobs with various timings.
* - [4.1.4] Sending null jobs to make thread exit. * - [4.1.4] Sending null jobs to make threads exit.
* . * .
*/ */
@ -138,11 +138,19 @@ static void oslib_test_004_001_execute(void) {
} }
test_end_step(3); test_end_step(3);
/* [4.1.4] Sending null jobs to make thread exit.*/ /* [4.1.4] Sending null jobs to make threads exit.*/
test_set_step(4); test_set_step(4);
{ {
chJobPost(&jq, JOB_NULL); job_descriptor_t *jdp;
chJobPost(&jq, JOB_NULL);
jdp = chJobGet(&jq);
jdp->jobfunc = NULL;
jdp->jobarg = NULL;
chJobPost(&jq, jdp);
jdp = chJobGet(&jq);
jdp->jobfunc = NULL;
jdp->jobarg = NULL;
chJobPost(&jq, jdp);
(void) chThdWait(tp1); (void) chThdWait(tp1);
(void) chThdWait(tp2); (void) chThdWait(tp2);
test_assert_sequence("abcdefgh", "unexpected tokens"); test_assert_sequence("abcdefgh", "unexpected tokens");