Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix make distcheck
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Fri, 4 Jan 2019 23:09:51 +0000 (00:09 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Fri, 4 Jan 2019 23:10:53 +0000 (00:10 +0100)
src/xbt/OsSemaphore.hpp [new file with mode: 0644]
tools/cmake/test_prog/prog_sem_init.c [deleted file]
tools/cmake/test_prog/prog_sem_open.c [deleted file]

diff --git a/src/xbt/OsSemaphore.hpp b/src/xbt/OsSemaphore.hpp
new file mode 100644 (file)
index 0000000..6459850
--- /dev/null
@@ -0,0 +1,35 @@
+/* Copyright (c) 2019. 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 <condition_variable>
+#include <mutex>
+
+namespace simgrid {
+namespace xbt {
+class XBT_PUBLIC OsSemaphore {
+public:
+  inline OsSemaphore(unsigned int uiCount) : capa_(uiCount) {}
+
+  inline void acquire()
+  {
+    std::unique_lock<std::mutex> lock(mutex_);
+    condition_.wait(lock, [&]() -> bool { return capa_ > 0; });
+    --capa_;
+  }
+
+  inline void release()
+  {
+    std::unique_lock<std::mutex> lock(mutex_);
+    ++capa_;
+    condition_.notify_one();
+  }
+
+private:
+  unsigned int capa_;
+  std::mutex mutex_;
+  std::condition_variable condition_;
+};
+} // namespace xbt
+} // namespace simgrid
diff --git a/tools/cmake/test_prog/prog_sem_init.c b/tools/cmake/test_prog/prog_sem_init.c
deleted file mode 100644 (file)
index e0a53f5..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-/* Copyright (c) 2010-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 <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <semaphore.h>
-
-int main(void)
-{
-  sem_t s;
-  if (sem_init(&s, 0, 0) != 0)
-     return 1;
-  return 0;
-}
diff --git a/tools/cmake/test_prog/prog_sem_open.c b/tools/cmake/test_prog/prog_sem_open.c
deleted file mode 100644 (file)
index 59ad72b..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/* Copyright (c) 2010-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 <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <semaphore.h>
-#include <stdio.h>
-
-#ifndef SEM_FAILED
-#define SEM_FAILED (-1)
-#endif
-
-int main(void) {
-#ifdef WIN32
-  int s;
-#else
-  sem_t * s;
-#endif
-   s = sem_open("/0", O_CREAT, 0644, 10);
-   if (s == SEM_FAILED){
-//     printf("sem_open failed\n");
-     return 1;
-   }
-//   printf("sem_open succeeded\n");
-   return 0;
-}