Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add debug + incredibly stupid bug fix.
[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_mutex_t mutex;
22         smx_cond_t cond;
23         smx_host_t host;
24         smx_action_t action;
25
26         smpi_bench_end();
27         host   = SIMIX_host_self();
28         action = SIMIX_action_sleep(host, seconds);
29         mutex  = SIMIX_mutex_init();
30         cond   = SIMIX_cond_init();
31
32         SIMIX_mutex_lock(mutex);
33         SIMIX_register_action_to_condition(action, cond);
34         SIMIX_cond_wait(cond, mutex);
35         SIMIX_unregister_action_to_condition(action, cond);
36         SIMIX_mutex_unlock(mutex);
37
38         SIMIX_mutex_destroy(mutex);
39         SIMIX_cond_destroy(cond);
40         SIMIX_action_destroy(action);
41
42         // FIXME: check for success/failure?
43
44         smpi_bench_begin();
45         return 0;
46 }
47
48 void smpi_exit(int status)
49 {
50         smpi_bench_end();
51         SIMIX_mutex_lock(smpi_global->running_hosts_count_mutex);
52         smpi_global->running_hosts_count--;
53         SIMIX_mutex_unlock(smpi_global->running_hosts_count_mutex);
54         SIMIX_process_kill(SIMIX_process_self());
55         return;
56 }