Commit 600b117b authored by zkasheff's avatar zkasheff

refs #36, have the FIFO realloc its buffer on resize, as opposed to malloc and memcpy

parent cf1f872d
...@@ -168,17 +168,9 @@ int toku_fifo_enq(FIFO fifo, const void *key, unsigned int keylen, const void *d ...@@ -168,17 +168,9 @@ int toku_fifo_enq(FIFO fifo, const void *key, unsigned int keylen, const void *d
if (need_space_total > fifo->memory_size) { if (need_space_total > fifo->memory_size) {
// Out of memory at the end. // Out of memory at the end.
int next_2 = next_power_of_two(need_space_total); int next_2 = next_power_of_two(need_space_total);
if ((2*next_2 > fifo->memory_size) // resize the fifo
|| (8*next_2 < fifo->memory_size)) { XREALLOC_N(next_2, fifo->memory);
// resize the fifo fifo->memory_size = next_2;
char *XMALLOC_N(next_2, newmem);
char *oldmem = fifo->memory;
if (newmem==0) return ENOMEM;
memcpy(newmem, oldmem, fifo->memory_used);
fifo->memory_size = next_2;
fifo->memory = newmem;
toku_free(oldmem);
}
} }
struct fifo_entry *entry = (struct fifo_entry *)(fifo->memory + fifo->memory_used); struct fifo_entry *entry = (struct fifo_entry *)(fifo->memory + fifo->memory_used);
fifo_entry_set_msg_type(entry, type); fifo_entry_set_msg_type(entry, type);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment