• R/O
  • SSH
  • HTTPS

chibios: Commit


Commit MetaInfo

Revision14905 (tree)
Time2021-10-13 18:27:02
Authorgdisirio

Log Message

Fixed SB messages with timeout.

Change Summary

Incremental Difference

--- trunk/os/rt/src/chschd.c (revision 14904)
+++ trunk/os/rt/src/chschd.c (revision 14905)
@@ -207,6 +207,10 @@
207207 /* Falls through.*/
208208 case CH_STATE_QUEUED:
209209 /* Falls through.*/
210+#if CH_CFG_USE_MESSAGES == TRUE
211+ case CH_STATE_SNDMSGQ:
212+ /* Falls through.*/
213+#endif
210214 #if (CH_CFG_USE_CONDVARS == TRUE) && (CH_CFG_USE_CONDVARS_TIMEOUT == TRUE)
211215 case CH_STATE_WTCOND:
212216 #endif
--- trunk/os/sb/host/sbapi.c (revision 14904)
+++ trunk/os/sb/host/sbapi.c (revision 14905)
@@ -918,6 +918,29 @@
918918 ectxp->r0 = SB_ERR_ENOSYS;
919919 }
920920
921+static thread_t *sb_msg_wait_timeout_s(sysinterval_t timeout) {
922+ thread_t *currtp = chThdGetSelfX();
923+ thread_t *tp;
924+
925+ chDbgCheckClassS();
926+
927+ /* The sender thread could have timed out in sbSendMessageTimeout() so
928+ repeating the wait if it did.*/
929+ do {
930+ if (!chMsgIsPendingI(currtp)) {
931+ if (chSchGoSleepTimeoutS(CH_STATE_WTMSG, timeout) != MSG_OK) {
932+ return NULL;
933+ }
934+ }
935+ } while(ch_queue_isempty(&currtp->msgqueue));
936+
937+ /* Dequeuing the sender thread and returning it.*/
938+ tp = threadref(ch_queue_fifo_remove(&currtp->msgqueue));
939+ tp->state = CH_STATE_SNDMSG;
940+
941+ return tp;
942+}
943+
921944 /*===========================================================================*/
922945 /* Module exported functions. */
923946 /*===========================================================================*/
@@ -1005,15 +1028,20 @@
10051028 #if CH_CFG_USE_MESSAGES == TRUE
10061029 sb_class_t *sbcp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p;
10071030
1031+ chSysLock();
1032+
10081033 if (sbcp->msg_tp == NULL) {
1009- sbcp->msg_tp = chMsgWait();
1034+ sbcp->msg_tp = sb_msg_wait_timeout_s(TIME_INFINITE);
10101035 ectxp->r0 = (uint32_t)chMsgGet(sbcp->msg_tp);
10111036 }
10121037 else {
1013- chMsgRelease(sbcp->msg_tp, MSG_RESET);
1038+ thread_t *tp = sbcp->msg_tp;
10141039 sbcp->msg_tp = NULL;
1040+ chMsgReleaseS(tp, MSG_RESET);
10151041 ectxp->r0 = SB_ERR_EBUSY;
10161042 }
1043+
1044+ chSysUnlock();
10171045 #else
10181046 ectxp->r0 = SB_ERR_NOT_IMPLEMENTED;
10191047 #endif
@@ -1023,14 +1051,19 @@
10231051 #if CH_CFG_USE_MESSAGES == TRUE
10241052 sb_class_t *sbcp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p;
10251053
1054+ chSysLock();
1055+
10261056 if (sbcp->msg_tp != NULL) {
1027- chMsgRelease(sbcp->msg_tp, (msg_t )ectxp->r0);
1057+ thread_t *tp = sbcp->msg_tp;
10281058 sbcp->msg_tp = NULL;
1059+ chMsgReleaseS(tp, (msg_t )ectxp->r0);
10291060 ectxp->r0 = SB_ERR_NOERROR;
10301061 }
10311062 else {
10321063 ectxp->r0 = SB_ERR_EBUSY;
10331064 }
1065+
1066+ chSysUnlock();
10341067 #else
10351068 ectxp->r0 = SB_ERR_NOT_IMPLEMENTED;
10361069 #endif
--- trunk/os/sb/host/sbhost.c (revision 14904)
+++ trunk/os/sb/host/sbhost.c (revision 14905)
@@ -201,7 +201,7 @@
201201 /* If a timeout occurred while the boxed thread already received the message
202202 then this thread needs to "unregister" as sender, the boxed error will
203203 get SB_ERR_EBUSY when/if trying to reply.*/
204- if (sbcp->msg_tp == ctp) {
204+ if ((msg == MSG_TIMEOUT) && (sbcp->msg_tp == ctp)) {
205205 sbcp->msg_tp = NULL;
206206 }
207207
Show on old repository browser