Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
oups forgot to describe new parameter
[simgrid.git] / src / msg / msg_synchro.c
1 /* Copyright (c) 2013 Da 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 "msg_private.h"
7 #include "xbt/sysdep.h"
8 #include "xbt/log.h"
9
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_synchro, msg,
11                                 "Logging specific to MSG (synchro)");
12
13
14 /** @addtogroup msg_synchro
15  *
16  *  @{
17  */
18
19 /********************************* Host **************************************/
20
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);
24 }
25
26 /** @brief locks on a semaphore object */
27 void MSG_sem_acquire(msg_sem_t sem) {
28   simcall_sem_acquire(sem);
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   xbt_ex_t e;
33   msg_error_t res = MSG_OK;
34   TRY {
35     simcall_sem_acquire_timeout(sem,timeout);
36   } CATCH(e) {
37     if (e.category == timeout_error) {
38       res = MSG_TIMEOUT;
39       xbt_ex_free(e);
40     } else {
41       RETHROW;
42     }
43   }
44   return res;
45 }
46 /** @brief releases the semaphore object */
47 void MSG_sem_release(msg_sem_t sem) {
48   simcall_sem_release(sem);
49 }
50 void MSG_sem_get_capacity(msg_sem_t sem) {
51   simcall_sem_get_capacity(sem);
52 }
53
54 void MSG_sem_destroy(msg_sem_t sem) {
55   simcall_sem_destroy(sem);
56 }
57 /** @brief returns a boolean indicating it this semaphore would block at this very specific time
58  *
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.
61  */
62 int MSG_sem_would_block(msg_sem_t sem) {
63   return simcall_sem_would_block(sem);
64 }
65
66 /**@}*/