Skip to content

Commit

Permalink
Merge pull request #15 from tbazin/patch-1
Browse files Browse the repository at this point in the history
Fix callback_handler() not run as infinite loop
  • Loading branch information
2bbb authored Nov 15, 2021
2 parents bc8c344 + 86c6828 commit 057e341
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/napi-abletonlink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,31 @@ namespace napi {
}

static void callback_handler() {
std::lock_guard<std::mutex> sl(bbb_mutex());
while(!bbb_tempo_queue().empty()) {
auto &&front = bbb_tempo_queue().front();
bbb_tempo_queue().pop();
if(bbb_tempo_queue().empty()) {
front.that->tempoChanged(front.bpm);
while (true) {
std::lock_guard<std::mutex> sl(bbb_mutex());
while(!bbb_tempo_queue().empty()) {
auto &&front = bbb_tempo_queue().front();
bbb_tempo_queue().pop();
if(bbb_tempo_queue().empty()) {
front.that->tempoChanged(front.bpm);
}
}
}
while(!bbb_peers_queue().empty()) {
auto &&front = bbb_peers_queue().front();
bbb_peers_queue().pop();
if(bbb_peers_queue().empty()) {
front.that->numPeersChanged(front.numPeers);
while(!bbb_peers_queue().empty()) {
auto &&front = bbb_peers_queue().front();
bbb_peers_queue().pop();
if(bbb_peers_queue().empty()) {
front.that->numPeersChanged(front.numPeers);
}
}
}
while(!bbb_is_playing_queue().empty()) {
auto &&front = bbb_is_playing_queue().front();
bbb_is_playing_queue().pop();
if(bbb_is_playing_queue().empty()) {
front.that->playStateChanged(front.isPlaying);
while(!bbb_is_playing_queue().empty()) {
auto &&front = bbb_is_playing_queue().front();
bbb_is_playing_queue().pop();
if(bbb_is_playing_queue().empty()) {
front.that->playStateChanged(front.isPlaying);
}
}
}
std::this_thread::sleep_for( std::chrono::milliseconds(1) );
std::this_thread::sleep_for( std::chrono::milliseconds(1) );
}
}
static std::thread &callback_thread() {
static std::thread th;
Expand Down

0 comments on commit 057e341

Please sign in to comment.