X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/ef40de9569d6b74e953808d9f9eb3095aa7c38ab..b58b0ba2f6b92efa234677e19dd998346113504d:/src/xbt/OsSemaphore.hpp diff --git a/src/xbt/OsSemaphore.hpp b/src/xbt/OsSemaphore.hpp index 64598509d8..821075f6b0 100644 --- a/src/xbt/OsSemaphore.hpp +++ b/src/xbt/OsSemaphore.hpp @@ -1,27 +1,28 @@ -/* Copyright (c) 2019. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2019-2023. 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 + #include #include -namespace simgrid { -namespace xbt { +namespace simgrid::xbt { class XBT_PUBLIC OsSemaphore { public: - inline OsSemaphore(unsigned int uiCount) : capa_(uiCount) {} + explicit inline OsSemaphore(unsigned int capa) : capa_(capa) {} inline void acquire() { - std::unique_lock lock(mutex_); - condition_.wait(lock, [&]() -> bool { return capa_ > 0; }); + std::unique_lock lock(mutex_); + condition_.wait(lock, [this]() { return capa_ > 0; }); --capa_; } inline void release() { - std::unique_lock lock(mutex_); + const std::scoped_lock lock(mutex_); ++capa_; condition_.notify_one(); } @@ -31,5 +32,4 @@ private: std::mutex mutex_; std::condition_variable condition_; }; -} // namespace xbt -} // namespace simgrid +} // namespace simgrid::xbt