X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/cff982bd049d26d7acbd0e23324e0de051b06d0d..691ad8fcfd10c7c03c272897ff3f309abadf3043:/src/s4u/s4u_Semaphore.cpp diff --git a/src/s4u/s4u_Semaphore.cpp b/src/s4u/s4u_Semaphore.cpp index 3d8d8c0b1d..d16abce10c 100644 --- a/src/s4u/s4u_Semaphore.cpp +++ b/src/s4u/s4u_Semaphore.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2018-2020. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2018-2021. 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. */ @@ -13,17 +13,12 @@ namespace simgrid { namespace s4u { -Semaphore::Semaphore(unsigned int initial_capacity) -{ - sem_ = kernel::actor::simcall([initial_capacity] { return new kernel::activity::SemaphoreImpl(initial_capacity); }); -} +Semaphore::Semaphore(unsigned int initial_capacity) : pimpl_(new kernel::activity::SemaphoreImpl(initial_capacity)) {} Semaphore::~Semaphore() { - if (sem_ != nullptr) { - xbt_assert(not sem_->is_used(), "Cannot destroy semaphore since someone is still using it"); - delete sem_; - } + xbt_assert(not pimpl_->is_used(), "Cannot destroy semaphore since someone is still using it"); + delete pimpl_; } SemaphorePtr Semaphore::create(unsigned int initial_capacity) @@ -33,27 +28,27 @@ SemaphorePtr Semaphore::create(unsigned int initial_capacity) void Semaphore::acquire() { - simcall_sem_acquire(sem_); + simcall_sem_acquire(pimpl_); } int Semaphore::acquire_timeout(double timeout) { - return simcall_sem_acquire_timeout(sem_, timeout); + return simcall_sem_acquire_timeout(pimpl_, timeout); } void Semaphore::release() { - kernel::actor::simcall([this] { sem_->release(); }); + kernel::actor::simcall([this] { pimpl_->release(); }); } int Semaphore::get_capacity() const { - return kernel::actor::simcall([this] { return sem_->get_capacity(); }); + return kernel::actor::simcall([this] { return pimpl_->get_capacity(); }); } int Semaphore::would_block() const { - return kernel::actor::simcall([this] { return sem_->would_block(); }); + return kernel::actor::simcall([this] { return pimpl_->would_block(); }); } void intrusive_ptr_add_ref(Semaphore* sem)