Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove declarations for never used signal slots.
[simgrid.git] / src / s4u / s4u_Mutex.cpp
1 /* Copyright (c) 2006-2019. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "simgrid/s4u/Mutex.hpp"
7 #include "src/kernel/activity/MutexImpl.hpp"
8
9 namespace simgrid {
10 namespace s4u {
11
12 Mutex::~Mutex()
13 {
14   if (pimpl_ != nullptr)
15     pimpl_->unref();
16 }
17
18 /** @brief Blocks the calling actor until the mutex can be obtained */
19 void Mutex::lock()
20 {
21   simcall_mutex_lock(pimpl_);
22 }
23
24 /** @brief Release the ownership of the mutex, unleashing a blocked actor (if any)
25  *
26  * Will fail if the calling actor does not own the mutex.
27  */
28 void Mutex::unlock()
29 {
30   simcall_mutex_unlock(pimpl_);
31 }
32
33 /** @brief Acquire the mutex if it's free, and return false (without blocking) if not */
34 bool Mutex::try_lock()
35 {
36   return simcall_mutex_trylock(pimpl_);
37 }
38
39 /** @brief Create a new mutex
40  *
41  * See @ref s4u_raii.
42  */
43 MutexPtr Mutex::create()
44 {
45   kernel::activity::MutexImpl* mutex = simix::simcall([] { return new kernel::activity::MutexImpl(); });
46   return MutexPtr(&mutex->mutex(), false);
47 }
48
49 /* refcounting of the intrusive_ptr is delegated to the implementation object */
50 void intrusive_ptr_add_ref(Mutex* mutex)
51 {
52   xbt_assert(mutex);
53   if (mutex->pimpl_)
54     mutex->pimpl_->ref();
55 }
56 void intrusive_ptr_release(Mutex* mutex)
57 {
58   xbt_assert(mutex);
59   if (mutex->pimpl_)
60     mutex->pimpl_->unref();
61 }
62
63 } // namespace s4u
64 } // namespace simgrid