Skip to content

Commit

Permalink
Fix a bug in callback_thread
Browse files Browse the repository at this point in the history
Signed-off-by: Jukka Laitinen <[email protected]>
  • Loading branch information
jlaitine committed Dec 14, 2023
1 parent 1d8d5fe commit cf09b85
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion platforms/common/uORB/SubscriptionCallback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,16 @@ class SubscriptionCallback : public SubscriptionInterval, public ListNode<Subscr
return DeviceNode::get_max_writer_priority(_subscription.get_node());
}

void do_call()
bool do_call()
{
bool dequeued = uORB::Manager::dequeueCallback(_subscription.get_node(), _cb_handle);

if (dequeued) {

call();
}

return dequeued;
}
#endif

Expand Down
12 changes: 11 additions & 1 deletion platforms/common/uORB/uORBManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,14 +530,24 @@ int
uORB::Manager::callback_thread(int argc, char *argv[])
{
while (true) {
/* Sleep here waiting for callbacks */
lockThread(per_process_lock);

/* Each publish has unlocked once, and each do_call() will
* lock it back. Free the lock once here, so that after the
* last call we won't lock in the last do_call()
*/
unlockThread(per_process_lock);

lock_cb_list();

for (auto sub : per_process_cb_list) {
adjust_callback_thread_priority(sub->priority());
sub->do_call();

/* Just in cast the callback thread has been starved,
* run all the queued callbacks now
*/
while (sub->do_call()) {}
}

unlock_cb_list();
Expand Down

0 comments on commit cf09b85

Please sign in to comment.