Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
snake_case LinkImpl (but the part that should to the engine)
[simgrid.git] / src / s4u / s4u_Mutex.cpp
1 /* Copyright (c) 2006-2018. 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 /** @brief Blocks the calling actor until the mutex can be obtained */
13 void Mutex::lock()
14 {
15   simcall_mutex_lock(pimpl_);
16 }
17
18 /** @brief Release the ownership of the mutex, unleashing a blocked actor (if any)
19  *
20  * Will fail if the calling actor does not own the mutex.
21  */
22 void Mutex::unlock()
23 {
24   simcall_mutex_unlock(pimpl_);
25 }
26
27 /** @brief Acquire the mutex if it's free, and return false (without blocking) if not */
28 bool Mutex::try_lock()
29 {
30   return simcall_mutex_trylock(pimpl_);
31 }
32
33 /** @brief Create a new mutex
34  *
35  * See @ref s4u_raii.
36  */
37 MutexPtr Mutex::createMutex()
38 {
39   smx_mutex_t mutex = simcall_mutex_init();
40   return MutexPtr(&mutex->mutex(), false);
41 }
42
43 /* refcounting of the intrusive_ptr is delegated to the implementation object */
44 void intrusive_ptr_add_ref(Mutex* mutex)
45 {
46   xbt_assert(mutex);
47   SIMIX_mutex_ref(mutex->pimpl_);
48 }
49 void intrusive_ptr_release(Mutex* mutex)
50 {
51   xbt_assert(mutex);
52   SIMIX_mutex_unref(mutex->pimpl_);
53 }
54 } // namespace s4u
55 } // namespace simgrid