Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill one simcall, simplify another
[simgrid.git] / src / xbt / xbt_os_synchro.cpp
1 /* Classical synchro schema, implemented on top of SimGrid                  */
2
3 /* Copyright (c) 2007-2016. 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 "xbt/ex.h"
10 #include "xbt/synchro.h"
11
12 #include "simgrid/simix.h" /* used implementation */
13 #include "src/simix/smx_synchro_private.hpp"
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   ((smx_mutex_t)mutex)->unlock(SIMIX_process_self());
36 }
37
38 void xbt_mutex_destroy(xbt_mutex_t mutex)
39 {
40   SIMIX_mutex_unref((smx_mutex_t)mutex);
41 }
42
43 /***** condition related functions *****/
44 xbt_cond_t xbt_cond_init(void)
45 {
46   return (xbt_cond_t)simcall_cond_init();
47 }
48
49 void xbt_cond_wait(xbt_cond_t cond, xbt_mutex_t mutex)
50 {
51   simcall_cond_wait((smx_cond_t)cond, (smx_mutex_t)mutex);
52 }
53
54 void xbt_cond_timedwait(xbt_cond_t cond, xbt_mutex_t mutex, double delay)
55 {
56   simcall_cond_wait_timeout((smx_cond_t)cond, (smx_mutex_t)mutex, delay);
57 }
58
59 void xbt_cond_signal(xbt_cond_t cond)
60 {
61   simcall_cond_signal((smx_cond_t)cond);
62 }
63
64 void xbt_cond_broadcast(xbt_cond_t cond)
65 {
66   simcall_cond_broadcast((smx_cond_t)cond);
67 }
68
69 void xbt_cond_destroy(xbt_cond_t cond)
70 {
71   SIMIX_cond_unref((smx_cond_t)cond);
72 }