Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Cosmetics: single "TODO" for less sonar smell.
[simgrid.git] / include / simgrid / simix / blocking_simcall.hpp
index 017b7f2..110a27d 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2016-2019. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2016-2021. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include <xbt/sysdep.h>
 
-#include <xbt/future.hpp>
 #include <simgrid/kernel/future.hpp>
 #include <simgrid/simix.h>
 #include <simgrid/simix.hpp>
+#include <xbt/promise.hpp>
 
 namespace simgrid {
 namespace simix {
@@ -45,7 +45,7 @@ XBT_PUBLIC void unblock(smx_actor_t process);
  */
 template <class F> auto kernel_sync(F code) -> decltype(code().get())
 {
-  typedef decltype(code().get()) T;
+  using T = decltype(code().get());
   if (SIMIX_is_maestro())
     xbt_die("Can't execute blocking call in kernel mode");
 
@@ -56,8 +56,8 @@ template <class F> auto kernel_sync(F code) -> decltype(code().get())
       [&result, self, &code] {
         try {
           auto future = code();
-          future.then_([&result, self](std::shared_ptr<simgrid::kernel::FutureState<T>>&& value) {
-            simgrid::xbt::set_promise(result, simgrid::kernel::Future<T>(value));
+          future.then_([&result, self](std::shared_ptr<simgrid::kernel::FutureState<T>> value) {
+            simgrid::xbt::set_promise(result, simgrid::kernel::Future<T>(std::move(value)));
             simgrid::simix::unblock(self);
           });
         } catch (...) {
@@ -70,16 +70,19 @@ template <class F> auto kernel_sync(F code) -> decltype(code().get())
 }
 
 /** A blocking (`wait()`-based) future for SIMIX processes */
-// TODO, .wait_for
-// TODO, .wait_until
-// TODO, SharedFuture
-// TODO, simgrid::simix::when_all - wait for all future to be ready (this one is simple!)
-// TODO, simgrid::simix::when_any - wait for any future to be ready
+// TODO:
+// - .wait_for
+// - .wait_until
+// - SharedFuture
+// - simgrid::simix::when_all - wait for all future to be ready (this one is simple!)
+// - simgrid::simix::when_any - wait for any future to be ready
 template <class T>
 class Future {
 public:
-  Future() { /* Nothing to do*/}
+  Future() = default;
   explicit Future(simgrid::kernel::Future<T> future) : future_(std::move(future)) {}
+  Future(Future&&) noexcept = default;
+  Future& operator=(Future&&) noexcept = default;
 
   bool valid() const { return future_.valid(); }
   T get()
@@ -92,9 +95,9 @@ public:
         [this, &result, self] {
           try {
             // When the kernel future is ready...
-            this->future_.then_([&result, self](std::shared_ptr<simgrid::kernel::FutureState<T>>&& value) {
+            this->future_.then_([&result, self](std::shared_ptr<simgrid::kernel::FutureState<T>> value) {
               // ... wake up the process with the result of the kernel future.
-              simgrid::xbt::set_promise(result, simgrid::kernel::Future<T>(value));
+              simgrid::xbt::set_promise(result, simgrid::kernel::Future<T>(std::move(value)));
               simgrid::simix::unblock(self);
             });
           } catch (...) {
@@ -123,9 +126,9 @@ public:
         [this, &exception, self] {
           try {
             // When the kernel future is ready...
-            this->future_.then_([this, self](std::shared_ptr<simgrid::kernel::FutureState<T>>&& value) {
+            this->future_.then_([this, self](std::shared_ptr<simgrid::kernel::FutureState<T>> value) {
               // ...store it the simix kernel and wake up.
-              this->future_ = std::move(simgrid::kernel::Future<T>(value));
+              this->future_ = simgrid::kernel::Future<T>(std::move(value));
               simgrid::simix::unblock(self);
             });
           } catch (...) {
@@ -135,6 +138,7 @@ public:
         },
         nullptr);
   }
+
 private:
   // We wrap an event-based kernel future:
   simgrid::kernel::Future<T> future_;
@@ -147,12 +151,12 @@ private:
  */
 template <class F> auto kernel_async(F code) -> Future<decltype(code().get())>
 {
-  typedef decltype(code().get()) T;
+  using T = decltype(code().get());
 
   // Execute the code in the kernel and get the kernel future:
   simgrid::kernel::Future<T> future = simgrid::kernel::actor::simcall(std::move(code));
 
-  // Wrap the kernel future in a actor future:
+  // Wrap the kernel future in an actor future:
   return simgrid::simix::Future<T>(std::move(future));
 }
 }