[Libwebsockets] lws_ring_get_count_free_elements() question/remark
olivier at olivierlanglois.net
Tue Mar 30 18:16:25 CEST 2021
If I read misc/lws_ring.c
I have come to the following observation. On a freshly created 100%
empty ring with a given COUNT,
lws_ring_get_count_free_elements() will return COUNT-1.
Is that correct?
I kinda understand that if head == tail, you cannot differentiate
between 100% full with 100% empty if you would allow the head to be
incremented to reach the same value of tail. Therefore, to avoid this
ambiguity, only the tail is allowed to make that move.
I see 2 ways that this could be resolved:
1. In lws_ring_create(), allocate an extra element so that an empty
ring does have the # of requested free elements
2. Maybe if struct ring had a waiting_elem count, this would remove
this ambiguity and would allow the code to not waste an element. By
assuming that the element size is significantly bigger than an extra
int, this added struct member would be justified memory wise.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Libwebsockets