#pragma once #include namespace saw { /** * ### Device ### * Device acts a launcher? * * Acts a logical device. * Though logical devices are not findable by an address as of now. * * Generally a device represents some info about the remote object? * But what exactly? Does it store capabilities? * * In that case I'd prefer it has compile time information about * those. * * ### RpcServer ### * Should always be created on the side which it is run on. * For SYCL it's kernel launches, so it's created on the local * thread. * For Threads it's supposed to be created on the remote thread. * How do I solve this cleanly? * Technically the server shouldn't know about the device. * It should register with an authority, so it gets requests * though. */ namespace rmt { struct Thread {}; } namespace impl { template class thread_rpc_communication_handler final { private: std::mutex mut_; using FunctionT = std::function(rpc_server&)>; std::deque dispatches_; // TODO Need a send + receive + erase request queue // std::deque; public: thread_rpc_communication_handler() = default; template error_or call(id dat_id){ std::lock_guard lock{mut_}; dispatches_.emplace_back([dat_id](rpc_server& srv){ srv.template call(dat_id); }); } error_or run_next_dispatch(rpc_server& srv){ std::lock_guard lock{mut_}; if(dispatches_.empty()){ return make_error("Dispatch Queue is empty"); } ref front{dispatches_.front()}; front()(); } }; } template class rpc_server { private: our> comms_; public: }; template class rpc_client { private: our> comms_; public: rpc_client(our> comms__): comms_{std::move(comms__)} {} }; /** * A device representing a remote thread. Technically it's * a logical distinction and not a physical. */ template<> class device final { private: event_loop ev_loop_; bool keep_running_; std::function run_func_; // std::vector()>> func_calls_; std::thread thread_; void run(){ wait_scope wait{ev_loop_}; while(keep_running_){ run_func_(); wait.wait(std::chrono::seconds{16u}); } wait.poll(); } public: template device(Func func): ev_loop_{}, keep_running_{true}, run_func_{std::move(func)} thread_{&device::run, this}, {} void stop(){ keep_running_ = false; } }; template<> class remote final { private: public: remote() = default; conveyor>> resolve_address(){ return heap>(*this); } device connect_device(const remote_address& ){ return {}; } }; }