Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #314 from simgrid/smpi-args-cleanup
authorMartin Quinson <624847+mquinson@users.noreply.github.com>
Wed, 21 Nov 2018 10:43:13 +0000 (11:43 +0100)
committerGitHub <noreply@github.com>
Wed, 21 Nov 2018 10:43:13 +0000 (11:43 +0100)
SMPI args cleanup

include/simgrid/forward.h
include/simgrid/msg.h
include/simgrid/s4u/Semaphore.hpp
include/simgrid/semaphore.h [new file with mode: 0644]
src/bindings/java/jmsg_synchro.cpp
src/msg/msg_legacy.cpp
src/msg/msg_synchro.cpp [deleted file]
src/s4u/s4u_Semaphore.cpp
tools/cmake/DefinePackages.cmake
tools/internal/travis-sonarqube.sh

index fd0ab86..4da6084 100644 (file)
@@ -176,6 +176,7 @@ typedef simgrid::s4u::Barrier s4u_Barrier;
 typedef simgrid::s4u::Host s4u_Host;
 typedef simgrid::s4u::Link s4u_Link;
 typedef simgrid::s4u::File s4u_File;
+typedef simgrid::s4u::Semaphore s4u_Semaphore;
 typedef simgrid::s4u::Storage s4u_Storage;
 typedef simgrid::s4u::NetZone s4u_NetZone;
 typedef simgrid::s4u::VirtualMachine s4u_VM;
@@ -195,6 +196,7 @@ typedef struct s4u_Barrier s4u_Barrier;
 typedef struct s4u_Host s4u_Host;
 typedef struct s4u_Link s4u_Link;
 typedef struct s4u_File s4u_File;
+typedef struct s4u_Semaphore s4u_Semaphore;
 typedef struct s4u_Storage s4u_Storage;
 typedef struct s4u_NetZone s4u_NetZone;
 typedef struct s4u_VM s4u_VM;
@@ -209,6 +211,7 @@ typedef struct s_smx_mailbox* smx_mailbox_t;
 #endif
 
 typedef s4u_Barrier* sg_bar_t;
+typedef s4u_Semaphore* sg_sem_t;
 typedef s4u_NetZone* sg_netzone_t;
 typedef s4u_Host* sg_host_t;
 typedef s4u_Link* sg_link_t;
index a80493e..d4d1577 100644 (file)
@@ -14,6 +14,7 @@
 #include <simgrid/instr.h>
 #include <simgrid/mailbox.h>
 #include <simgrid/plugins/live_migration.h>
+#include <simgrid/semaphore.h>
 #include <simgrid/storage.h>
 #include <simgrid/vm.h>
 #include <simgrid/zone.h>
@@ -428,14 +429,11 @@ XBT_PUBLIC const char* MSG_task_get_category(msg_task_t task);
  */
 XBT_PUBLIC void MSG_mailbox_set_async(const char* alias);
 
-/** @brief Opaque type representing a semaphore
- *  @hideinitializer
- */
-typedef struct s_smx_sem_t* msg_sem_t; // Yeah that's a rename of the smx_sem_t which doesnt require smx_sem_t to be
-                                       // declared here
+/** @brief Opaque type representing a semaphore */
+typedef sg_sem_t msg_sem_t;
 XBT_PUBLIC msg_sem_t MSG_sem_init(int initial_value);
 XBT_PUBLIC void MSG_sem_acquire(msg_sem_t sem);
-XBT_PUBLIC msg_error_t MSG_sem_acquire_timeout(msg_sem_t sem, double timeout);
+XBT_PUBLIC int MSG_sem_acquire_timeout(msg_sem_t sem, double timeout);
 XBT_PUBLIC void MSG_sem_release(msg_sem_t sem);
 XBT_PUBLIC int MSG_sem_get_capacity(msg_sem_t sem);
 XBT_PUBLIC void MSG_sem_destroy(msg_sem_t sem);
index 6be8c9f..749db63 100644 (file)
@@ -29,13 +29,13 @@ class XBT_PUBLIC Semaphore {
   smx_sem_t sem_;
   std::atomic_int_fast32_t refcount_{0};
 
-  explicit Semaphore(unsigned int initial_capacity);
-  ~Semaphore();
-
   friend void intrusive_ptr_add_ref(Semaphore* sem);
   friend void intrusive_ptr_release(Semaphore* sem);
 
 public:
+  explicit Semaphore(unsigned int initial_capacity);
+  ~Semaphore();
+
   // No copy:
   /** You cannot create a new semaphore by copying an existing one. Use SemaphorePtr instead */
   Semaphore(Semaphore const&) = delete;
@@ -46,7 +46,10 @@ public:
   static SemaphorePtr create(unsigned int initial_capacity);
 
   void acquire();
+  int acquire_timeout(double timeout);
   void release();
+  int get_capacity();
+  int would_block();
 };
 
 }} // namespace simgrid::s4u
diff --git a/include/simgrid/semaphore.h b/include/simgrid/semaphore.h
new file mode 100644 (file)
index 0000000..61beb12
--- /dev/null
@@ -0,0 +1,25 @@
+/* Public interface to the Link datatype                                    */
+
+/* Copyright (c) 2018. 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. */
+
+#ifndef INCLUDE_SIMGRID_SEMAPHORE_H_
+#define INCLUDE_SIMGRID_SEMAPHORE_H_
+
+#include <simgrid/forward.h>
+
+/* C interface */
+SG_BEGIN_DECL()
+XBT_PUBLIC sg_sem_t sg_sem_init(int initial_value);
+XBT_PUBLIC void sg_sem_acquire(sg_sem_t sem);
+XBT_PUBLIC int sg_sem_acquire_timeout(sg_sem_t sem, double timeout);
+XBT_PUBLIC void sg_sem_release(sg_sem_t sem);
+XBT_PUBLIC int sg_sem_get_capacity(sg_sem_t sem);
+XBT_PUBLIC void sg_sem_destroy(sg_sem_t sem);
+XBT_PUBLIC int sg_sem_would_block(sg_sem_t sem);
+
+SG_END_DECL()
+
+#endif /* INCLUDE_SIMGRID_SEMAPHORE_H_ */
index e79910c..1856342 100644 (file)
@@ -64,7 +64,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Semaphore_acquire(JNIEnv * env, jobj
   msg_sem_t sem;
 
   sem             = (msg_sem_t)(uintptr_t)env->GetLongField(obj, jsynchro_field_Semaphore_bind);
-  msg_error_t res = MSG_sem_acquire_timeout(sem, (double) timeout);
+  msg_error_t res = MSG_sem_acquire_timeout(sem, (double)timeout) == 0 ? MSG_OK : MSG_TIMEOUT;
   if (res != MSG_OK) {
     jmsg_throw_status(env, res);
   }
index 733a70a..53f3cb3 100644 (file)
@@ -378,3 +378,32 @@ int MSG_barrier_wait(sg_bar_t bar)
 {
   return sg_barrier_wait(bar);
 }
+
+sg_sem_t MSG_sem_init(int initial_value)
+{
+  return sg_sem_init(initial_value);
+}
+void MSG_sem_acquire(sg_sem_t sem)
+{
+  sg_sem_acquire(sem);
+}
+int MSG_sem_acquire_timeout(sg_sem_t sem, double timeout)
+{
+  return sg_sem_acquire_timeout(sem, timeout);
+}
+void MSG_sem_release(sg_sem_t sem)
+{
+  sg_sem_release(sem);
+}
+int MSG_sem_get_capacity(sg_sem_t sem)
+{
+  return sg_sem_get_capacity(sem);
+}
+void MSG_sem_destroy(sg_sem_t sem)
+{
+  sg_sem_destroy(sem);
+}
+int MSG_sem_would_block(sg_sem_t sem)
+{
+  return sg_sem_would_block(sem);
+}
diff --git a/src/msg/msg_synchro.cpp b/src/msg/msg_synchro.cpp
deleted file mode 100644 (file)
index c24469b..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Copyright (c) 2013-2018. 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 "msg_private.hpp"
-#include "simgrid/Exception.hpp"
-#include "src/simix/smx_private.hpp"
-#include "src/simix/smx_synchro_private.hpp"
-#include "xbt/synchro.h"
-
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_synchro, msg, "Logging specific to MSG (synchro)");
-
-/** @addtogroup msg_synchro
- *
- *  @{
- */
-
-/** @brief creates a semaphore object of the given initial capacity */
-msg_sem_t MSG_sem_init(int initial_value) {
-  return simgrid::simix::simcall([initial_value] { return SIMIX_sem_init(initial_value); });
-}
-
-/** @brief locks on a semaphore object */
-void MSG_sem_acquire(msg_sem_t sem) {
-  simcall_sem_acquire(sem);
-}
-
-/** @brief locks on a semaphore object up until the provided timeout expires */
-msg_error_t MSG_sem_acquire_timeout(msg_sem_t sem, double timeout) {
-  return simcall_sem_acquire_timeout(sem, timeout) ? MSG_TIMEOUT : MSG_OK;
-}
-
-/** @brief releases the semaphore object */
-void MSG_sem_release(msg_sem_t sem) {
-  simgrid::simix::simcall([sem] { SIMIX_sem_release(sem); });
-}
-
-int MSG_sem_get_capacity(msg_sem_t sem) {
-  return simgrid::simix::simcall([sem] { return SIMIX_sem_get_capacity(sem); });
-}
-
-void MSG_sem_destroy(msg_sem_t sem) {
-  SIMIX_sem_destroy(sem);
-}
-
-/** @brief returns a boolean indicating if this semaphore would block at this very specific time
- *
- * Note that the returned value may be wrong right after the function call, when you try to use it...
- * But that's a classical semaphore issue, and SimGrid's semaphore are not different to usual ones here.
- */
-int MSG_sem_would_block(msg_sem_t sem) {
-  return simgrid::simix::simcall([sem] { return SIMIX_sem_would_block(sem); });
-}
-
-/**@}*/
index 191094a..a1df83b 100644 (file)
@@ -7,6 +7,7 @@
 #include "src/simix/smx_synchro_private.hpp"
 #include "xbt/log.h"
 
+#include "simgrid/forward.h"
 #include "simgrid/s4u/Semaphore.hpp"
 
 namespace simgrid {
@@ -32,11 +33,26 @@ void Semaphore::acquire()
     simcall_sem_acquire(sem_);
 }
 
+int Semaphore::acquire_timeout(double timeout)
+{
+  return simcall_sem_acquire_timeout(sem_, timeout);
+}
+
 void Semaphore::release()
 {
     simgrid::simix::simcall([this] { SIMIX_sem_release(sem_); });
 }
 
+int Semaphore::get_capacity()
+{
+  return simgrid::simix::simcall([this] { return SIMIX_sem_get_capacity(sem_); });
+}
+
+int Semaphore::would_block()
+{
+  return simgrid::simix::simcall([this] { return SIMIX_sem_would_block(sem_); });
+}
+
 void intrusive_ptr_add_ref(Semaphore* sem)
 {
   xbt_assert(sem);
@@ -54,3 +70,47 @@ void intrusive_ptr_release(Semaphore* sem)
 
 }
 }
+/* **************************** Public C interface *************************** */
+/** @brief creates a semaphore object of the given initial capacity */
+sg_sem_t sg_sem_init(int initial_value)
+{
+  return new simgrid::s4u::Semaphore(initial_value);
+}
+
+/** @brief locks on a semaphore object */
+void sg_sem_acquire(sg_sem_t sem)
+{
+  sem->acquire();
+}
+
+/** @brief locks on a semaphore object up until the provided timeout expires */
+int sg_sem_acquire_timeout(sg_sem_t sem, double timeout)
+{
+  return sem->acquire_timeout(timeout);
+}
+
+/** @brief releases the semaphore object */
+void sg_sem_release(sg_sem_t sem)
+{
+  sem->release();
+}
+
+int sg_sem_get_capacity(sg_sem_t sem)
+{
+  return sem->get_capacity();
+}
+
+void sg_sem_destroy(sg_sem_t sem)
+{
+  delete sem;
+}
+
+/** @brief returns a boolean indicating if this semaphore would block at this very specific time
+ *
+ * Note that the returned value may be wrong right after the function call, when you try to use it...
+ * But that's a classical semaphore issue, and SimGrid's semaphore are not different to usual ones here.
+ */
+int sg_sem_would_block(sg_sem_t sem)
+{
+  return sem->would_block();
+}
index ecc3468..8b92768 100644 (file)
@@ -453,7 +453,6 @@ set(MSG_SRC
   src/msg/msg_gos.cpp
   src/msg/msg_legacy.cpp
   src/msg/msg_process.cpp
-  src/msg/msg_synchro.cpp
   src/msg/msg_task.cpp
   )
 
@@ -690,6 +689,7 @@ set(headers_to_install
   include/simgrid/kernel/future.hpp
   include/simgrid/host.h
   include/simgrid/link.h
+  include/simgrid/semaphore.h
   include/simgrid/storage.h
   include/simgrid/vm.h
   include/simgrid/zone.h
index 5cf1136..cfeec9a 100755 (executable)
@@ -11,10 +11,11 @@ set -ex
 
 # Install required software
 installSonarQubeScanner() {
-  export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-2.8
+  local SONAR_SCANNER_VERSION=3.2.0.1227
+  export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION
   rm -rf $SONAR_SCANNER_HOME
   mkdir -p $SONAR_SCANNER_HOME
-  curl -sSLo $HOME/.sonar/sonar-scanner.zip http://repo1.maven.org/maven2/org/sonarsource/scanner/cli/sonar-scanner-cli/2.8/sonar-scanner-cli-2.8.zip
+  curl -sSLo $HOME/.sonar/sonar-scanner.zip http://repo1.maven.org/maven2/org/sonarsource/scanner/cli/sonar-scanner-cli/$SONAR_SCANNER_VERSION/sonar-scanner-cli-$SONAR_SCANNER_VERSION.zip
   unzip $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
   rm $HOME/.sonar/sonar-scanner.zip
   export PATH=$SONAR_SCANNER_HOME/bin:$PATH