1 /* Copyright (c) 2006-2015. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef SIMGRID_S4U_MUTEX_HPP
7 #define SIMGRID_S4U_MUTEX_HPP
12 #include <boost/intrusive_ptr.hpp>
14 #include "simgrid/simix.h"
19 class ConditionVariable;
21 XBT_PUBLIC_CLASS Mutex {
22 friend ConditionVariable;
25 mutex_(simcall_mutex_init()) {}
26 Mutex(simgrid::simix::Mutex* mutex) : mutex_(SIMIX_mutex_ref(mutex)) {}
29 SIMIX_mutex_unref(mutex_);
32 // Copy+move (with the copy-and-swap idiom):
33 Mutex(Mutex const& mutex) : mutex_(SIMIX_mutex_ref(mutex.mutex_)) {}
34 friend void swap(Mutex& first, Mutex& second)
37 swap(first.mutex_, second.mutex_);
39 Mutex& operator=(Mutex mutex)
44 Mutex(Mutex&& mutex) : mutex_(nullptr)
51 return mutex_ != nullptr;
60 simgrid::simix::Mutex* mutex_;
63 }} // namespace simgrid::s4u
65 #endif /* SIMGRID_S4U_MUTEX_HPP */