Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Engine is in charge of platform creation, not SIMIX anymore
[simgrid.git] / src / s4u / s4u_Semaphore.cpp
index a1df83b..57a6283 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006-201. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2018-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. */
@@ -15,22 +15,25 @@ namespace s4u {
 
 Semaphore::Semaphore(unsigned int initial_capacity)
 {
-    sem_ = simgrid::simix::simcall([initial_capacity] { return SIMIX_sem_init(initial_capacity); });
+  sem_ = simgrid::simix::simcall([initial_capacity] { return SIMIX_sem_init(initial_capacity); });
 }
 
 Semaphore::~Semaphore()
 {
-    SIMIX_sem_destroy(sem_);
+  if (sem_ != nullptr) {
+    xbt_assert(sem_->sleeping.empty(), "Cannot destroy semaphore since someone is still using it");
+    delete sem_;
+  }
 }
 
 SemaphorePtr Semaphore::create(unsigned int initial_capacity)
 {
-    return SemaphorePtr(new Semaphore(initial_capacity));
+  return SemaphorePtr(new Semaphore(initial_capacity));
 }
 
 void Semaphore::acquire()
 {
-    simcall_sem_acquire(sem_);
+  simcall_sem_acquire(sem_);
 }
 
 int Semaphore::acquire_timeout(double timeout)
@@ -40,7 +43,7 @@ int Semaphore::acquire_timeout(double timeout)
 
 void Semaphore::release()
 {
-    simgrid::simix::simcall([this] { SIMIX_sem_release(sem_); });
+  simgrid::simix::simcall([this] { SIMIX_sem_release(sem_); });
 }
 
 int Semaphore::get_capacity()