]> pd.if.org Git - nbds/blobdiff - test/ll_test.c
generic interface for map-like data structures
[nbds] / test / ll_test.c
index e7c9337d4f7c02f7c402474209d4c46059ff1790..490bf7d1393afec8e115a6721d50fdce0f554fda 100644 (file)
@@ -5,13 +5,13 @@
 
 #include "common.h"
 #include "runtime.h"
-#include "struct.h"
+#include "map.h"
 
 #define NUM_ITERATIONS 10000000
 
 static volatile int wait_;
 static long num_threads_;
-static list_t *ll_;
+static map_t *map_;
 
 void *worker (void *arg) {
 
@@ -21,12 +21,22 @@ void *worker (void *arg) {
 
     for (int i = 0; i < NUM_ITERATIONS/num_threads_; ++i) {
         unsigned r = nbd_rand();
-        int key = r & 0xF;
+        uint64_t key = r & 0xF;
+#if 1
+        char key_str[10];
+        sprintf(key_str, "%llX", key);
         if (r & (1 << 8)) {
-            ll_add(ll_, key, 1);
+            map_set(map_, key_str, strlen(key_str) + 1, 1);
         } else {
-            ll_remove(ll_, key);
+            map_remove(map_, key_str, strlen(key_str) + 1);
         }
+#else
+        if (r & (1 << 8)) {
+            map_set(map_, (void *)key, -1, 1);
+        } else {
+            map_remove(map_, (void *)key, -1);
+        }
+#endif
 
         rcu_update();
     }
@@ -36,7 +46,7 @@ void *worker (void *arg) {
 
 int main (int argc, char **argv) {
     nbd_init();
-    //lwt_set_trace_level("m0l0");
+    //lwt_set_trace_level("l3");
 
     char* program_name = argv[0];
     pthread_t thread[MAX_NUM_THREADS];
@@ -65,7 +75,7 @@ int main (int argc, char **argv) {
         }
     }
 
-    ll_ = ll_alloc();
+    map_ = map_alloc(MAP_TYPE_LIST);
 
     struct timeval tv1, tv2;
     gettimeofday(&tv1, NULL);
@@ -83,7 +93,7 @@ int main (int argc, char **argv) {
 
     gettimeofday(&tv2, NULL);
     int ms = (int)(1000000*(tv2.tv_sec - tv1.tv_sec) + tv2.tv_usec - tv1.tv_usec) / 1000;
-    ll_print(ll_);
+    map_print(map_);
     printf("Th:%ld Time:%dms\n", num_threads_, ms);
 
     return 0;