Skip to content

Instantly share code, notes, and snippets.

@mazbox
Created September 9, 2020 10:11
Show Gist options
  • Save mazbox/ab66cd00d001b88dfb3cebb68c72f359 to your computer and use it in GitHub Desktop.
Save mazbox/ab66cd00d001b88dfb3cebb68c72f359 to your computer and use it in GitHub Desktop.
#include "concurrentqueue.h"
moodycamel::ConcurrentQueue<function<void()>> audioThreadQueue(100);
moodycamel::ConcurrentQueue<function<void()>> uiThreadQueue(100);
void runOnAudioThread(function<void()> fn) {
audioThreadQueue.enqueue(fn);
}
void pollAudioThreadQueue() {
function<void()> fn;
while(audioThreadQueue.try_dequeue(fn)) {
fn();
}
}
void runOnUIThread(function<void()> fn) {
uiThreadQueue.enqueue(fn);
}
void pollUIThreadQueue() {
function<void()> fn;
while(uiThreadQueue.try_dequeue(fn)) {
fn();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment