-
Notifications
You must be signed in to change notification settings - Fork 117
feat(audiotrack): lockless buffer #656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
||
import ( | ||
"runtime" | ||
"sync/atomic" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We standardise on uber atomic. It is nicer to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, will replace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
capacity-- | ||
capacity |= capacity >> 1 | ||
capacity |= capacity >> 2 | ||
capacity |= capacity >> 4 | ||
capacity |= capacity >> 8 | ||
capacity |= capacity >> 16 | ||
capacity++ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bits.Len32
head *atomic.Uint32 | ||
tail *atomic.Uint32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are zero initialized automatically so you can avoid the extra indirection and skip initializing with New(0) if these are atomic.Uint32
instead of *atomic.Uint32
for i := uint32(0); i < currentBatchSize; i++ { | ||
slotIndex := (head + i) & cb.mask | ||
result = append(result, cb.buffer[slotIndex]) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be implemented in at most 2 copies? after head has been updated is the read range safe from concurrent writes?
Noticing some crackling noise, debugging that. The audio otherwise seems to be in the correct order.