Logo AND Algorithmique Numérique Distribuée

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