Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Indent the rest of the code (examples, buildtools, doc...) except for examples/SMPI...
[simgrid.git] / tools / tesh2 / src / timer.c
index 70e99d3..550f8ae 100644 (file)
  *             This file contains all the definitions of the functions related with\r
  *             the tesh timer type.\r
  *\r
- */\r
\r
+ */  \r
+    \r
 #include <timer.h>\r
 #include <command.h>\r
 #include <unit.h>\r
-\r
-\r
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh);\r
-\r
-static void*\r
-timer_start_routine(void* p);\r
-\r
-ttimer_t\r
-timer_new(command_t command)\r
-{\r
-       ttimer_t timer;\r
-       \r
-       timer = xbt_new0(s_timer_t, 1);\r
-       \r
-       timer->command = command;\r
-       timer->thread = NULL;\r
-       timer->timeouted = 0;\r
-       timer->started = xbt_os_sem_init(0);\r
-\r
-       return timer;\r
-}\r
-\r
-int\r
-timer_free(ttimer_t* ptr)\r
-{\r
-       if((*ptr)->started)\r
-               xbt_os_sem_destroy((*ptr)->started);\r
-\r
-       free(*ptr);\r
-\r
-       *ptr = NULL;\r
-       \r
-       return 0;\r
-}\r
-\r
-void\r
-timer_time(ttimer_t timer)\r
-{\r
-       timer->thread = xbt_os_thread_create("", timer_start_routine, timer);\r
-}\r
-\r
-static void*\r
-timer_start_routine(void* p)\r
-{\r
-       ttimer_t timer = (ttimer_t)p;\r
-       command_t command = timer->command;\r
-       \r
-       int now = (int)time(NULL);\r
-       int lead_time = now + command->context->timeout;\r
-       \r
-       xbt_os_sem_release(timer->started);\r
-       \r
-       while(!command->failed && !command->interrupted && !command->successeded && !timer->timeouted) \r
-       {\r
-               if(lead_time >= now)\r
-               {\r
-                       xbt_os_thread_yield();\r
-                       now = (int)time(NULL);\r
-               }\r
-               else\r
-               {\r
-                       timer->timeouted = 1;\r
-               }\r
-       }\r
-\r
-       if(timer->timeouted && !command->failed && !command->successeded  && !command->interrupted)\r
-       {\r
-               ERROR3("[%s] `%s' timed out after %d sec", command->context->pos, command->context->command_line, command->context->timeout);\r
-\r
-\r
-               unit_set_error(command->unit, ECMDTIMEDOUT, 1);\r
-\r
-               command_kill(command);\r
-               command_handle_failure(command, csr_timeout);\r
-\r
-               while(!command->reader->done)\r
-                       xbt_os_thread_yield();\r
-\r
-               if(command->output->used)\r
-                       INFO2("[%s] Output on timeout:\n%s",command->context->pos, command->output->data);\r
-               else\r
-                       INFO1("[%s] No output before timeout",command->context->pos);\r
-       }\r
-       \r
-       return NULL;\r
-}\r
-\r
-void\r
-timer_wait(ttimer_t timer)\r
-{\r
-       xbt_os_thread_join(timer->thread, NULL);\r
-}\r
+    \r\rXBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh);
+\r\rstatic void *\r timer_start_routine(void *p);
+\r\rttimer_t \r timer_new(command_t command) \r
+{
+  \rttimer_t timer;
+  \r\rtimer = xbt_new0(s_timer_t, 1);
+  \r\rtimer->command = command;
+  \rtimer->thread = NULL;
+  \rtimer->timeouted = 0;
+  \rtimer->started = xbt_os_sem_init(0);
+  \r\rreturn timer;
+\r}
+
+\r\rint \r timer_free(ttimer_t * ptr) \r
+{
+  \rif ((*ptr)->started)
+    \rxbt_os_sem_destroy((*ptr)->started);
+  \r\rfree(*ptr);
+  \r\r*ptr = NULL;
+  \r\rreturn 0;
+\r}
+
+\r\rvoid \r timer_time(ttimer_t timer) \r
+{
+  \rtimer->thread = xbt_os_thread_create("", timer_start_routine, timer);
+\r\r\rstatic void *\r timer_start_routine(void *p) \r
+{
+  \rttimer_t timer = (ttimer_t) p;
+  \rcommand_t command = timer->command;
+  \r\rint now = (int) time(NULL);
+  \rint lead_time = now + command->context->timeout;
+  \r\rxbt_os_sem_release(timer->started);
+  \r\rwhile (!command->failed && !command->interrupted
+           && !command->successeded && !timer->timeouted)
+    \r {
+    \rif (lead_time >= now)
+      \r {
+      \rxbt_os_thread_yield();
+      \rnow = (int) time(NULL);
+      \r}
+    \r
+    else
+      \r {
+      \rtimer->timeouted = 1;
+      \r}
+    \r}
+  \r\rif (timer->timeouted && !command->failed && !command->successeded
+        && !command->interrupted)
+    \r {
+    \rERROR3("[%s] `%s' timed out after %d sec", command->context->pos,
+            command->context->command_line, command->context->timeout);
+    \r\r\runit_set_error(command->unit, ECMDTIMEDOUT, 1,
+                      command->context->pos);
+    \r\rcommand_kill(command);
+    \rcommand_handle_failure(command, csr_timeout);
+    \r\rwhile (!command->reader->done)
+      \rxbt_os_thread_yield();
+    \r\rif (command->output->used)
+      \rINFO2("[%s] Output on timeout:\n%s", command->context->pos,
+             command->output->data);
+    \r
+    else
+      \rINFO1("[%s] No output before timeout", command->context->pos);
+    \r}
+  \r\rreturn NULL;
+\r}
+
+\r\rvoid \r timer_wait(ttimer_t timer) \r
+{
+  \rxbt_os_thread_join(timer->thread, NULL);
+\r\r