Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ac5d3721bac7311320c8c4029bb302e250e35572
[simgrid.git] / src / smpi / smpi_util.c
1 #include "private.h"
2
3 int smpi_gettimeofday(struct timeval *tv, struct timezone *tz)
4 {
5         double now;
6         int retval = 0;
7         smpi_bench_end();
8         if (NULL == tv) {
9                 retval = -1;
10         } else {
11                 now = SIMIX_get_clock();
12                 tv->tv_sec  = now;
13                 tv->tv_usec = ((now - (double)tv->tv_sec) * 1000000.0);
14         }
15         smpi_bench_begin();
16         return retval;
17 }
18
19 unsigned int smpi_sleep(unsigned int seconds)
20 {
21         smx_host_t host;
22         smx_action_t action;
23
24         smpi_bench_end();
25
26         host  = SIMIX_host_self();
27
28         SIMIX_mutex_lock(smpi_global->execute_mutex);
29
30         // FIXME: explicit conversion to double?
31         action = SIMIX_action_sleep(host, seconds);
32
33         SIMIX_register_action_to_condition(action, smpi_global->execute_cond);
34         SIMIX_cond_wait(smpi_global->execute_cond, smpi_global->execute_mutex);
35         SIMIX_unregister_action_to_condition(action, smpi_global->execute_cond);
36         SIMIX_action_destroy(action);
37
38         SIMIX_mutex_unlock(smpi_global->execute_mutex);
39
40         smpi_bench_begin();
41         return 0;
42 }
43
44 void smpi_exit(int status)
45 {
46         smpi_bench_end();
47         SIMIX_mutex_lock(smpi_global->running_hosts_count_mutex);
48         smpi_global->running_hosts_count--;
49         SIMIX_mutex_unlock(smpi_global->running_hosts_count_mutex);
50         SIMIX_process_kill(SIMIX_process_self());
51         return;
52 }