X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/2ca35a707044d033c33cb4f016e6ffddfded0d05..5eeb3c843b60e9ba5e1a952ffe83df2a4d8f5fa0:/include/simgrid/s4u/Mutex.hpp diff --git a/include/simgrid/s4u/Mutex.hpp b/include/simgrid/s4u/Mutex.hpp index 241ae36f91..ae785f4841 100644 --- a/include/simgrid/s4u/Mutex.hpp +++ b/include/simgrid/s4u/Mutex.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2006-2015. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2006-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. */ @@ -6,49 +6,59 @@ #ifndef SIMGRID_S4U_MUTEX_HPP #define SIMGRID_S4U_MUTEX_HPP -#include -#include - -#include - -#include -#include "simgrid/simix.h" +#include +#include namespace simgrid { namespace s4u { class ConditionVariable; -XBT_PUBLIC_CLASS Mutex { -friend ConditionVariable; -private: - friend simgrid::simix::Mutex; - simgrid::simix::Mutex* mutex_; - Mutex(simgrid::simix::Mutex* mutex) : mutex_(mutex) {} -public: +/** @brief A classical mutex, but blocking in the simulation world + * @ingroup s4u_api + * + * It is strictly impossible to use a real mutex, such as + * std::mutex + * or pthread_mutex_t, + * because it would block the whole simulation. + * Instead, you should use the present class, that is a drop-in replacement of + * mutex_); - } - friend void intrusive_ptr_release(Mutex* mutex) - { - xbt_assert(mutex); - SIMIX_mutex_unref(mutex->mutex_); - } +public: using Ptr = boost::intrusive_ptr; // No copy: + /** You cannot create a new mutex by copying an existing one. Use MutexPtr instead */ Mutex(Mutex const&) = delete; + /** You cannot create a new mutex by value assignment either. Use MutexPtr instead */ Mutex& operator=(Mutex const&) = delete; - static Ptr createMutex(); + /** Constructs a new mutex */ + static Ptr create(); -public: void lock(); void unlock(); bool try_lock(); + + // deprecated + /** @deprecated Mutex::create() */ + XBT_ATTRIB_DEPRECATED_v323("Please use Mutex::create()") static Ptr createMutex() { return create(); } }; using MutexPtr = Mutex::Ptr;