Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Remove useless commented lines of code.
[simgrid.git] / src / xbt / xbt_os_synchro.cpp
1 /* Classical synchro schema, implemented on top of SimGrid                  */
2
3 /* Copyright (c) 2007-2019. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #include "simgrid/Exception.hpp"
10 #include "simgrid/simix.h" /* used implementation */
11 #include "src/kernel/activity/ConditionVariableImpl.hpp"
12 #include "src/kernel/activity/MutexImpl.hpp"
13 #include "xbt/synchro.h"
14
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_sync, xbt, "Synchronization mechanism");
16
17 /****** mutex related functions ******/
18 xbt_mutex_t xbt_mutex_init(void)
19 {
20   return (xbt_mutex_t)simcall_mutex_init();
21 }
22
23 void xbt_mutex_acquire(xbt_mutex_t mutex)
24 {
25   simcall_mutex_lock((smx_mutex_t)mutex);
26 }
27
28 int xbt_mutex_try_acquire(xbt_mutex_t mutex)
29 {
30   return simcall_mutex_trylock((smx_mutex_t)mutex);
31 }
32
33 void xbt_mutex_release(xbt_mutex_t mutex)
34 {
35   simcall_mutex_unlock((smx_mutex_t)mutex);
36 }
37
38 void xbt_mutex_destroy(xbt_mutex_t mutex)
39 {
40   if (mutex != nullptr)
41     mutex->unref();
42 }
43
44 /***** condition related functions *****/
45 xbt_cond_t xbt_cond_init(void)
46 {
47   return (xbt_cond_t)simcall_cond_init();
48 }
49
50 void xbt_cond_wait(xbt_cond_t cond, xbt_mutex_t mutex)
51 {
52   simcall_cond_wait((smx_cond_t)cond, (smx_mutex_t)mutex);
53 }
54
55 int xbt_cond_timedwait(xbt_cond_t cond, xbt_mutex_t mutex, double delay)
56 {
57   return simcall_cond_wait_timeout((smx_cond_t)cond, (smx_mutex_t)mutex, delay);
58 }
59
60 void xbt_cond_signal(xbt_cond_t cond)
61 {
62   cond->cond_.notify_one();
63 }
64
65 void xbt_cond_broadcast(xbt_cond_t cond)
66 {
67   cond->cond_.notify_all();
68 }
69
70 void xbt_cond_destroy(xbt_cond_t cond)
71 {
72   delete cond;
73 }