guix-env: some update.
[oweals/gnunet.git] / src / testbed / gnunet-service-test-barriers.c
index efc9d56777e825e6adc7ebb2a89d607f2bfb0fe5..874c7a363ee08a958dae50f2dd8a624de1e204e1 100644 (file)
@@ -1,6 +1,6 @@
 /*
       This file is part of GNUnet
-      (C) 2008--2013 Christian Grothoff (and other contributing authors)
+      Copyright (C) 2008--2013 GNUnet e.V.
 
       GNUnet is free software; you can redistribute it and/or modify
       it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
       You should have received a copy of the GNU General Public License
       along with GNUnet; see the file COPYING.  If not, write to the
-      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-      Boston, MA 02111-1307, USA.
+      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+      Boston, MA 02110-1301, USA.
  */
 
 /**
 /**
  * Our barrier wait handle
  */
-struct GNUNET_TESTBED_BarrierWaitHandle *wh;
+static struct GNUNET_TESTBED_BarrierWaitHandle *wh;
+
+static struct GNUNET_SCHEDULER_Task *tt;
 
 
 /**
  * Dummy task callback to keep us running forever
  *
  * @param cls NULL
- * @param tc scheduler task context
  */
 static void
-do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_shutdown (void *cls)
 {
   if (NULL != wh)
+  {
     GNUNET_TESTBED_barrier_wait_cancel (wh);
-  wh = NULL;
+    wh = NULL;
+  }
+  if (NULL != tt)
+  {
+    GNUNET_SCHEDULER_cancel (tt);
+    tt = NULL;
+  }
 }
 
 
@@ -64,11 +72,13 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  *
  * @param cls NULL
  * @param name the barrier name
- * @param status GNUNET_SYSERR in case of error while waiting for the barrier;
- *   GNUNET_OK if the barrier is crossed
+ * @param status #GNUNET_SYSERR in case of error while waiting for the barrier;
+ *   #GNUNET_OK if the barrier is crossed
  */
 static void
-barrier_wait_cb (void *cls, const char *name, int status)
+barrier_wait_cb (void *cls,
+                 const char *name,
+                 int status)
 {
   GNUNET_break (NULL == cls);
   wh = NULL;
@@ -80,15 +90,15 @@ barrier_wait_cb (void *cls, const char *name, int status)
  * Task to wait for the barrier
  *
  * @param cls NULL
- * @param tc scheduler task context
  * @return
  */
 static void
-do_wait (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_wait (void *cls)
 {
-  if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
-    return;
-  wh = GNUNET_TESTBED_barrier_wait (TEST_BARRIER_NAME, &barrier_wait_cb, NULL);
+  tt = NULL;
+  wh = GNUNET_TESTBED_barrier_wait (TEST_BARRIER_NAME,
+                                   &barrier_wait_cb,
+                                   NULL);
   GNUNET_break (NULL != wh);
 }
 
@@ -102,17 +112,20 @@ do_wait (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * @param config the configuration file handle
  */
 static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+     char *const *args,
+     const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *config)
 {
   unsigned int rsec;
 
-  rsec = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 10);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
-                                (GNUNET_TIME_UNIT_SECONDS, rsec),
-                                &do_wait, NULL);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                &do_shutdown, NULL);
+  rsec = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
+                                   10);
+  tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+                                                                    rsec),
+                                    &do_wait,
+                                     NULL);
+  GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
 }
 
 
@@ -120,7 +133,8 @@ run (void *cls, char *const *args, const char *cfgfile,
 /**
  * Main
  */
-int main (int argc, char **argv)
+int
+main (int argc, char **argv)
 {
   struct GNUNET_GETOPT_CommandLineOption options[] = {
     GNUNET_GETOPT_OPTION_END
@@ -129,6 +143,10 @@ int main (int argc, char **argv)
 
   ret =
       GNUNET_PROGRAM_run (argc, argv,
-                          "test-barriers", "nohelp", options, &run, NULL);
+                          "test-barriers",
+                          "nohelp",
+                          options,
+                          &run,
+                          NULL);
   return ret;
 }