Skip to content

Commit 8b1b30f

Browse files
committed
[imp] allow timeouts in notification broadcasts
1 parent be679c4 commit 8b1b30f

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/Framework/Notifications/notifier.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,16 @@ class Notifier {
9696
/**
9797
* @brief Broadcast message to registered @p Listener.
9898
*
99-
* @note The broadcast is guaranteed to NOT block. Errors can either occur
100-
* the @p Notifier message pool is exhausted or if the mail box of a
101-
* @p Listener is full.
99+
* @note Message dropping because of timeouts can either occur because
100+
* the @p Notifier message pool is exhausted or because the mail box
101+
* of a @p Listener is full.
102102
*
103103
* @param[in] msg Holds the message which is to be broadcasted.
104+
* @param timeout Timeout for memory allocation.
104105
* @return RDY_OK If all @p Listener were notified.
105106
* @return RDY_RESET If at least one @p Listener got no message
106107
*/
107-
msg_t broadcast(const MsgType& msg);
108+
msg_t broadcast(const MsgType& msg, systime_t timeout);
108109

109110
/**
110111
* @brief Acquire a @p NotifierMsg which can be transmitted with
@@ -121,7 +122,7 @@ class Notifier {
121122
* @return RDY_OK If all @p Listener were notified.
122123
* @return RDY_RESET If at least one @p Listener got no message
123124
*/
124-
msg_t broadcastMsg(NotifierMsg<MsgType>* msg);
125+
msg_t broadcastMsg(NotifierMsg<MsgType>* msg, systime_t timeout);
125126

126127
/**
127128
* @brief Register a @p Listener to the Notifier

src/Framework/Notifications/notifier_imp.hpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ NotifierMsg<MsgType>* Notifier<MsgType>::acquireMsg(systime_t timeout){
6969
}
7070

7171
template <class MsgType>
72-
msg_t Notifier<MsgType>::broadcastMsg(NotifierMsg<MsgType>* msg){
72+
msg_t Notifier<MsgType>::broadcastMsg(NotifierMsg<MsgType>* msg,
73+
systime_t timeout){
74+
7375

7476
msg_t errorState = RDY_OK;
7577

@@ -79,13 +81,15 @@ msg_t Notifier<MsgType>::broadcastMsg(NotifierMsg<MsgType>* msg){
7981
Listener<MsgType>* listener = n->get();
8082

8183
chSysLock();
82-
msg_t err = chMBPostI(&listener->mailbox, (msg_t) msg);
8384

84-
if (err == RDY_OK){
85+
msg_t rdymsg = chMBPostS(&listener->mailbox, (msg_t) msg, timeout);
86+
87+
if (rdymsg == RDY_OK){
8588
msg->usedCntr++;
8689
} else {
8790
errorState = RDY_RESET;
8891
}
92+
8993
chSysUnlock()
9094

9195
}
@@ -95,13 +99,13 @@ msg_t Notifier<MsgType>::broadcastMsg(NotifierMsg<MsgType>* msg){
9599
}
96100

97101
template <class MsgType>
98-
msg_t Notifier<MsgType>::broadcast(const MsgType& msg){
102+
msg_t Notifier<MsgType>::broadcast(const MsgType& msg, systime_t timeout){
99103

100104
// If there is no listener -> skip all the stuff
101105
if(listenersList.empty())
102106
return RDY_OK;
103107

104-
NotifierMsg<MsgType>* msgCopy = acquireMsg(TIME_IMMEDIATE);
108+
NotifierMsg<MsgType>* msgCopy = acquireMsg(timeout);
105109

106110
// Out of pool memory
107111
if(!msgCopy)
@@ -110,7 +114,7 @@ msg_t Notifier<MsgType>::broadcast(const MsgType& msg){
110114
// Assign message to new copy of object
111115
msgCopy->msg = msg;
112116

113-
return broadcastMsg(msgCopy);
117+
return broadcastMsg(msgCopy, timeout);
114118

115119
}
116120

0 commit comments

Comments
 (0)