1 /* Copyright (c) 2013-2018. The SimGrid Team. All rights reserved. */
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. */
6 #include "msg_private.hpp"
7 #include "simgrid/Exception.hpp"
8 #include "src/simix/smx_private.hpp"
9 #include "src/simix/smx_synchro_private.hpp"
10 #include "xbt/synchro.h"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_synchro, msg, "Logging specific to MSG (synchro)");
14 /** @addtogroup msg_synchro
19 /** @brief creates a semaphore object of the given initial capacity */
20 msg_sem_t MSG_sem_init(int initial_value) {
21 return simgrid::simix::simcall([initial_value] { return SIMIX_sem_init(initial_value); });
24 /** @brief locks on a semaphore object */
25 void MSG_sem_acquire(msg_sem_t sem) {
26 simcall_sem_acquire(sem);
29 /** @brief locks on a semaphore object up until the provided timeout expires */
30 msg_error_t MSG_sem_acquire_timeout(msg_sem_t sem, double timeout) {
31 return simcall_sem_acquire_timeout(sem, timeout) ? MSG_TIMEOUT : MSG_OK;
34 /** @brief releases the semaphore object */
35 void MSG_sem_release(msg_sem_t sem) {
36 simgrid::simix::simcall([sem] { SIMIX_sem_release(sem); });
39 int MSG_sem_get_capacity(msg_sem_t sem) {
40 return simgrid::simix::simcall([sem] { return SIMIX_sem_get_capacity(sem); });
43 void MSG_sem_destroy(msg_sem_t sem) {
44 SIMIX_sem_destroy(sem);
47 /** @brief returns a boolean indicating if this semaphore would block at this very specific time
49 * Note that the returned value may be wrong right after the function call, when you try to use it...
50 * But that's a classical semaphore issue, and SimGrid's semaphore are not different to usual ones here.
52 int MSG_sem_would_block(msg_sem_t sem) {
53 return simgrid::simix::simcall([sem] { return SIMIX_sem_would_block(sem); });