Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Massive mv to use cmake as the default compilation infrastructure.
[simgrid.git] / examples / msg / suspend / suspend.c
1 /*      $Id$     */
2
3 /* Copyright (c) 2005 Arnaud Legrand. All rights reserved.        */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #include "msg/msg.h"            /* Yeah! If you want to use msg, you need to include msg/msg.h */
9 #include "xbt/sysdep.h"         /* calloc */
10
11 /* Create a log channel to have nice outputs. */
12 #include "xbt/log.h"
13 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
14                              "Messages specific for this msg example");
15
16 typedef enum {
17   PORT_22 = 0,
18   MAX_CHANNEL
19 } channel_t;
20
21
22 /** Lazy guy function. This process suspends itself asap.  */
23 static int lazy_guy(int argc, char *argv[])
24 {
25   INFO0("Nobody's watching me ? Let's go to sleep.");
26   MSG_process_suspend(MSG_process_self());
27   INFO0("Uuuh ? Did somebody call me ?");
28   INFO0("Mmmh, goodbye now.");
29   return 0;
30 }                               /* end_of_lazy_guy */
31
32 /** Dream master function. This process creates a lazy_guy process and
33     resumes it 10 seconds later. */
34 static int dream_master(int argc, char *argv[])
35 {
36   m_process_t lazy = NULL;
37
38   INFO0("Let's create a lazy guy.");
39   lazy = MSG_process_create("Lazy", lazy_guy, NULL, MSG_host_self());
40   INFO0("Let's wait a little bit...");
41   MSG_process_sleep(10.0);
42   INFO0("Let's wake the lazy guy up! >:) BOOOOOUUUHHH!!!!");
43   MSG_process_resume(lazy);
44   INFO0("OK, goodbye now.");
45   return 0;
46 }                               /* end_of_dram_master */
47
48 /** Test function */
49 static MSG_error_t test_all(const char *platform_file,
50                             const char *application_file)
51 {
52   MSG_error_t res = MSG_OK;
53
54   {                             /*  Simulation setting */
55     MSG_set_channel_number(MAX_CHANNEL);
56     MSG_create_environment(platform_file);
57   }
58   {                             /*   Application deployment */
59     MSG_function_register("dream_master", dream_master);
60     MSG_launch_application(application_file);
61   }
62   res = MSG_main();
63
64   INFO1("Simulation time %g", MSG_get_clock());
65   return res;
66 }                               /* end_of_test_all */
67
68
69 /** Main function */
70 int main(int argc, char *argv[])
71 {
72   MSG_error_t res = MSG_OK;
73
74   MSG_global_init(&argc, argv);
75   if (argc < 3) {
76     CRITICAL1("Usage: %s platform_file deployment_file\n", argv[0]);
77     CRITICAL1("example: %s msg_platform.xml msg_deployment_suspend.xml\n",
78               argv[0]);
79     exit(1);
80   }
81   test_all(argv[1], argv[2]);
82   res = MSG_clean();
83
84   if (res == MSG_OK)
85     return 0;
86   else
87     return 1;
88 }                               /* end_of_main */