17 #ifndef DISTRHO_RUNNER_HPP_INCLUDED 
   18 #define DISTRHO_RUNNER_HPP_INCLUDED 
   20 #include "../DistrhoUtils.hpp" 
   22 #ifndef DISTRHO_OS_WASM 
   23 # include "Thread.hpp" 
   25 # include "String.hpp" 
   26 # include <emscripten/html5.h> 
   31 #ifdef DISTRHO_RUNNER_INDIRECT_WASM_CALLS 
   32 long d_emscripten_set_interval(
void (*)(
void*), 
double, 
void*);
 
   33 void d_emscripten_clear_interval(
long);
 
   35 # define d_emscripten_set_interval emscripten_set_interval 
   36 # define d_emscripten_clear_interval emscripten_clear_interval 
   61     Runner(
const char* 
const runnerName = 
nullptr) noexcept
 
   62        #ifndef DISTRHO_OS_WASM 
   63         : fRunnerThread(
this, runnerName),
 
   66         : fRunnerName(runnerName),
 
   77         DISTRHO_SAFE_ASSERT(! isRunnerActive());
 
   86     virtual bool run() = 0;
 
   92     bool shouldRunnerStop() 
const noexcept
 
   94        #ifndef DISTRHO_OS_WASM 
   95         return fRunnerThread.shouldThreadExit();
 
   97         return fIntervalId == 0;
 
  107     bool isRunnerActive() noexcept
 
  109        #ifndef DISTRHO_OS_WASM 
  110         return fRunnerThread.isThreadRunning();
 
  112         return fIntervalId != 0;
 
  119     bool startRunner(
const uint timeIntervalMilliseconds = 0) noexcept
 
  121        #ifndef DISTRHO_OS_WASM 
  122         DISTRHO_SAFE_ASSERT_RETURN(!fRunnerThread.isThreadRunning(), 
false);
 
  123         fTimeInterval = timeIntervalMilliseconds;
 
  124         return fRunnerThread.startThread();
 
  126         DISTRHO_SAFE_ASSERT_RETURN(fIntervalId == 0, 
false);
 
  127         fIntervalId = d_emscripten_set_interval(_entryPoint, timeIntervalMilliseconds, 
this);
 
  136     bool stopRunner() noexcept
 
  138        #ifndef DISTRHO_OS_WASM 
  139         return fRunnerThread.stopThread(-1);
 
  141         signalRunnerShouldStop();
 
  149     void signalRunnerShouldStop() noexcept
 
  151        #ifndef DISTRHO_OS_WASM 
  152         fRunnerThread.signalThreadShouldExit();
 
  154         if (fIntervalId != 0)
 
  156             d_emscripten_clear_interval(fIntervalId);
 
  168     const String& getRunnerName() 
const noexcept
 
  170        #ifndef DISTRHO_OS_WASM 
  171         return fRunnerThread.getThreadName();
 
  180 #ifndef DISTRHO_OS_WASM 
  181     class RunnerThread : 
public Thread 
  186         RunnerThread(
Runner* 
const r, 
const char* 
const rn)
 
  193             const uint timeInterval = runner->fTimeInterval;
 
  195             while (!shouldThreadExit())
 
  197                 bool stillRunning = 
false;
 
  200                     stillRunning = runner->run();
 
  203                 if (stillRunning && !shouldThreadExit())
 
  205                     if (timeInterval != 0)
 
  206                         d_msleep(timeInterval);
 
  223     void _runEntryPoint() noexcept
 
  225         bool stillRunning = 
false;
 
  228             stillRunning = run();
 
  231         if (fIntervalId != 0 && !stillRunning)
 
  233             d_emscripten_clear_interval(fIntervalId);
 
  238     static void _entryPoint(
void* 
const userData) noexcept
 
  240         static_cast<Runner*
>(userData)->_runEntryPoint();
 
  244     DISTRHO_DECLARE_NON_COPYABLE(
Runner)
 
Definition: Runner.hpp:56
 
Definition: String.hpp:35
 
Definition: Thread.hpp:38
 
#define END_NAMESPACE_DISTRHO
Definition: DistrhoInfo.hpp:949
 
#define START_NAMESPACE_DISTRHO
Definition: DistrhoInfo.hpp:943