gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r8721 - in gnunet/src: datastore include util


From: gnunet
Subject: [GNUnet-SVN] r8721 - in gnunet/src: datastore include util
Date: Fri, 17 Jul 2009 04:36:54 -0600

Author: grothoff
Date: 2009-07-17 04:36:53 -0600 (Fri, 17 Jul 2009)
New Revision: 8721

Modified:
   gnunet/src/datastore/perf_datastore_api.c
   gnunet/src/datastore/test_datastore_api.c
   gnunet/src/include/gnunet_time_lib.h
   gnunet/src/util/time.c
Log:
stuff

Modified: gnunet/src/datastore/perf_datastore_api.c
===================================================================
--- gnunet/src/datastore/perf_datastore_api.c   2009-07-16 22:31:33 UTC (rev 
8720)
+++ gnunet/src/datastore/perf_datastore_api.c   2009-07-17 10:36:53 UTC (rev 
8721)
@@ -111,7 +111,6 @@
 
 static int ok;
 
-
 static int
 putValue (int i, int k)
 {
@@ -171,33 +170,81 @@
 }
 
 
+enum RunPhase
+  {
+    RP_DONE = 0,
+    RP_PUT,
+    RP_CUT,
+    RP_REPORT,
+    RP_END
+  };
 
-static void
-run (void *cls,
-     struct GNUNET_SCHEDULER_Handle *sched,
-     char *const *args,
-     const char *cfgfile, struct GNUNET_CONFIGURATION_Handle *cfg)
+
+struct CpsRunContext
 {
+  struct GNUNET_SCHEDULER_Handle *sched;
+  struct GNUNET_CONFIGURATION_Handle *cfg;
+  enum RunPhase phase;
   int j;
   unsigned long long size;
   int i;
 
-  datastore = GNUNET_DATASTORE_connect (cfg, sched);
-  /* FIXME: change loop to use CPS; current
-     datastore API will likely react negative to
-     us ignoring the callbacks... */
-  for (i = 0; i < ITERATIONS; i++)
+
+  GNUNET_HashCode key;
+  int *iptr;
+};
+
+
+
+static void
+run_continuation (void *cls,
+                 const struct GNUNET_SCHEDULER_TaskContext *tc);
+
+
+
+static void
+run_continuation (void *cls,
+                 const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct CpsRunContext *crc = cls;
+  ok = (int) crc->phase;
+  switch (crc->phase)
     {
-#if REPORT_ID
-      fprintf (stderr, ".");
-#endif
-      /* insert data equivalent to 1/10th of MAX_SIZE */
-      for (j = 0; j < PUT_10; j++)
-       GNUNET_assert (GNUNET_OK == putValue (j, i));
+    case RP_PUT:
+      memset (&crc->key, 256 - crc->i, sizeof (GNUNET_HashCode));
 
+      GNUNET_assert (GNUNET_OK == putValue (j, i));
+      GNUNET_DATASTORE_put (datastore,
+                           0,
+                           &crc->key,
+                           get_size (crc->i),
+                           get_data (crc->i),
+                           get_type (crc->i),
+                           get_priority (crc->i),
+                           get_anonymity (crc->i),
+                           get_expiration (crc->i),
+                           TIMEOUT,
+                           &check_success,
+                           crc);
+      crc->j++;
+      if (crc->j < PUT_10)
+       break;
+      crc->j = 0;
+      crc->i++;
+      if (crc->i == ITERATIONS)
+       crc->phase = RP_DONE;
+      else
+       crc->phase = RP_CUT;
+      break;
+    case RP_CUT:
       /* trim down below MAX_SIZE again */
       if ((i % 2) == 0)
-        GNUNET_DATASTORE_get_random (datastore, &iterate_delete, NULL);
+        GNUNET_DATASTORE_get_random (datastore, 
+                                    &iterate_delete,
+                                    NULL);
+      crc->phase = RP_REPORT;
+      break;
+    case RP_REPORT:
       size = 0;
       printf (
 #if REPORT_ID
@@ -207,11 +254,44 @@
               stored_bytes / 1024,     /* used size in k */
                (stored_ops * 2 - stored_entries) / 1024,        /* total 
operations (in k) */
                1000 * (stored_ops * 2 - stored_entries) / (1 + 
GNUNET_TIME_absolute_get_duration(start_time).value));       /* operations per 
second */
+      crc->phase = RP_PUT;
+      // fixme: trigger next round...
+      GNUNET_SCHEDULER_add_continuation (crc->sched,
+                                        GNUNET_NO,
+                                        &run_continuation,
+                                        crc,
+                                        GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+      break;
+    case RP_DONE:
+      GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
+      ok = 0;
+      break;
     }
-  GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
 }
 
 
+static void
+run (void *cls,
+     struct GNUNET_SCHEDULER_Handle *sched,
+     char *const *args,
+     const char *cfgfile, struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  struct CpsRunContext *crc;
+
+  datastore = GNUNET_DATASTORE_connect (cfg, sched);
+
+  crc = GNUNET_malloc(sizeof(struct CpsRunContext));
+  crc->sched = sched;
+  crc->cfg = cfg;
+  crc->phase = RP_PUT;
+  GNUNET_SCHEDULER_add_continuation (crc->sched,
+                                    GNUNET_NO,
+                                    &run_continuation,
+                                    crc,
+                                    GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+}
+
+
 static int
 check ()
 {

Modified: gnunet/src/datastore/test_datastore_api.c
===================================================================
--- gnunet/src/datastore/test_datastore_api.c   2009-07-16 22:31:33 UTC (rev 
8720)
+++ gnunet/src/datastore/test_datastore_api.c   2009-07-17 10:36:53 UTC (rev 
8721)
@@ -82,7 +82,7 @@
 }
 
 
-static struct GNUNET_TIME_Absolute 
+tatic struct GNUNET_TIME_Absolute 
 get_expiration (int i)
 {
   struct GNUNET_TIME_Absolute av;

Modified: gnunet/src/include/gnunet_time_lib.h
===================================================================
--- gnunet/src/include/gnunet_time_lib.h        2009-07-16 22:31:33 UTC (rev 
8720)
+++ gnunet/src/include/gnunet_time_lib.h        2009-07-17 10:36:53 UTC (rev 
8721)
@@ -136,6 +136,17 @@
                                                               rel);
 
 /**
+ * Return the minimum of two relative time values.
+ *
+ * @return timestamp that is smaller
+ */
+struct GNUNET_TIME_Relative GNUNET_TIME_relative_min (struct
+                                                     GNUNET_TIME_Relative
+                                                     t1,
+                                                     struct
+                                                     GNUNET_TIME_Relative t2);
+
+/**
  * Given a timestamp in the future, how much time
  * remains until then?
  *

Modified: gnunet/src/util/time.c
===================================================================
--- gnunet/src/util/time.c      2009-07-16 22:31:33 UTC (rev 8720)
+++ gnunet/src/util/time.c      2009-07-17 10:36:53 UTC (rev 8721)
@@ -107,7 +107,22 @@
   return ret;
 }
 
+
 /**
+ * Return the minimum of two relative time values.
+ *
+ * @return timestamp that is smaller
+ */
+struct GNUNET_TIME_Relative GNUNET_TIME_relative_min (struct
+                                                     GNUNET_TIME_Relative
+                                                     t1,
+                                                     struct
+                                                     GNUNET_TIME_Relative t2)
+{
+  return (t1.value < t2.value) ? t1 : t2;
+}
+
+/**
  * Given a timestamp in the future, how much time
  * remains until then?
  *





reply via email to

[Prev in Thread] Current Thread [Next in Thread]