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
13 #include "simgrid/simix.h"
18 class ConditionVariable;
20 XBT_PUBLIC_CLASS Mutex {
21 friend ConditionVariable;
24 mutex_(simcall_mutex_init()) {}
25 Mutex(simgrid::simix::Mutex* mutex) : mutex_(SIMIX_mutex_ref(mutex)) {}
28 SIMIX_mutex_unref(mutex_);
31 // Copy+move (with the copy-and-swap idiom):
32 Mutex(Mutex const& mutex) : mutex_(SIMIX_mutex_ref(mutex.mutex_)) {}
33 friend void swap(Mutex& first, Mutex& second)
36 swap(first.mutex_, second.mutex_);
38 Mutex& operator=(Mutex mutex)
43 Mutex(Mutex&& mutex) : mutex_(nullptr)
50 return mutex_ != nullptr;
59 simgrid::simix::Mutex* mutex_;
62 }} // namespace simgrid::s4u
64 #endif /* SIMGRID_S4U_MUTEX_HPP */