Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[s4u] add mutex
[simgrid.git] / src / s4u / s4u_mutex.cpp
1 /* Copyright (c) 2006-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "xbt/log.h"
8 #include "src/msg/msg_private.h"
9 #include "src/simix/smx_network_private.h"
10
11 #include "simgrid/s4u/mutex.hpp"
12
13
14 using namespace simgrid;
15
16 s4u::Mutex::Mutex() {
17     smx_mutex_t smx_mutex = simcall_mutex_init();
18     _mutex = std::shared_ptr<simgrid::simix::Mutex>(smx_mutex, SIMIX_mutex_destroy  );
19 }
20
21 void s4u::Mutex::lock() {
22   simcall_mutex_lock(_mutex.get());
23 }
24
25 void s4u::Mutex::unlock() {
26   simcall_mutex_unlock(_mutex.get());
27 }
28
29 bool s4u::Mutex::try_lock() {
30   return simcall_mutex_trylock(_mutex.get());
31 }