<div dir="ltr">Yes the physical state can vary depending on the configuration of the RFS. But that is not my point here.<div><br></div><div>Let's see an example:</div><div><br></div><div>Assuming</div><div>- set = physical 1, so RTEMS_RFS_BITMAP_ELEMENT_SET = UINT32_MAX</div><div>- map[index]=0b1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1110 (only the bit at offset=0 is clear)</div><div>- calling rtems_rfs_bitmap_map_set with the bit: index=0 offset=1</div><div><br></div><div>In rtems_rfs_bitmap_map_set()</div><div>- The if condition rtems_rfs_bitmap_match(map[index], RTEMS_RFS_BITMAP_ELEMENT_SET) is <b>false</b></div><div>- the following if body executes:</div><div> map[index] = rtems_rfs_bitmap_set (map[index], 1 << offset); // map[index] <b>remains the same</b> because the bit at offset=1 was set before the call.<br></div><div><div> bit = index;</div><div> index = rtems_rfs_bitmap_map_index (bit);</div><div> offset = rtems_rfs_bitmap_map_offset (bit);</div><div> search_map[index] = rtems_rfs_bitmap_set (search_map[index], 1 << offset); </div><div> control->free--; // <b>WRONG, because map[index] did not change.</b></div><div> rtems_rfs_buffer_mark_dirty (control->buffer); // UNNECESSARY, because map[index] did not change.</div></div><div> </div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 12, 2017 at 12:19 PM, Chris Johns <span dir="ltr"><<a href="mailto:chrisj@rtems.org" target="_blank">chrisj@rtems.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 12/10/17 11:46 am, Fan Deng wrote:<br>
> Thanks Chris!<br>
><br>
> First of all let's make sure a few points are clarified:<br>
><br>
> 1) What should rtems_rfs_bitmap_map_<wbr>set(control, bit) do?<br>
> - 'control' is a handle to the bitmap.<br>
> - 'bit' is the offset of the bit to set in the bitmap. 'bit' should be in the<br>
> range of [0, control->size - 1].<br>
><br>
> 2) How does the bitmap store bits?<br>
> By storing bits in an array of rtems_rfs_bitmap_element objects.<br>
> Each rtems_rfs_bitmap_element is 32bit. So the number of elements is<br>
> control->size / 32.<br>
><br>
> 3) What is map[index]?<br>
> 'index' is calculated as 'bit / 32' and is the offset into the block buffer of<br>
> the element that contains the 'bit'. So map[index] is the value of the element<br>
> that contains the 'bit'.<br>
><br>
> 4) What is 'offset'?<br>
> 'offset' is calculated as 'bit % 32'. It locates the 'bit' in the element that<br>
> contains it.<br>
><br>
> 5) What is RTEMS_RFS_BITMAP_ELEMENT_SET<br>
> This is a constant. If map[index] == RTEMS_RFS_BITMAP_ELEMENT_SET, all bits in<br>
> this element (map[index]) are set. It is used to check that condition and<br>
</span>> _update the search map_.<br>
<br>
Yes the match is doing something like this. The actual match is made more<br>
complicated because the physical state of a set bit can be controlled.<br>
<span class=""><br>
> Now let's see what your change does:<br>
><br>
> - map[index] = rtems_rfs_bitmap_set (map[index], 1 << offset);<br>
> - if (rtems_rfs_bitmap_match(map[<wbr>index], RTEMS_RFS_BITMAP_ELEMENT_SET))<br>
> + if (!rtems_rfs_bitmap_match(map[<wbr>index], RTEMS_RFS_BITMAP_ELEMENT_SET))<br>
> {<br>
><br>
> Your change:<br>
> 1. First updates map[index] to set the bit.<br>
<br>
</span>I moved the set which is a bug in the code in master in my patch I posed. I did<br>
not paste that bit to the next post, I am sorry about that. Here is the fragment<br>
with the moved set included:<br>
<span class=""><br>
- map[index] = rtems_rfs_bitmap_set (map[index], 1 << offset);<br>
- if (rtems_rfs_bitmap_match(map[<wbr>index], RTEMS_RFS_BITMAP_ELEMENT_SET))<br>
+ if (!rtems_rfs_bitmap_match(map[<wbr>index], RTEMS_RFS_BITMAP_ELEMENT_SET))<br>
{<br>
</span>+ map[index] = rtems_rfs_bitmap_set (map[index], 1 << offset);<br>
<span class=""><br>
> 2. Compares the updated map[index] with RTEMS_RFS_BITMAP_ELEMENT_SET. Note this:<br>
</span>> - *DOES NOT* check whether the original bit was set.<br>
<br>
It does because the set was moved.<br>
<br>
> - *DOES NOT* have a way to check if the bit was previously set, as<br>
<span class="">> map[index] has already been overwritten.<br>
</span>> - *DOES* check whether all bits in map[index] are set.<br>
<span class="">><br>
> Please let me know if you agree with my assertions in #2 above. Note the name of<br>
> "RTEMS_RFS_BITMAP_ELEMENT_SET" is slightly misleading. See my points #5 for a<br>
> clarification.<br>
<br>
</span>As above the set state of a bit can be a physical 0 or 1 depending on the build<br>
configuration of the RFS.<br>
<span class="HOEnZb"><font color="#888888"><br>
Chris<br>
</font></span></blockquote></div><br></div>