Skip to content

Commit

Permalink
Code formating only, for the LF_HASH.
Browse files Browse the repository at this point in the history
Added brackets even to single statement blocks,
applied clang-format.

Brackets for blocks helps with GCOV coverage reports.
  • Loading branch information
marcalff committed Mar 22, 2018
1 parent 603614b commit 6514d5c
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 68 deletions.
8 changes: 5 additions & 3 deletions include/lf.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
/* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
Expand Down Expand Up @@ -86,7 +86,7 @@ struct LF_PINS {
void *purgatory;
uint32 purgatory_count;
std::atomic<uint32> link;
/* we want sizeof(LF_PINS) to be 64 to avoid false sharing */
/* we want sizeof(LF_PINS) to be 64 to avoid false sharing */
#if SIZEOF_INT * 2 + SIZEOF_CHARP * (LF_PINBOX_PINS + 2) != 64
char pad[64 - sizeof(uint32) * 2 - sizeof(void *) * (LF_PINBOX_PINS + 2)];
#endif
Expand Down Expand Up @@ -147,7 +147,9 @@ void lf_alloc_destroy(LF_ALLOCATOR *allocator);
uint lf_alloc_pool_count(LF_ALLOCATOR *allocator);

static inline void lf_alloc_direct_free(LF_ALLOCATOR *allocator, void *addr) {
if (allocator->destructor) allocator->destructor((uchar *)addr);
if (allocator->destructor) {
allocator->destructor((uchar *)addr);
}
my_free(addr);
}

Expand Down
44 changes: 32 additions & 12 deletions mysys/lf_alloc-pin.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* QQ: TODO multi-pinbox */
/* Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
/* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
Expand Down Expand Up @@ -178,13 +178,17 @@ LF_PINS *lf_pinbox_get_pins(LF_PINBOX *pinbox) {
if (!(pins = top_ver % LF_PINBOX_MAX_PINS)) {
/* the stack of free elements is empty */
pins = pinbox->pins_in_array.fetch_add(1) + 1;
if (unlikely(pins >= LF_PINBOX_MAX_PINS)) return 0;
if (unlikely(pins >= LF_PINBOX_MAX_PINS)) {
return 0;
}
/*
note that the first allocated element has index 1 (pins==1).
index 0 is reserved to mean "NULL pointer"
*/
el = (LF_PINS *)lf_dynarray_lvalue(&pinbox->pinarray, pins);
if (unlikely(!el)) return 0;
if (unlikely(!el)) {
return 0;
}
break;
}
el = (LF_PINS *)lf_dynarray_value(&pinbox->pinarray, pins);
Expand Down Expand Up @@ -219,7 +223,9 @@ void lf_pinbox_put_pins(LF_PINS *pins) {
{
/* This thread should not hold any pin. */
int i;
for (i = 0; i < LF_PINBOX_PINS; i++) DBUG_ASSERT(pins->pin[i] == 0);
for (i = 0; i < LF_PINBOX_PINS; i++) {
DBUG_ASSERT(pins->pin[i] == 0);
}
}
#endif /* DBUG_OFF */

Expand Down Expand Up @@ -264,7 +270,9 @@ static inline void add_to_purgatory(LF_PINS *pins, void *addr) {
*/
void lf_pinbox_free(LF_PINS *pins, void *addr) {
add_to_purgatory(pins, addr);
if (pins->purgatory_count % LF_PURGATORY_SIZE == 0) lf_pinbox_real_free(pins);
if (pins->purgatory_count % LF_PURGATORY_SIZE == 0) {
lf_pinbox_real_free(pins);
}
}

struct st_match_and_save_arg {
Expand Down Expand Up @@ -297,11 +305,14 @@ static int match_and_save(LF_PINS *el, struct st_match_and_save_arg *arg) {
add_to_purgatory(arg->pins, cur);
/* unlink from old purgatory */
*list_prev = next;
} else
} else {
list_prev = (void **)((char *)cur + arg->pinbox->free_ptr_offset);
}
cur = next;
}
if (!arg->old_purgatory) return 1;
if (!arg->old_purgatory) {
return 1;
}
}
}
}
Expand All @@ -326,7 +337,9 @@ static void lf_pinbox_real_free(LF_PINS *pins) {
if (arg.old_purgatory) {
/* Some objects in the old purgatory were not pinned, free them. */
void *last = arg.old_purgatory;
while (pnext_node(pinbox, last)) last = pnext_node(pinbox, last);
while (pnext_node(pinbox, last)) {
last = pnext_node(pinbox, last);
}
pinbox->free_func(arg.old_purgatory, last, pinbox->free_func_arg);
}
}
Expand Down Expand Up @@ -402,7 +415,9 @@ void lf_alloc_destroy(LF_ALLOCATOR *allocator) {
uchar *node = allocator->top;
while (node) {
uchar *tmp = anext_node(node);
if (allocator->destructor) allocator->destructor(node);
if (allocator->destructor) {
allocator->destructor(node);
}
my_free(node);
node = tmp;
}
Expand All @@ -428,15 +443,20 @@ void *lf_alloc_new(LF_PINS *pins) {
if (!node) {
node = static_cast<uchar *>(
my_malloc(key_memory_lf_node, allocator->element_size, MYF(MY_WME)));
if (allocator->constructor) allocator->constructor(node);
if (allocator->constructor) {
allocator->constructor(node);
}
#ifdef MY_LF_EXTRA_DEBUG
if (likely(node != 0)) ++allocator->mallocs;
if (likely(node != 0)) {
++allocator->mallocs;
}
#endif
break;
}
if (atomic_compare_exchange_strong(&allocator->top, &node,
anext_node(node).load()))
anext_node(node).load())) {
break;
}
}
lf_unpin(pins, 0);
return node;
Expand Down
58 changes: 40 additions & 18 deletions mysys/lf_dynarray.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
/* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
Expand Down Expand Up @@ -67,16 +67,19 @@ void lf_dynarray_init(LF_DYNARRAY *array, uint element_size) {
}

static void recursive_free(std::atomic<void *> *alloc, int level) {
if (!alloc) return;
if (!alloc) {
return;
}

if (level) {
int i;
for (i = 0; i < LF_DYNARRAY_LEVEL_LENGTH; i++)
recursive_free(static_cast<std::atomic<void *> *>(alloc[i].load()),
level - 1);
my_free(alloc);
} else
} else {
my_free(alloc[-1]);
}
}

void lf_dynarray_destroy(LF_DYNARRAY *array) {
Expand Down Expand Up @@ -121,11 +124,14 @@ void *lf_dynarray_lvalue(LF_DYNARRAY *array, uint idx) {
void *alloc = my_malloc(key_memory_lf_dynarray,
LF_DYNARRAY_LEVEL_LENGTH * sizeof(void *),
MYF(MY_WME | MY_ZEROFILL));
if (unlikely(!alloc)) return (NULL);
if (atomic_compare_exchange_strong(ptr_ptr, &ptr, alloc))
if (unlikely(!alloc)) {
return (NULL);
}
if (atomic_compare_exchange_strong(ptr_ptr, &ptr, alloc)) {
ptr = alloc;
else
} else {
my_free(alloc);
}
}
ptr_ptr =
((std::atomic<void *> *)ptr) + idx / dynarray_idxes_in_prev_level[i];
Expand All @@ -138,19 +144,25 @@ void *lf_dynarray_lvalue(LF_DYNARRAY *array, uint idx) {
LF_DYNARRAY_LEVEL_LENGTH * array->size_of_element +
MY_MAX(array->size_of_element, sizeof(void *)),
MYF(MY_WME | MY_ZEROFILL)));
if (unlikely(!alloc)) return (NULL);
if (unlikely(!alloc)) {
return (NULL);
}
/* reserve the space for free() address */
data = alloc + sizeof(void *);
{ /* alignment */
{
/* alignment */
intptr mod = ((intptr)data) % array->size_of_element;
if (mod) data += array->size_of_element - mod;
if (mod) {
data += array->size_of_element - mod;
}
}
((void **)data)[-1] = alloc; /* free() will need the original pointer */
if (atomic_compare_exchange_strong(ptr_ptr, &ptr,
static_cast<void *>(data)))
static_cast<void *>(data))) {
ptr = data;
else
} else {
my_free(alloc);
}
}
return ((uchar *)ptr) + array->size_of_element * idx;
}
Expand All @@ -168,24 +180,33 @@ void *lf_dynarray_value(LF_DYNARRAY *array, uint idx) {
std::atomic<void *> *ptr_ptr = &array->level[i];
idx -= dynarray_idxes_in_prev_levels[i];
for (; i > 0; i--) {
if (!(ptr = *ptr_ptr)) return (NULL);
if (!(ptr = *ptr_ptr)) {
return (NULL);
}
ptr_ptr =
((std::atomic<void *> *)ptr) + idx / dynarray_idxes_in_prev_level[i];
idx %= dynarray_idxes_in_prev_level[i];
}
if (!(ptr = *ptr_ptr)) return (NULL);
if (!(ptr = *ptr_ptr)) {
return (NULL);
}
return ((uchar *)ptr) + array->size_of_element * idx;
}

static int recursive_iterate(LF_DYNARRAY *array, void *ptr, int level,
lf_dynarray_func func, void *arg) {
int res, i;
if (!ptr) return 0;
if (!level) return func(ptr, arg);
if (!ptr) {
return 0;
}
if (!level) {
return func(ptr, arg);
}
for (i = 0; i < LF_DYNARRAY_LEVEL_LENGTH; i++)
if ((res =
recursive_iterate(array, ((void **)ptr)[i], level - 1, func, arg)))
if ((res = recursive_iterate(array, ((void **)ptr)[i], level - 1, func,
arg))) {
return res;
}
return 0;
}

Expand All @@ -205,7 +226,8 @@ static int recursive_iterate(LF_DYNARRAY *array, void *ptr, int level,
int lf_dynarray_iterate(LF_DYNARRAY *array, lf_dynarray_func func, void *arg) {
int i, res;
for (i = 0; i < LF_DYNARRAY_LEVELS; i++)
if ((res = recursive_iterate(array, array->level[i], i, func, arg)))
if ((res = recursive_iterate(array, array->level[i], i, func, arg))) {
return res;
}
return 0;
}
Loading

0 comments on commit 6514d5c

Please sign in to comment.