]> git.lizzy.rs Git - dragonstd.git/blobdiff - test/test_refcount_map.c
Use proper format for size_t printf
[dragonstd.git] / test / test_refcount_map.c
index 642f15b6bd799eb2f8de73db17ad80e2b765cb0b..6a8c03998220d06cda367bc4c49e3286fd0435b1 100644 (file)
@@ -16,41 +16,31 @@ typedef struct {
        Refcount rc;
 } DataObject;
 
-void *data_object_delete(DataObject *obj)
-{
-       refcount_dst(&obj->rc);
-       free(obj);
-       return obj;
-}
-
 int rand_id()
 {
        return rand() % 1000;
 }
 
-int data_object_compare(const void *pa, const void *pb)
+void delete_obj(DataObject *obj)
 {
-       return
-               ((DataObject *) ((const Refcount *) pa)->obj)->id -
-               ((DataObject *) ((const Refcount *) pb)->obj)->id;
+       refcount_dst(&obj->rc);
+       free(obj);
 }
 
-int data_object_compare_id(const void *pa, const void *pb)
+int cmp_obj(const Refcount *rc, const int *id)
 {
-       return
-               ((DataObject *) ((const Refcount *) pa)->obj)->id -
-               *(const int *) pb;
+       return ((DataObject *) rc->obj)->id - *id;
 }
 
 static void *thread_create(unsigned int *result)
 {
-       while (! cancel) {
+       while (!cancel) {
                DataObject *obj = malloc(sizeof *obj);
                obj->id = rand_id();
 
-               refcount_ini(&obj->rc, obj, (void *) &data_object_delete);
+               refcount_ini(&obj->rc, obj, &delete_obj);
 
-               if (map_add(&map, &obj->rc, &data_object_compare, &refcount_inc) == &obj->rc)
+               if (map_add(&map, &obj->id, &obj->rc, &cmp_obj, &refcount_inc))
                        (*result)++;
 
                refcount_drp(&obj->rc);
@@ -65,7 +55,7 @@ static void *thread_access(unsigned int *result)
 {
        DataObject *objs[NUM_OBJS] = {NULL};
 
-       while (! cancel) {
+       while (!cancel) {
                int i = rand() % NUM_OBJS;
 
                if (objs[i]) {
@@ -73,9 +63,9 @@ static void *thread_access(unsigned int *result)
                        objs[i] = NULL;
                }
 
-               while (! objs[i] && ! cancel) {
+               while (!objs[i] && !cancel) {
                        int id = rand_id();
-                       objs[i] = map_get(&map, &id, &data_object_compare_id, &refcount_grb);
+                       objs[i] = map_get(&map, &id, &cmp_obj, &refcount_grb);
                }
 
                if (objs[i])
@@ -93,10 +83,10 @@ static void *thread_access(unsigned int *result)
 
 static void *thread_delete(unsigned int *result)
 {
-       while (! cancel) {
+       while (!cancel) {
                unsigned int id = rand_id();
 
-               if (map_del(&map, &id, &data_object_compare_id, &refcount_drp))
+               if (map_del(&map, &id, &cmp_obj, &refcount_drp, NULL, NULL))
                        (*result)++;
        }
 
@@ -137,7 +127,7 @@ int main()
                                results[i][0] += results[i][j];
                }
 
-       map_cnl(&map, (void *) &refcount_drp, NULL, NULL, 0);
+       map_cnl(&map, &refcount_drp, NULL, NULL, 0);
        map_dst(&map);
 
        printf("Time: 1 second\n");