-
-
Notifications
You must be signed in to change notification settings - Fork 44
Refactor/communication between audio and js threads #864
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?
Refactor/communication between audio and js threads #864
Conversation
packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioEventScheduler.h
Outdated
Show resolved
Hide resolved
packages/react-native-audio-api/common/cpp/audioapi/core/AudioNode.cpp
Outdated
Show resolved
Hide resolved
...t-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.h
Outdated
Show resolved
Hide resolved
packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioEventScheduler.cpp
Outdated
Show resolved
Hide resolved
packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/AudioPlayer.cpp
Outdated
Show resolved
Hide resolved
packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/AudioPlayer.cpp
Outdated
Show resolved
Hide resolved
...native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.cpp
Outdated
Show resolved
Hide resolved
packages/react-native-audio-api/common/cpp/audioapi/core/BaseAudioContext.cpp
Outdated
Show resolved
Hide resolved
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.
I would mark this as something that we need to take a look at. It would be very good to be 100% sure that it is thread safe.
| /// @brief Move constructor | ||
| /// @param other | ||
| FatFunction(FatFunction &&other) noexcept { | ||
| if (other.invoker_) { | ||
| if (other.mover_) { | ||
| other.mover_(storage_.data(), other.storage_.data()); | ||
| } else { | ||
| std::memcpy(storage_.data(), other.storage_.data(), N); | ||
| } | ||
| invoker_ = other.invoker_; | ||
| deleter_ = other.deleter_; | ||
| mover_ = other.mover_; | ||
| other.reset(); | ||
| } | ||
| } | ||
|
|
||
| /// @brief Move assignment operator | ||
| /// @param other | ||
| FatFunction &operator=(FatFunction &&other) noexcept { | ||
| if (this != &other) { | ||
| reset(); | ||
| if (other.invoker_) { | ||
| if (other.mover_) { | ||
| other.mover_(storage_.data(), other.storage_.data()); | ||
| } else { | ||
| std::memcpy(storage_.data(), other.storage_.data(), N); | ||
| } | ||
| invoker_ = other.invoker_; | ||
| deleter_ = other.deleter_; | ||
| mover_ = other.mover_; | ||
| other.reset(); | ||
| } | ||
| } |
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.
| /// @brief Move constructor | |
| /// @param other | |
| FatFunction(FatFunction &&other) noexcept { | |
| if (other.invoker_) { | |
| if (other.mover_) { | |
| other.mover_(storage_.data(), other.storage_.data()); | |
| } else { | |
| std::memcpy(storage_.data(), other.storage_.data(), N); | |
| } | |
| invoker_ = other.invoker_; | |
| deleter_ = other.deleter_; | |
| mover_ = other.mover_; | |
| other.reset(); | |
| } | |
| } | |
| /// @brief Move assignment operator | |
| /// @param other | |
| FatFunction &operator=(FatFunction &&other) noexcept { | |
| if (this != &other) { | |
| reset(); | |
| if (other.invoker_) { | |
| if (other.mover_) { | |
| other.mover_(storage_.data(), other.storage_.data()); | |
| } else { | |
| std::memcpy(storage_.data(), other.storage_.data(), N); | |
| } | |
| invoker_ = other.invoker_; | |
| deleter_ = other.deleter_; | |
| mover_ = other.mover_; | |
| other.reset(); | |
| } | |
| } | |
| /// @brief Move constructor | |
| /// @param other | |
| FatFunction(FatFunction &&other) noexcept { | |
| if (other.invoker_) { | |
| if (other.mover_) { | |
| other.mover_(storage_.data(), other.storage_.data()); | |
| } else { | |
| std::memcpy(storage_.data(), other.storage_.data(), N); | |
| } | |
| invoker_ = other.invoker_; | |
| deleter_ = other.deleter_; | |
| mover_ = other.mover_; | |
| other.reset(); | |
| } | |
| } | |
| /// @brief Move assignment operator | |
| /// @param other | |
| FatFunction &operator=(FatFunction &&other) noexcept { | |
| if (this != &other) { | |
| reset(); | |
| new (this) FatFunction(std::move(other)); | |
| } | |
| } |
code duplication
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.
Uuuuu 🆒
Closes RNAA-250
Introduced changes
CrossThreadEventSchedulerwrapper to be executed on Audio thread.HostObjectplays aShadowAudioNoderole - it stores a copy of node's state.Read: Simply read
HostObjectstateWrite: Schedule modification and modify
Shadow StateLock free approach!!!
TODO:
Nodes:
Checklist