Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add the Storage::read_async and Storage::write_async methods
[simgrid.git] / src / xbt / xbt_os_synchro.cpp
1 /* Classical synchro schema, implemented on top of SimGrid                  */
2
3 /* Copyright (c) 2007-2018. 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/simix.h" /* used implementation */
10 #include "src/kernel/activity/ConditionVariableImpl.hpp"
11 #include "xbt/ex.hpp"
12 #include "xbt/synchro.h"
13
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_sync, xbt, "Synchronization mechanism");
15
16 /****** mutex related functions ******/
17 xbt_mutex_t xbt_mutex_init(void)
18 {
19   return (xbt_mutex_t)simcall_mutex_init();
20 }
21
22 void xbt_mutex_acquire(xbt_mutex_t mutex)
23 {
24   simcall_mutex_lock((smx_mutex_t)mutex);
25 }
26
27 int xbt_mutex_try_acquire(xbt_mutex_t mutex)
28 {
29   return simcall_mutex_trylock((smx_mutex_t)mutex);
30 }
31
32 void xbt_mutex_release(xbt_mutex_t mutex)
33 {
34   simcall_mutex_unlock((smx_mutex_t)mutex);
35 }
36
37 void xbt_mutex_destroy(xbt_mutex_t mutex)
38 {
39   SIMIX_mutex_unref((smx_mutex_t)mutex);
40 }
41
42 /***** condition related functions *****/
43 xbt_cond_t xbt_cond_init(void)
44 {
45   return (xbt_cond_t)simcall_cond_init();
46 }
47
48 void xbt_cond_wait(xbt_cond_t cond, xbt_mutex_t mutex)
49 {
50   simcall_cond_wait((smx_cond_t)cond, (smx_mutex_t)mutex);
51 }
52
53 int xbt_cond_timedwait(xbt_cond_t cond, xbt_mutex_t mutex, double delay)
54 {
55   return simcall_cond_wait_timeout((smx_cond_t)cond, (smx_mutex_t)mutex, delay);
56 }
57
58 void xbt_cond_signal(xbt_cond_t cond)
59 {
60   cond->cond_.notify_one();
61 }
62
63 void xbt_cond_broadcast(xbt_cond_t cond)
64 {
65   cond->cond_.notify_all();
66 }
67
68 void xbt_cond_destroy(xbt_cond_t cond)
69 {
70   delete cond;
71 }