Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
smx: synchro->suspend() and synchro->resume() as proper methods
authorMartin Quinson <martin.quinson@loria.fr>
Fri, 6 May 2016 16:04:43 +0000 (18:04 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Fri, 6 May 2016 16:08:03 +0000 (18:08 +0200)
15 files changed:
src/simix/Synchro.h
src/simix/SynchroComm.cpp [new file with mode: 0644]
src/simix/SynchroComm.hpp
src/simix/SynchroExec.cpp [new file with mode: 0644]
src/simix/SynchroExec.hpp
src/simix/SynchroIo.cpp [new file with mode: 0644]
src/simix/SynchroIo.hpp
src/simix/SynchroRaw.cpp [new file with mode: 0644]
src/simix/SynchroRaw.hpp
src/simix/SynchroSleep.cpp [new file with mode: 0644]
src/simix/SynchroSleep.hpp
src/simix/smx_host.cpp
src/simix/smx_network.cpp
src/simix/smx_process.cpp
tools/cmake/DefinePackages.cmake

index b55a2b9..9ed8f9f 100644 (file)
@@ -22,6 +22,9 @@ namespace simix {
     char *name;                        /* synchro name if any */
     xbt_fifo_t simcalls;               /* List of simcalls waiting for this synchro */
     char *category = nullptr;          /* For instrumentation */
+
+    virtual void suspend()=0;
+    virtual void resume()=0;
   };
 }} // namespace simgrid::simix
 #else /* not C++ */
diff --git a/src/simix/SynchroComm.cpp b/src/simix/SynchroComm.cpp
new file mode 100644 (file)
index 0000000..27ac085
--- /dev/null
@@ -0,0 +1,22 @@
+/* Copyright (c) 2007-2016. 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 "src/simix/SynchroComm.hpp"
+#include "src/surf/surf_interface.hpp"
+
+void simgrid::simix::Comm::suspend() {
+  /* FIXME: shall we suspend also the timeout synchro? */
+  if (surf_comm)
+    surf_comm->suspend();
+  /* in the other case, the action will be suspended on creation, in SIMIX_comm_start() */
+
+}
+
+void simgrid::simix::Comm::resume() {
+  /*FIXME: check what happen with the timeouts */
+  if (surf_comm)
+    surf_comm->resume();
+  /* in the other case, the synchro were not really suspended yet, see SIMIX_comm_suspend() and SIMIX_comm_start() */
+}
index 03c71d7..58e0466 100644 (file)
@@ -6,6 +6,7 @@
 #ifndef _SIMIX_SYNCHRO_COMM_HPP
 #define _SIMIX_SYNCHRO_COMM_HPP
 
+#include "surf/surf.h"
 #include "src/simix/Synchro.h"
 
 typedef enum {
@@ -20,6 +21,9 @@ namespace simix {
 
   XBT_PUBLIC_CLASS Comm : public Synchro {
   public:
+    void suspend();
+    void resume();
+
     e_smx_comm_type_t type;         /* Type of the communication (SIMIX_COMM_SEND or SIMIX_COMM_RECEIVE) */
     smx_mailbox_t mbox;             /* Rendez-vous where the comm is queued */
 
diff --git a/src/simix/SynchroExec.cpp b/src/simix/SynchroExec.cpp
new file mode 100644 (file)
index 0000000..db79ea0
--- /dev/null
@@ -0,0 +1,19 @@
+/* Copyright (c) 2007-2016. 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 "src/simix/SynchroExec.hpp"
+#include "src/surf/surf_interface.hpp"
+
+void simgrid::simix::Exec::suspend()
+{
+  if (surf_exec)
+    surf_exec->suspend();
+}
+
+void simgrid::simix::Exec::resume()
+{
+  if (surf_exec)
+    surf_exec->resume();
+}
index 27b62fd..c81b6b7 100644 (file)
@@ -6,6 +6,7 @@
 #ifndef _SIMIX_SYNCHRO_EXEC_HPP
 #define _SIMIX_SYNCHRO_EXEC_HPP
 
+#include "surf/surf.h"
 #include "src/simix/Synchro.h"
 
 namespace simgrid {
@@ -13,6 +14,9 @@ namespace simix {
 
   XBT_PUBLIC_CLASS Exec : public Synchro {
   public:
+    void suspend();
+    void resume();
+
     sg_host_t host;                /* The host where the execution takes place */
     surf_action_t surf_exec;        /* The Surf execution action encapsulated */
   };
diff --git a/src/simix/SynchroIo.cpp b/src/simix/SynchroIo.cpp
new file mode 100644 (file)
index 0000000..e27e5f5
--- /dev/null
@@ -0,0 +1,19 @@
+/* Copyright (c) 2007-2016. 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 "src/simix/SynchroIo.hpp"
+#include "src/surf/surf_interface.hpp"
+
+void simgrid::simix::Io::suspend()
+{
+  if (surf_io)
+    surf_io->suspend();
+}
+
+void simgrid::simix::Io::resume()
+{
+  if (surf_io)
+    surf_io->resume();
+}
index a3039b7..3d0aa2b 100644 (file)
@@ -6,6 +6,7 @@
 #ifndef _SIMIX_SYNCHRO_IO_HPP
 #define _SIMIX_SYNCHRO_IO_HPP
 
+#include "surf/surf.h"
 #include "src/simix/Synchro.h"
 
 namespace simgrid {
@@ -13,6 +14,9 @@ namespace simix {
 
   XBT_PUBLIC_CLASS Io : public Synchro {
   public:
+    void suspend();
+    void resume();
+
     sg_host_t host;
     surf_action_t surf_io;
   };
diff --git a/src/simix/SynchroRaw.cpp b/src/simix/SynchroRaw.cpp
new file mode 100644 (file)
index 0000000..e73fe3d
--- /dev/null
@@ -0,0 +1,16 @@
+/* Copyright (c) 2007-2016. 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 "src/simix/SynchroRaw.hpp"
+#include "src/surf/surf_interface.hpp"
+
+void simgrid::simix::Raw::suspend() {
+  /* The suspension of raw synchros is delayed to when the process is rescheduled. */
+}
+
+void simgrid::simix::Raw::resume() {
+  /* I cannot resume raw synchros directly. This is delayed to when the process is rescheduled at
+   * the end of the synchro. */
+}
index 3d8a28e..c0a3444 100644 (file)
@@ -6,6 +6,7 @@
 #ifndef _SIMIX_SYNCHRO_RAW_HPP
 #define _SIMIX_SYNCHRO_RAW_HPP
 
+#include "surf/surf.h"
 #include "src/simix/Synchro.h"
 
 namespace simgrid {
@@ -14,6 +15,9 @@ namespace simix {
   /** Used to implement mutexes, semaphores and conditions */
   XBT_PUBLIC_CLASS Raw : public Synchro {
   public:
+    void suspend();
+    void resume();
+
     surf_action_t sleep;
   };
 
diff --git a/src/simix/SynchroSleep.cpp b/src/simix/SynchroSleep.cpp
new file mode 100644 (file)
index 0000000..2395950
--- /dev/null
@@ -0,0 +1,15 @@
+/* Copyright (c) 2007-2016. 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 "src/simix/SynchroSleep.hpp"
+#include "src/surf/surf_interface.hpp"
+
+void simgrid::simix::Sleep::suspend() {
+  surf_sleep->suspend();
+}
+
+void simgrid::simix::Sleep::resume() {
+  surf_sleep->resume();
+}
index 8e4b9a1..5a87136 100644 (file)
@@ -6,6 +6,7 @@
 #ifndef _SIMIX_SYNCHRO_SLEEP_HPP
 #define _SIMIX_SYNCHRO_SLEEP_HPP
 
+#include "surf/surf.h"
 #include "src/simix/Synchro.h"
 
 namespace simgrid {
@@ -13,6 +14,9 @@ namespace simix {
 
   XBT_PUBLIC_CLASS Sleep : public Synchro {
   public:
+    void suspend();
+    void resume();
+
     sg_host_t host;                /* The host that is sleeping */
     surf_action_t surf_sleep;       /* The Surf sleeping action encapsulated */
   };
index 800a511..2115a80 100644 (file)
@@ -416,16 +416,12 @@ void simcall_HANDLER_execution_wait(smx_simcall_t simcall, smx_synchro_t synchro
 
 void SIMIX_execution_suspend(smx_synchro_t synchro)
 {
-  simgrid::simix::Exec *exec = static_cast<simgrid::simix::Exec *>(synchro);
-  if(exec->surf_exec)
-    exec->surf_exec->suspend();
+  synchro->suspend(); // FIXME: USELESS
 }
 
 void SIMIX_execution_resume(smx_synchro_t synchro)
 {
-  simgrid::simix::Exec *exec = static_cast<simgrid::simix::Exec *>(synchro);
-  if(exec->surf_exec)
-    exec->surf_exec->resume();
+  synchro->resume(); // FIXME: USELESS
 }
 
 void SIMIX_execution_finish(smx_synchro_t synchro)
index 8d808d7..03d3519 100644 (file)
@@ -854,22 +854,12 @@ void SIMIX_comm_cancel(smx_synchro_t synchro)
 
 void SIMIX_comm_suspend(smx_synchro_t synchro)
 {
-  simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
-
-  /*FIXME: shall we suspend also the timeout synchro? */
-  if (comm->surf_comm)
-    comm->surf_comm->suspend();
-  /* in the other case, the action will be suspended on creation, in SIMIX_comm_start() */
+  synchro->suspend(); // FIXME: USELESS
 }
 
 void SIMIX_comm_resume(smx_synchro_t synchro)
 {
-  simgrid::simix::Comm *comm = static_cast<simgrid::simix::Comm*>(synchro);
-
-  /*FIXME: check what happen with the timeouts */
-  if (comm->surf_comm)
-    comm->surf_comm->resume();
-  /* in the other case, the synchro were not really suspended yet, see SIMIX_comm_suspend() and SIMIX_comm_start() */
+  synchro->resume(); // FIXME: USELESS
 }
 
 
index c20273a..ed6a6d0 100644 (file)
@@ -644,8 +644,6 @@ void simcall_HANDLER_process_suspend(smx_simcall_t simcall, smx_process_t proces
 
 smx_synchro_t SIMIX_process_suspend(smx_process_t process, smx_process_t issuer)
 {
-  xbt_assert((process != NULL), "Invalid parameters");
-
   if (process->suspended) {
     XBT_DEBUG("Process '%s' is already suspended", process->name);
     return NULL;
@@ -653,32 +651,14 @@ smx_synchro_t SIMIX_process_suspend(smx_process_t process, smx_process_t issuer)
 
   process->suspended = 1;
 
-  /* If we are suspending another process, and it is waiting on a sync, suspend its synchronization. */
+  /* If we are suspending another process that is waiting on a sync, suspend its synchronization. */
   if (process != issuer) {
 
-    if (process->waiting_synchro) {
-
-      simgrid::simix::Exec *exec = dynamic_cast<simgrid::simix::Exec*>(process->waiting_synchro);
-      if (exec != nullptr) {
-        SIMIX_execution_suspend(process->waiting_synchro);
-      }
-
-      simgrid::simix::Comm *comm = dynamic_cast<simgrid::simix::Comm*>(process->waiting_synchro);
-      if (comm != nullptr) {
-        SIMIX_comm_suspend(process->waiting_synchro);
-      }
-
-      simgrid::simix::Sleep *sleep = dynamic_cast<simgrid::simix::Sleep*>(process->waiting_synchro);
-      if (sleep != nullptr) {
-        SIMIX_process_sleep_suspend(process->waiting_synchro);
-      }
+    if (process->waiting_synchro)
+      process->waiting_synchro->suspend();
+    /* If the other process is not waiting, its suspension is delayed to when the process is rescheduled. */
 
-      /* The suspension of raw synchros is delayed to when the process is rescheduled. */
-      return NULL;
-    } else {
-      /* If the other process is not waiting, its suspension is delayed to when the process is rescheduled. */
-      return NULL;
-    }
+    return NULL;
   } else {
     /* FIXME: computation size is zero. Is it okay that bound is zero ? */
     return SIMIX_execution_start(process, "suspend", 0.0, 1.0, 0.0, 0);
@@ -706,24 +686,7 @@ void SIMIX_process_resume(smx_process_t process, smx_process_t issuer)
   if (process != issuer) {
 
     if (process->waiting_synchro) {
-    simgrid::simix::Exec *exec = dynamic_cast<simgrid::simix::Exec*>(process->waiting_synchro);
-    if (exec != nullptr) {
-      SIMIX_execution_resume(process->waiting_synchro);
-    }
-
-    simgrid::simix::Comm *comm = dynamic_cast<simgrid::simix::Comm*>(process->waiting_synchro);
-    if (comm != nullptr) {
-      SIMIX_comm_resume(process->waiting_synchro);
-    }
-
-    simgrid::simix::Sleep *sleep = dynamic_cast<simgrid::simix::Sleep*>(process->waiting_synchro);
-    if (sleep != nullptr) {
-      SIMIX_process_sleep_resume(process->waiting_synchro);
-    }
-
-    /* I cannot resume raw synchros now. This is delayed to when the process is rescheduled at
-     * the end of the synchro. */
-
+      process->waiting_synchro->resume();
     }
   } else XBT_WARN("Strange. Process %p is trying to resume himself.", issuer);
 
@@ -951,16 +914,12 @@ void SIMIX_process_sleep_destroy(smx_synchro_t synchro)
 
 void SIMIX_process_sleep_suspend(smx_synchro_t synchro)
 {
-  simgrid::simix::Sleep *sleep = static_cast<simgrid::simix::Sleep*>(synchro);
-  sleep->surf_sleep->suspend();
+  synchro->suspend(); //FIXME: USELESS
 }
 
 void SIMIX_process_sleep_resume(smx_synchro_t synchro)
 {
-  XBT_DEBUG("Synchro state is %d on process_sleep_resume.", synchro->state);
-  simgrid::simix::Sleep *sleep = static_cast<simgrid::simix::Sleep*>(synchro);
-
-  sleep->surf_sleep->resume();
+  synchro->resume();  //FIXME: USELESS
 }
 
 /**
index d079dd8..d805523 100644 (file)
@@ -348,6 +348,11 @@ set(SIMIX_SRC
   src/simix/smx_vm.cpp
   src/simix/popping.cpp
   src/simix/Synchro.cpp
+  src/simix/SynchroComm.cpp
+  src/simix/SynchroExec.cpp
+  src/simix/SynchroSleep.cpp
+  src/simix/SynchroRaw.cpp
+  src/simix/SynchroIo.cpp
   
   ${SIMIX_GENERATED_SRC}
   )