roc-streaming / roc-toolkit

Real-time audio streaming over the network.
https://roc-streaming.org
Mozilla Public License 2.0
1.02k stars 204 forks source link

Extract SeqlockImpl class from Seqlock class #599

Closed gavv closed 6 months ago

gavv commented 9 months ago

core::Seqlock<T> template implements typed sequence lock primitive.

To reduce code size and compilation times, it would be nice to extract its internals to a non-template implementation class. All existing code will continue using Seqlock<T>, however its methods will mostly just invoke similar methods of SeqlockImpl and make some type casts. This way, the template part will be small, and non-template part will be compiled once and reused.

We did a very similar job for core::MpscQueue here:

Unlike MpscQueue, Seqlock has state that depends on template argument (T val_), and can't be moved to implementation class.

However, it does not actually use val_ except doing a byte copy (copy constructor is not used). We can keep val_ field in template class and pass pointer to val_ as void* to methods of the implementation class. We'll also need to pass sizeof(val_) to them.

nolan-veed commented 6 months ago

I'll do this.