Skip to content

Commit 0ebd911

Browse files
committed
Add NOWAIT flag to prevent reply from consumer
The consumer of a message will reply to the producer when it has finished processing a message. This additional IPC can be avoided by setting the flag NOWAIT on the outbound message. Both, consumer and producer, will act as if the reply has been send implicitly.
1 parent afc3a7d commit 0ebd911

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

src/IPCQueue.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ WaitForConsumption(IPCMessage* aMsg, IPCMessageReply* aReply)
8787
int
8888
IPCMessageWaitForReply(IPCMessage* aMsg)
8989
{
90+
if (aMsg->mStatus & IPC_MESSAGE_FLAG_NOWAIT) {
91+
/* The consumer won't reply to us, so we're
92+
* returning an error here. */
93+
return -1;
94+
}
9095
IPCMessageReply reply;
9196
int res = WaitForConsumption(aMsg, &reply);
9297
if (res < 0) {
@@ -102,6 +107,13 @@ IPCMessageWaitForReply(IPCMessage* aMsg)
102107
int
103108
IPCMessageWaitForConsumption(IPCMessage* aMsg)
104109
{
110+
if (aMsg->mStatus & IPC_MESSAGE_FLAG_NOWAIT) {
111+
/* The consumer won't send a reply. We simply reset
112+
* the message state and succeed silently. */
113+
aMsg->mStatus &= 0x0fffffff;
114+
aMsg->mStatus |= IPC_MESSAGE_STATE_CLEAR;
115+
return 0;
116+
}
105117
IPCMessageReply reply;
106118
int res = WaitForConsumption(aMsg, &reply);
107119
if (res < 0) {
@@ -127,6 +139,11 @@ IPCMessageConsumeAndReply(IPCMessage* aMsg,
127139
uint32_t aFlags, uint32_t aLength,
128140
void* aBuffer)
129141
{
142+
if (aMsg->mStatus & IPC_MESSAGE_FLAG_NOWAIT) {
143+
/* We cannot reply because the producer doesn't
144+
* wait for the consumption of the message. */
145+
return -1;
146+
}
130147
IPCMessageReply reply = {
131148
.mDWord0 = aDWord0,
132149
.mDWord1 = aDWord1,
@@ -139,6 +156,9 @@ IPCMessageConsumeAndReply(IPCMessage* aMsg,
139156
int
140157
IPCMessageConsume(IPCMessage* aMsg)
141158
{
159+
if (aMsg->mStatus & IPC_MESSAGE_FLAG_NOWAIT) {
160+
return 0; /* Silently succeed */
161+
}
142162
static const IPCMessageReply sReply = {
143163
.mDWord0 = 0,
144164
.mDWord1 = 0,
@@ -186,8 +206,15 @@ IPCMessageQueueConsume(IPCMessageQueue* aMsgQueue, IPCMessage* aMsg)
186206
return -1;
187207
}
188208

209+
/* Usually the consumer will send a reply after the message has
210+
* been processed. Except if we set the NOWAIT flag. In this case
211+
* we reset the message state to CLEAR. */
189212
aMsg->mStatus &= 0x0fffffff;
190-
aMsg->mStatus |= IPC_MESSAGE_STATE_PENDING;
213+
if (aMsg->mStatus & IPC_MESSAGE_FLAG_NOWAIT) {
214+
aMsg->mStatus |= IPC_MESSAGE_STATE_CLEAR;
215+
} else {
216+
aMsg->mStatus |= IPC_MESSAGE_STATE_PENDING;
217+
}
191218

192219
BaseType_t res = xQueueSend(aMsgQueue->mWaitQueue, aMsg, 0);
193220
if (res != pdPASS){

src/IPCQueue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
*/
1515

1616
enum IPCMessageStatus {
17+
/* Don't wait for consumer and don't signal consumption to producer. */
18+
IPC_MESSAGE_FLAG_NOWAIT = 0x01000000,
1719
IPC_MESSAGE_STATE_CLEAR = 0x00000000,
1820
IPC_MESSAGE_STATE_PRODUCED = 0x10000000,
1921
IPC_MESSAGE_STATE_PENDING = 0x20000000,

src/Producer.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "Producer.h"
66

77
#include <string.h>
8-
#include <uart_if.h>
98

109
#include "IPCQueue.h"
1110
#include "Ptr.h"
@@ -31,6 +30,8 @@ Run(ProducerTask* aProducer)
3130
if (res < 0) {
3231
return;
3332
}
33+
/* no need to synchronize over static constant buffer */
34+
msg.mStatus |= IPC_MESSAGE_FLAG_NOWAIT;
3435

3536
res = IPCMessageQueueConsume(aProducer->mSendQueue, &msg);
3637
if (res < 0) {
@@ -40,8 +41,8 @@ Run(ProducerTask* aProducer)
4041
vTaskDelay(TicksOfMSecs(200));
4142

4243
/* While we have been waiting in vTaskDelay(), the consumer
43-
* probably processed our message. Waiting for consumption should
44-
* have the reply ready.
44+
* probably processed our message. Waiting for consumption is
45+
* only a formality here, as we set the NOWAIT flag.
4546
*/
4647
res = IPCMessageWaitForConsumption(&msg);
4748
if (res < 0) {

0 commit comments

Comments
 (0)