clang-format changed files

pull/2383/head
Vijay Pai 10 years ago
parent d6cc1814c0
commit d54c3e6b39
  1. 10
      src/core/support/stack_lockfree.c
  2. 2
      src/core/support/stack_lockfree.h
  3. 28
      test/core/support/stack_lockfree_test.c

@ -65,7 +65,8 @@ typedef union lockfree_node {
} lockfree_node;
#define ENTRY_ALIGNMENT_BITS 3 /* make sure that entries aligned to 8-bytes */
#define INVALID_ENTRY_INDEX ((1<<16)-1) /* reserve this entry as invalid */
#define INVALID_ENTRY_INDEX ((1 << 16) - 1) /* reserve this entry as invalid \
*/
struct gpr_stack_lockfree {
lockfree_node *entries;
@ -109,8 +110,7 @@ void gpr_stack_lockfree_push(gpr_stack_lockfree *stack, int entry) {
head.atm = gpr_atm_no_barrier_load(&(stack->head.atm));
/* Point to it */
stack->entries[entry].contents.index = head.contents.index;
} while (!gpr_atm_rel_cas(&(stack->head.atm),
head.atm, newhead.atm));
} while (!gpr_atm_rel_cas(&(stack->head.atm), head.atm, newhead.atm));
/* Use rel_cas above to make sure that entry index is set properly */
}
@ -125,8 +125,6 @@ int gpr_stack_lockfree_pop(gpr_stack_lockfree *stack) {
newhead.atm =
gpr_atm_no_barrier_load(&(stack->entries[head.contents.index].atm));
} while (!gpr_atm_no_barrier_cas(&(stack->head.atm),
head.atm,
newhead.atm));
} while (!gpr_atm_no_barrier_cas(&(stack->head.atm), head.atm, newhead.atm));
return head.contents.index;
}

@ -38,7 +38,7 @@ typedef struct gpr_stack_lockfree gpr_stack_lockfree;
/* This stack must specify the maximum number of entries to track.
The current implementation only allows up to 65534 entries */
gpr_stack_lockfree *gpr_stack_lockfree_create(int entries);
gpr_stack_lockfree* gpr_stack_lockfree_create(int entries);
void gpr_stack_lockfree_destroy(gpr_stack_lockfree* stack);
/* Pass in a valid entry number for the next stack entry */

@ -59,13 +59,13 @@ static void test_serial_sized(int size) {
GPR_ASSERT(gpr_stack_lockfree_pop(stack) == -1);
/* Now add repeatedly more items and check them */
for (i=1; i<size; i*=2) {
for (i = 1; i < size; i *= 2) {
int j;
for (j=0; j<=i; j++) {
for (j = 0; j <= i; j++) {
gpr_stack_lockfree_push(stack, j);
}
for (j=0; j<=i; j++) {
GPR_ASSERT(gpr_stack_lockfree_pop(stack) == i-j);
for (j = 0; j <= i; j++) {
GPR_ASSERT(gpr_stack_lockfree_pop(stack) == i - j);
}
GPR_ASSERT(gpr_stack_lockfree_pop(stack) == -1);
}
@ -75,7 +75,7 @@ static void test_serial_sized(int size) {
static void test_serial() {
int i;
for (i=128; i<MAX_STACK_SIZE; i*=2) {
for (i = 128; i < MAX_STACK_SIZE; i *= 2) {
test_serial_sized(i);
}
test_serial_sized(MAX_STACK_SIZE);
@ -94,9 +94,9 @@ static void test_mt_body(void *v) {
int lo, hi;
int i;
int res;
lo = arg->rank*arg->stack_size/arg->nthreads;
hi = (arg->rank+1)*arg->stack_size/arg->nthreads;
for (i=lo; i<hi; i++) {
lo = arg->rank * arg->stack_size / arg->nthreads;
hi = (arg->rank + 1) * arg->stack_size / arg->nthreads;
for (i = lo; i < hi; i++) {
gpr_stack_lockfree_push(arg->stack, i);
if ((res = gpr_stack_lockfree_pop(arg->stack)) != -1) {
arg->sum += res;
@ -116,7 +116,7 @@ static void test_mt_sized(int size, int nth) {
gpr_thd_options options = gpr_thd_options_default();
stack = gpr_stack_lockfree_create(size);
for (i=0; i<nth; i++) {
for (i = 0; i < nth; i++) {
args[i].stack = stack;
args[i].stack_size = size;
args[i].nthreads = nth;
@ -132,17 +132,17 @@ static void test_mt_sized(int size, int nth) {
gpr_thd_join(thds[i]);
sum = sum + args[i].sum;
}
GPR_ASSERT((unsigned)sum == ((unsigned)size*(size-1))/2);
GPR_ASSERT((unsigned)sum == ((unsigned)size * (size - 1)) / 2);
gpr_stack_lockfree_destroy(stack);
}
static void test_mt() {
int size, nth;
for (nth=1; nth < MAX_THREADS; nth++) {
for (size=128; size < MAX_STACK_SIZE; size*=2) {
test_mt_sized(size,nth);
for (nth = 1; nth < MAX_THREADS; nth++) {
for (size = 128; size < MAX_STACK_SIZE; size *= 2) {
test_mt_sized(size, nth);
}
test_mt_sized(MAX_STACK_SIZE,nth);
test_mt_sized(MAX_STACK_SIZE, nth);
}
}

Loading…
Cancel
Save