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);
{
DataObject *objs[NUM_OBJS] = {NULL};
- while (! cancel) {
+ while (!cancel) {
int i = rand() % NUM_OBJS;
if (objs[i]) {
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])
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)++;
}
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");