#ifndef MBGL_UTIL_RUN_LOOP #define MBGL_UTIL_RUN_LOOP #include #include #include #include namespace uv { class async; class loop; } namespace mbgl { namespace util { template class Thread; class RunLoop { friend Thread; protected: // These are called by the Thread<> wrapper. RunLoop(); ~RunLoop(); // Called by the Thread<> wrapper to start the loop. When you implement this // method in a child class, you *must* call this function as the last action. void start(); protected: // Called by the Thread<> wrapper to terminate this loop. void stop(); // Obtain the underlying loop object in case you want to attach additional listeners. uv::loop& loop() { return *runloop; }; private: // Invokes function in the run loop. void process(); public: // Schedules a function to be executed as part of this run loop. void invoke(std::function&& fn); private: const std::unique_ptr runloop; const std::unique_ptr runloopAsync; std::mutex runloopMutex; std::queue> runloopQueue; }; } } #endif