1 /* Copyright (c) 2013 Da 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.h"
7 #include "xbt/sysdep.h"
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_synchro, msg,
11 "Logging specific to MSG (synchro)");
14 /** @addtogroup msg_synchro
19 /********************************* Host **************************************/
21 /** @brief creates a semaphore object of the given initial capacity */
22 msg_sem_t MSG_sem_init(int initial_value) {
23 return simcall_sem_init(initial_value);
26 /** @brief locks on a semaphore object */
27 void MSG_sem_acquire(msg_sem_t sem) {
28 simcall_sem_acquire(sem);
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) {
33 msg_error_t res = MSG_OK;
35 simcall_sem_acquire_timeout(sem,timeout);
37 if (e.category == timeout_error) {
46 /** @brief releases the semaphore object */
47 void MSG_sem_release(msg_sem_t sem) {
48 simcall_sem_release(sem);
50 void MSG_sem_get_capacity(msg_sem_t sem) {
51 simcall_sem_get_capacity(sem);
54 void MSG_sem_destroy(msg_sem_t sem) {
55 simcall_sem_destroy(sem);
57 /** @brief returns a boolean indicating it this semaphore would block at this very specific time
59 * Note that the returned value may be wrong right after the function call, when you try to use it...
60 * But that's a classical semaphore issue, and SimGrid's semaphore are not different to usual ones here.
62 int MSG_sem_would_block(msg_sem_t sem) {
63 return simcall_sem_would_block(sem);