Skip to content

Instantly share code, notes, and snippets.

@mazbox
Created September 9, 2020 10:11
Show Gist options
  • Select an option

  • Save mazbox/ab66cd00d001b88dfb3cebb68c72f359 to your computer and use it in GitHub Desktop.

Select an option

Save mazbox/ab66cd00d001b88dfb3cebb68c72f359 to your computer and use it in GitHub Desktop.

Revisions

  1. mazbox created this gist Sep 9, 2020.
    26 changes: 26 additions & 0 deletions moodylambdaqueue.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #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();
    }
    }