summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2024-06-27 17:02:57 +0200
committerClaudius "keldu" Holeksa <mail@keldu.de>2024-06-27 17:02:57 +0200
commit64c26487299e22a0d563fa2b9ea12aecd73ff6e4 (patch)
tree9f8b77880a97e12060b105b5725dac6a651a56f6
parenta2f713193ecbc888a1adad7784386e6f54386d4d (diff)
Added ref class in core and did some thoughts in thread
-rw-r--r--modules/core/c++/common.hpp41
-rw-r--r--modules/thread/c++/remote.hpp47
2 files changed, 83 insertions, 5 deletions
diff --git a/modules/core/c++/common.hpp b/modules/core/c++/common.hpp
index d892efe..40b2c43 100644
--- a/modules/core/c++/common.hpp
+++ b/modules/core/c++/common.hpp
@@ -40,6 +40,47 @@ template <typename T> using our = std::shared_ptr<T>;
template <typename T> using lent = std::weak_ptr<T>;
+/**
+ * Reference class for easier distinction
+ * of references and its referenced types.
+ */
+template <typename T>
+class ref {
+private:
+ /**
+ * Referenced type
+ */
+ T* ref_;
+
+ /**
+ * We don't want to move since the would invalidate the type.
+ */
+ SAW_FORBID_MOVE(ref);
+public:
+ /**
+ * Main constructor.
+ */
+ ref(T& ref__):
+ ref_{&ref__}
+ {}
+
+ SAW_DEFAULT_COPY(ref);
+
+ /**
+ * Operator retrieving the itself.
+ */
+ T& operator()(){
+ return *ref_;
+ }
+
+ /**
+ * Operator retrieving the itself.
+ */
+ const T& operator()() const {
+ return *ref_;
+ }
+};
+
template <typename T, class... Args> own<T> heap(Args &&...args) {
return own<T>(new T(std::forward<Args>(args)...));
}
diff --git a/modules/thread/c++/remote.hpp b/modules/thread/c++/remote.hpp
index 83dca4c..37f89ad 100644
--- a/modules/thread/c++/remote.hpp
+++ b/modules/thread/c++/remote.hpp
@@ -3,30 +3,67 @@
#include <thread>
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 {};
}
+/**
+ * A device representing a remote thread. Technically it's
+ * a logical distinction and not a physical.
+ */
template<>
class device<rmt::Thread> final {
private:
event_loop ev_loop_;
- std::thread thread_;
bool keep_running_;
+ std::function<void()> run_func_;
+
+ std::thread thread_;
void run(){
wait_scope wait{ev_loop_};
while(keep_running_){
- wait.wait(std::chrono::seconds{4u});
+ run_func_();
+ wait.wait(std::chrono::seconds{16u});
}
+
+ wait.poll();
}
public:
- device():
+ template<typename Func>
+ device(Func func):
ev_loop_{},
+ keep_running_{true},
+ run_func_{std::move(func)}
thread_{&device<rmt::Thread>::run, this},
- keep_running_{true}
- {
+ {}
+
+ void stop(){
+ keep_running_ = false;
}
};