Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add the Storage::read_async and Storage::write_async methods
[simgrid.git] / src / msg / msg_synchro.cpp
1 /* Copyright (c) 2013-2018. 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 "xbt/ex.hpp"
7
8 #include "msg_private.hpp"
9 #include "src/simix/smx_private.hpp"
10 #include "src/simix/smx_synchro_private.hpp"
11 #include "xbt/synchro.h"
12
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_synchro, msg, "Logging specific to MSG (synchro)");
14
15 /** @addtogroup msg_synchro
16  *
17  *  @{
18  */
19
20 /** @brief creates a semaphore object of the given initial capacity */
21 msg_sem_t MSG_sem_init(int initial_value) {
22   return simgrid::simix::simcall([initial_value] { return SIMIX_sem_init(initial_value); });
23 }
24
25 /** @brief locks on a semaphore object */
26 void MSG_sem_acquire(msg_sem_t sem) {
27   simcall_sem_acquire(sem);
28 }
29
30 /** @brief locks on a semaphore object up until the provided timeout expires */
31 msg_error_t MSG_sem_acquire_timeout(msg_sem_t sem, double timeout) {
32   return simcall_sem_acquire_timeout(sem, timeout) ? MSG_TIMEOUT : MSG_OK;
33 }
34
35 /** @brief releases the semaphore object */
36 void MSG_sem_release(msg_sem_t sem) {
37   simgrid::simix::simcall([sem] { SIMIX_sem_release(sem); });
38 }
39
40 int MSG_sem_get_capacity(msg_sem_t sem) {
41   return simgrid::simix::simcall([sem] { return SIMIX_sem_get_capacity(sem); });
42 }
43
44 void MSG_sem_destroy(msg_sem_t sem) {
45   SIMIX_sem_destroy(sem);
46 }
47
48 /** @brief returns a boolean indicating if this semaphore would block at this very specific time
49  *
50  * Note that the returned value may be wrong right after the function call, when you try to use it...
51  * But that's a classical semaphore issue, and SimGrid's semaphore are not different to usual ones here.
52  */
53 int MSG_sem_would_block(msg_sem_t sem) {
54   return simgrid::simix::simcall([sem] { return SIMIX_sem_would_block(sem); });
55 }
56
57 /**@}*/