Conversation
sys/include/tsrb.h
Outdated
| /** | ||
| * @brief Reset a tsrb. | ||
| * @param[out] rb Ringbuffer to operate on | ||
| */ | ||
| static inline void tsrb_reset(tsrb_t *rb) |
There was a problem hiding this comment.
Just nitpicking the name, maybe tsrb_clear would be better?
There was a problem hiding this comment.
Thought about it too and personally I would expect that clear just clears bytes and reset also resets the read and write pointer, which is the case here 🤷
There was a problem hiding this comment.
But no strong preference on my side
There was a problem hiding this comment.
+1 for tsrb_clear(). The read and write pointers are implementation details that should be never accessed from users.
There was a problem hiding this comment.
Then lets go with clear, you can squash that right away.
maribu
left a comment
There was a problem hiding this comment.
Looks good to. I don't insist on the inline-suggestion, as I see arguments for both versions.
sys/include/tsrb.h
Outdated
| static inline void tsrb_reset(tsrb_t *rb) | ||
| { | ||
| unsigned irq_state = irq_disable(); | ||
| tsrb_init(rb, rb->buf, rb->size); |
There was a problem hiding this comment.
| tsrb_init(rb, rb->buf, rb->size); | |
| rb->reads = rb->writes; |
would also work. It might be beneficial to keep rb->reads and rb->writes monotonically growing (except for overflows) for debugging (e.g. to check the total number of bytes written to the tsrb). But I agree that it is more obvious that a call to tsrb_init() will clear the buffer when reading the code.
I think that a modern compiler will emit equally efficient code for both versions.
There was a problem hiding this comment.
Feel free to address or not @HendrikVE squash and trigger ci in either case!
9d18d1c to
de4b32e
Compare
|
Note to self: use this in #17265 instead of zeroing out the read/write members. |
|
The CI is happy with the changes. |
fjmolinas
left a comment
There was a problem hiding this comment.
ACK, thanks @HendrikVE!
Contribution description
Add a function to reset the buffer to its initial state.
Testing procedure
A test case was added. Run
make tests-tsrb term