-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mbox: provide function to unset initialized mbox #15485
Conversation
@@ -185,6 +185,17 @@ static inline size_t mbox_avail(mbox_t *mbox) | |||
return cib_avail(&mbox->cib); | |||
} | |||
|
|||
/** | |||
* @brief Unset's the mbox, effectively deinitializing and invalidating it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From #15484 (comment)
This leaks a possibly supplied queue. Maybe better call it mbox_release_queue?
The mbox actually works without queue, it'd just be synchronous from that point on.This is also a bit dangerous, if this is called with messages in the queue, they get lost. If there's a sender that was previously waiting, it would be stuck there until the queue transitions from full to empty again.
The sys_mbox_set_invalid()
function is called whenever a netconn (lwIP's sock equivalent) is closed or finished, so this isn't a risk, but maybe that function should be fixed in the way that readers and writers are also released and removed somehow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I still see issues:
- as is, this is not thread safe, something could send/rx a message between those two lines. I think mbox breaks if the array is NULL but cib mask not. (this could be mitigated by changing the order, but that seems hacky).
- any waiters on that mbox would be blocked indefinitely.
I don't see any nice way around this. evenwhile (mbox_try_ receive(tmp) {}
would be racey.
I'm fine adding this function (if needed), but maybe those should be fixed or mentioned?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please squash, changes are minimal and make sense.
I squashed, but have you read my own worries in #15485 (comment)? |
cd29ef3
to
e22e1df
Compare
Hm it's a strange low-level function, if it's useful there is no harm in adding it. Maybe you want something that can take a callback function and iterates over the mbox, calling each element with that function if it's not NULL? But if it's not currently useful that way, we shouldn't merge a bad API. |
It's not really about usefulness, but about exposing such a feature in the first place. |
Useful proper encapsulation is always ;-) |
Ping @kaspar030? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
Ping @kaspar030 the second ;-) |
@kaspar030 do you have something like this on your radar for the rework? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK.
rework postponed ... |
This PR seems mostly ready to go if I'm not mistaken!? |
@miri64 ping |
I agree with @OlegHahm. What do I need to do, to get this in? @kaspar030 approved this, there seems to be no merge conflict, I guess all this needs is a second ACK due to the (inconsequential) core change? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Just to be sure, I ran the testing procedures I provided on BOARD=native make -C tests/pkg/lwip -j flash test
for ipv4 in 0 1; do
for ipv6 in 0 1; do
for board in native samr21-xpro; do
for app in lwip_sock_ip lwip_sock_tcp lwip_sock_udp; do
if [ $ipv4 == 0 ] && [ $ipv6 == 0 ]; then
continue
fi
BOARD=$board LWIP_IPV4=$ipv4 LWIP_IPV6=$ipv6 make -C tests/pkg/${app} -j flash test
done
done
done
done |
I think I need to rebase here, too, just for the Github Actions to succeeds though :-/ |
e22e1df
to
6229fda
Compare
$ git range-diff upstream/master e22e1df 6229fda
1: 0334583749 = 1: 12194ad9e6 mbox: provide function to unset initialized mbox
2: e22e1dfecf = 2: 6229fda7bd lwip: use new mbox_unset() function ;-) so no changes to the commits themselves ;-) |
Contribution description
Split out of #15484, as suggested in #15484 (comment).
Testing procedure
The following tests should still compile and run successfully:
tests/lwip
tests/lwip_sock_ip
(both withLWIP_IPV4=1
andLWIP_IPV6=1
and their combination)tests/lwip_sock_tcp
(both withLWIP_IPV4=1
andLWIP_IPV6=1
and their combination)tests/lwip_sock_udp
(both withLWIP_IPV4=1
andLWIP_IPV6=1
and their combination)Issues/PRs references
Split out of #15484