Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cleaning up and refactoring some of the code to create execution actions.
[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         action = SIMIX_action_sleep(host, seconds);
31
32         SIMIX_register_action_to_condition(action, smpi_global->execute_cond);
33         SIMIX_cond_wait(smpi_global->execute_cond, smpi_global->execute_mutex);
34         SIMIX_unregister_action_to_condition(action, smpi_global->execute_cond);
35         SIMIX_action_destroy(action);
36
37         SIMIX_mutex_unlock(smpi_global->execute_mutex);
38
39         smpi_bench_begin();
40         return 0;
41 }
42
43 void smpi_exit(int status)
44 {
45         smpi_bench_end();
46         SIMIX_mutex_lock(smpi_global->running_hosts_count_mutex);
47         smpi_global->running_hosts_count--;
48         SIMIX_mutex_unlock(smpi_global->running_hosts_count_mutex);
49         SIMIX_process_kill(SIMIX_process_self());
50         return;
51 }