Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
move MutexImpl to the right namespace
[simgrid.git] / src / s4u / s4u_mutex.cpp
1 /* Copyright (c) 2006-2017. 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(mutex_);
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(mutex_);
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(mutex_);
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 }
44 }