#pragma once #include #include #include #include #include #include #include #include namespace reanimated { // // Copyright (c) 2013 Juan Palacios juan.palacios.puyana@gmail.com // Subject to the BSD 2-Clause License // - see < http://opensource.org/licenses/BSD-2-Clause> // template class Queue { public: T pop() { std::unique_lock mlock(mutex_); while (queue_.empty()) { cond_.wait(mlock); } auto item = queue_.front(); queue_.pop(); return item; } void pop(T &item) { std::unique_lock mlock(mutex_); while (queue_.empty()) { cond_.wait(mlock); } item = queue_.front(); queue_.pop(); } void push(const T &item) { std::unique_lock mlock(mutex_); queue_.push(item); mlock.unlock(); cond_.notify_one(); } void push(T &&item) { std::unique_lock mlock(mutex_); queue_.push(std::move(item)); mlock.unlock(); cond_.notify_one(); } size_t getSize() { std::unique_lock mlock(mutex_); const size_t res = queue_.size(); mlock.unlock(); cond_.notify_one(); return res; } private: std::queue queue_; std::mutex mutex_; std::condition_variable cond_; }; class RuntimeManager; class Scheduler { public: Scheduler(); void scheduleOnJS(std::function job); void setJSCallInvoker( std::shared_ptr jsCallInvoker); void setRuntimeManager(std::shared_ptr runtimeManager); virtual void scheduleOnUI(std::function job); virtual void triggerUI(); virtual ~Scheduler(); protected: std::atomic scheduledOnUI{}; Queue> uiJobs; std::shared_ptr jsCallInvoker_; std::weak_ptr runtimeManager; }; } // namespace reanimated