X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/b8df87e176f27b25534f27d7e240defa32ca35bc..fbf5fafb60eb44c0c00a7283fd05a6dec5f2b58f:/src/s4u/s4u_Semaphore.cpp diff --git a/src/s4u/s4u_Semaphore.cpp b/src/s4u/s4u_Semaphore.cpp index b407059186..8476633918 100644 --- a/src/s4u/s4u_Semaphore.cpp +++ b/src/s4u/s4u_Semaphore.cpp @@ -4,33 +4,36 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "src/msg/msg_private.hpp" -#include "src/simix/smx_synchro_private.hpp" #include "xbt/log.h" #include "simgrid/forward.h" #include "simgrid/s4u/Semaphore.hpp" +#include "src/kernel/activity/SemaphoreImpl.hpp" namespace simgrid { namespace s4u { Semaphore::Semaphore(unsigned int initial_capacity) { - sem_ = simgrid::simix::simcall([initial_capacity] { return SIMIX_sem_init(initial_capacity); }); + sem_ = simix::simcall([initial_capacity] { return new kernel::activity::SemaphoreImpl(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,17 +43,17 @@ int Semaphore::acquire_timeout(double timeout) void Semaphore::release() { - simgrid::simix::simcall([this] { SIMIX_sem_release(sem_); }); + simix::simcall([this] { sem_->release(); }); } int Semaphore::get_capacity() { - return simgrid::simix::simcall([this] { return SIMIX_sem_get_capacity(sem_); }); + return simix::simcall([this] { return sem_->get_capacity(); }); } int Semaphore::would_block() { - return simgrid::simix::simcall([this] { return SIMIX_sem_would_block(sem_); }); + return simix::simcall([this] { return sem_->would_block(); }); } void intrusive_ptr_add_ref(Semaphore* sem) @@ -68,8 +71,9 @@ void intrusive_ptr_release(Semaphore* sem) } } -} -} +} // namespace s4u +} // namespace simgrid + /* **************************** Public C interface *************************** */ /** @brief creates a semaphore object of the given initial capacity */ sg_sem_t sg_sem_init(int initial_value)