<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Sep 21, 2023 at 10:01 AM Sebastian Huber <<a href="mailto:sebastian.huber@embedded-brains.de">sebastian.huber@embedded-brains.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
On 21.09.23 16:52, Kinsey Moore wrote:<br>
> On Thu, Sep 21, 2023 at 9:47 AM Sebastian Huber <br>
> <<a href="mailto:sebastian.huber@embedded-brains.de" target="_blank">sebastian.huber@embedded-brains.de</a> <br>
> <mailto:<a href="mailto:sebastian.huber@embedded-brains.de" target="_blank">sebastian.huber@embedded-brains.de</a>>> wrote:<br>
> <br>
> On 20.09.23 20:35, Kinsey Moore wrote:<br>
> [...]<br>
> > @@ -1306,8 +1307,22 @@ static void process_delayed_work(void)<br>
> > while (!rtems_chain_is_tail(&process_work_chain, node)) {<br>
> > work = (struct delayed_work*) node;<br>
> > rtems_chain_node* next_node = rtems_chain_next(node);<br>
> > +<br>
> > + /*<br>
> > + * Don't leave extracted node exposed to other<br>
> operations<br>
> > + * under RTEMS_DEBUG<br>
> > + */<br>
> > +#ifdef RTEMS_DEBUG<br>
> > + mutex_lock(&delayed_work_mutex);<br>
> > +#endif<br>
> > rtems_chain_extract(node);<br>
> > +#ifdef RTEMS_DEBUG<br>
> > + node->next = node;<br>
> > + mutex_unlock(&delayed_work_mutex);<br>
> > +#endif<br>
> > +<br>
> > work->callback(&work->work);<br>
> > + rtems_chain_set_off_chain(node);<br>
> > node = next_node;<br>
> > }<br>
> > }<br>
> <br>
> This change makes no sense to me. The code should work regardless if<br>
> RTEMS_DEBUG is defined or not.<br>
> <br>
> <br>
> RTEMS_DEBUG introduces a behavioral change in rtems_chain_extract() such <br>
> that extracted nodes are automatically set off-chain. When RTEMS_DEBUG <br>
> is not set, node->next is left untouched. This has to be managed because <br>
> this code needs the node to remain on-chain so that it is not re-queued <br>
> during the operation.<br>
<br>
Yes, but while a node is on a chain you must not call <br>
rtems_chain_set_off_chain(). If you want to use the off-chain state, <br>
then you have to use this:<br>
<br>
rtems_chain_extract(node);<br>
rtems_chain_set_off_chain(node);<br>
<br>
or<br>
<br>
rtems_chain_extract_unprotected(node);<br>
rtems_chain_set_off_chain(node);<br>
<br>
The automatic set off-chain in RTEMS_DEBUG is just to ensure that basic <br>
chain operations are used in the right state.<br></blockquote><div><br></div><div>Yes, there is no behavior here where rtems_chain_set_off_chain() is being called on a node that is still in a chain. This section of code is entirely managing the side-effect of RTEMS_DEBUG that sets the node in the off-chain state post-extraction. In this case, that side-effect is undesirable and so a lock is in place to prevent that temporary side-effect from leaking to other parts of the system since all other off-chain checks are behind the same lock.</div><div><br></div><div>Kinsey<br></div></div></div>