Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix copyright headers
[simgrid.git] / src / xbt / xbt_sg_time.c
1 /* time - time related syscal wrappers                                      */
2
3 /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #include "gras/Virtu/virtu_sg.h"
10
11 /*
12  * Time elapsed since the begining of the simulation.
13  */
14 double xbt_time()
15 {
16   return SIMIX_get_clock();
17 }
18
19 /*
20  * Freeze the process for the specified amount of time
21  */
22 void xbt_sleep(double sec)
23 {
24   smx_action_t act_sleep;
25   smx_process_t proc = SIMIX_process_self();
26   smx_mutex_t mutex;
27   smx_cond_t cond;
28   /* create action to sleep */
29   act_sleep = SIMIX_action_sleep(SIMIX_process_get_host(proc), sec);
30
31   mutex = SIMIX_mutex_init();
32   SIMIX_mutex_lock(mutex);
33   /* create conditional and register action to it */
34   cond = SIMIX_cond_init();
35
36   SIMIX_register_action_to_condition(act_sleep, cond);
37   SIMIX_cond_wait(cond, mutex);
38   SIMIX_mutex_unlock(mutex);
39
40   /* remove variables */
41   SIMIX_cond_destroy(cond);
42   SIMIX_mutex_destroy(mutex);
43   SIMIX_action_destroy(act_sleep);
44
45 }