1 /* Copyright (c) 2013-2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "msg_private.h"
8 #include "xbt/sysdep.h"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_synchro, msg,
12 "Logging specific to MSG (synchro)");
15 /** @addtogroup msg_synchro
20 /********************************* Host **************************************/
22 /** @brief creates a semaphore object of the given initial capacity */
23 msg_sem_t MSG_sem_init(int initial_value) {
24 return simcall_sem_init(initial_value);
27 /** @brief locks on a semaphore object */
28 void MSG_sem_acquire(msg_sem_t sem) {
29 simcall_sem_acquire(sem);
31 /** @brief locks on a semaphore object up until the provided timeout expires */
32 msg_error_t MSG_sem_acquire_timeout(msg_sem_t sem, double timeout) {
34 msg_error_t res = MSG_OK;
36 simcall_sem_acquire_timeout(sem,timeout);
38 if (e.category == timeout_error) {
47 /** @brief releases the semaphore object */
48 void MSG_sem_release(msg_sem_t sem) {
49 simcall_sem_release(sem);
51 void MSG_sem_get_capacity(msg_sem_t sem) {
52 simcall_sem_get_capacity(sem);
55 void MSG_sem_destroy(msg_sem_t sem) {
56 simcall_sem_destroy(sem);
58 /** @brief returns a boolean indicating it this semaphore would block at this very specific time
60 * Note that the returned value may be wrong right after the function call, when you try to use it...
61 * But that's a classical semaphore issue, and SimGrid's semaphore are not different to usual ones here.
63 int MSG_sem_would_block(msg_sem_t sem) {
64 return simcall_sem_would_block(sem);