mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-21 06:33:31 +00:00
trace_buffer: eliminate race
Since the head of the buffer is marked by a zero-length entry, we must only write the length field if a new head was set. Otherwise, the consumer might already read the new entry and not find the new head as a stop condition. genodelabs/genode#4430
This commit is contained in:
parent
b57ccf3517
commit
91b6032a71
@ -93,7 +93,11 @@ class Genode::Trace::Buffer
|
|||||||
if (len == 0)
|
if (len == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_head_entry()->len = len;
|
/**
|
||||||
|
* remember current length field so that we can write it after we set
|
||||||
|
* the new head
|
||||||
|
*/
|
||||||
|
size_t *old_head_len = &_head_entry()->len;
|
||||||
|
|
||||||
/* advance head offset, wrap when reaching buffer boundary */
|
/* advance head offset, wrap when reaching buffer boundary */
|
||||||
_head_offset += sizeof(_Entry) + len;
|
_head_offset += sizeof(_Entry) + len;
|
||||||
@ -103,6 +107,8 @@ class Genode::Trace::Buffer
|
|||||||
/* mark entry next to new entry with len 0 */
|
/* mark entry next to new entry with len 0 */
|
||||||
else if (_head_offset + sizeof(_Entry) <= _size)
|
else if (_head_offset + sizeof(_Entry) <= _size)
|
||||||
_head_entry()->len = 0;
|
_head_entry()->len = 0;
|
||||||
|
|
||||||
|
*old_head_len = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t wrapped() const { return _wrapped; }
|
size_t wrapped() const { return _wrapped; }
|
||||||
|
Loading…
Reference in New Issue
Block a user