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>
15 #include "simgrid/simix.h"
20 class ConditionVariable;
22 XBT_PUBLIC_CLASS Mutex {
23 friend ConditionVariable;
26 mutex_(simcall_mutex_init()) {}
27 Mutex(simgrid::simix::Mutex* mutex) : mutex_(SIMIX_mutex_ref(mutex)) {}
30 SIMIX_mutex_unref(mutex_);
33 // Copy+move (with the copy-and-swap idiom):
34 Mutex(Mutex const& mutex) : mutex_(SIMIX_mutex_ref(mutex.mutex_)) {}
35 friend void swap(Mutex& first, Mutex& second)
38 swap(first.mutex_, second.mutex_);
40 Mutex& operator=(Mutex mutex)
45 Mutex(Mutex&& mutex) : mutex_(nullptr)
52 return mutex_ != nullptr;
61 simgrid::simix::Mutex* mutex_;
64 }} // namespace simgrid::s4u
66 #endif /* SIMGRID_S4U_MUTEX_HPP */