Browse Source

ckdb - add klist cull to reduce a list to minimum - and cull transfer

master
kanoi 10 years ago
parent
commit
a6b40c7702
  1. 5
      src/ckdb.c
  2. 33
      src/klist.c
  3. 2
      src/klist.h

5
src/ckdb.c

@ -9685,8 +9685,11 @@ static void *socketer(__maybe_unused void *arg)
}
K_WLOCK(transfer_free);
k_list_transfer_to_head(trf_store, transfer_free);
K_WUNLOCK(transfer_free);
trf_store = k_free_store(trf_store);
if (transfer_free->count == transfer_free->total &&
transfer_free->total > ALLOC_TRANSFER * 16)
k_cull_list(transfer_free);
K_WUNLOCK(transfer_free);
}
}

33
src/klist.c

@ -378,3 +378,36 @@ K_STORE *_k_free_store(K_STORE *store, KLIST_FFL_ARGS)
return NULL;
}
// Must be locked and none in use and/or unlinked
void _k_cull_list(K_LIST *list, KLIST_FFL_ARGS)
{
int i;
if (list->is_store) {
quithere(1, "List %s can't %s() a store" KLIST_FFL,
list->name, __func__, KLIST_FFL_PASS);
}
if (list->count != list->total) {
quithere(1, "List %s can't %s() a list in use" KLIST_FFL,
list->name, __func__, KLIST_FFL_PASS);
}
for (i = 0; i < list->item_mem_count; i++)
free(list->item_memory[i]);
free(list->item_memory);
list->item_memory = NULL;
list->item_mem_count = 0;
for (i = 0; i < list->data_mem_count; i++)
free(list->data_memory[i]);
free(list->data_memory);
list->data_memory = NULL;
list->data_mem_count = 0;
list->total = list->count = list->count_up = 0;
list->head = list->tail = NULL;
k_alloc_items(list, KLIST_FFL_PASS);
}

2
src/klist.h

@ -94,5 +94,7 @@ extern K_LIST *_k_free_list(K_LIST *list, KLIST_FFL_ARGS);
#define k_free_list(_list) _k_free_list(_list, KLIST_FFL_HERE)
extern K_STORE *_k_free_store(K_STORE *store, KLIST_FFL_ARGS);
#define k_free_store(_store) _k_free_store(_store, KLIST_FFL_HERE)
extern void _k_cull_list(K_LIST *list, KLIST_FFL_ARGS);
#define k_cull_list(_list) _k_cull_list(_list, KLIST_FFL_HERE)
#endif

Loading…
Cancel
Save