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
11 #include <boost/intrusive_ptr.hpp>
13 #include "simgrid/simix.h"
18 XBT_PUBLIC_CLASS Mutex {
22 mutex_(simcall_mutex_init()) {}
23 Mutex(simgrid::simix::Mutex* mutex) : mutex_(SIMIX_mutex_ref(mutex)) {}
26 SIMIX_mutex_unref(mutex_);
29 // Copy+move (with the copy-and-swap idiom):
30 Mutex(Mutex const& mutex) : mutex_(SIMIX_mutex_ref(mutex.mutex_)) {}
31 friend void swap(Mutex& first, Mutex& second)
34 swap(first.mutex_, second.mutex_);
36 Mutex& operator=(Mutex mutex)
41 Mutex(Mutex&& mutex) : mutex_(nullptr)
48 return mutex_ != nullptr;
57 simgrid::simix::Mutex* mutex_;
59 }} // namespace simgrid::s4u
61 #endif /* SIMGRID_S4U_MUTEX_HPP */