Almost working......

pull/6407/head
Craig Tiller 9 years ago
parent 2743ba94f9
commit dfbb1c080a
  1. 12
      src/core/lib/iomgr/async_execution_lock.c
  2. 2
      test/core/iomgr/async_execution_lock_test.c

@ -67,23 +67,30 @@ static void finish(grpc_exec_ctx *exec_ctx, grpc_aelock *lock) {
NO_CONSUMER)) { NO_CONSUMER)) {
return; return;
} }
// TODO(ctiller): consider sleeping
continue;
} else { } else {
// skip the tombstone: we'll re-add it later
lock->tail = next; lock->tail = next;
tail = next; tail = next;
next = (grpc_aelock_qnode *)gpr_atm_acq_load(&tail->next); next = (grpc_aelock_qnode *)gpr_atm_acq_load(&tail->next);
} }
} }
if (next != NULL) { if (next != NULL) {
// found a node
lock->tail = next; lock->tail = next;
tail->action(exec_ctx, tail->arg); tail->action(exec_ctx, tail->arg);
gpr_free(tail); gpr_free(tail);
} else { } else {
// nothing there: might be in an incosistant state
grpc_aelock_qnode *head = grpc_aelock_qnode *head =
(grpc_aelock_qnode *)gpr_atm_acq_load(&lock->head); (grpc_aelock_qnode *)gpr_atm_acq_load(&lock->head);
if (head != tail) { if (head != tail) {
// non-empty list: spin for a bit
// TODO(ctiller): consider sleeping? // TODO(ctiller): consider sleeping?
continue; continue;
} }
// must have swallowed tombstone above: re-add it
gpr_atm_no_barrier_store(&lock->tombstone.next, 0); gpr_atm_no_barrier_store(&lock->tombstone.next, 0);
while (!gpr_atm_rel_cas(&lock->head, (gpr_atm)head, while (!gpr_atm_rel_cas(&lock->head, (gpr_atm)head,
(gpr_atm)&lock->tombstone)) { (gpr_atm)&lock->tombstone)) {
@ -117,7 +124,7 @@ retry_top:
} else { } else {
n->arg = arg; n->arg = arg;
} }
gpr_atm_no_barrier_store(&n->next, 0); gpr_atm_rel_store(&n->next, 0);
while (!gpr_atm_rel_cas(&lock->head, head, (gpr_atm)n)) { while (!gpr_atm_rel_cas(&lock->head, head, (gpr_atm)n)) {
retry_queue_load: retry_queue_load:
head = gpr_atm_acq_load(&lock->head); head = gpr_atm_acq_load(&lock->head);
@ -132,5 +139,6 @@ retry_top:
return; // early out return; // early out
} }
} }
gpr_atm_rel_store(&((grpc_aelock_qnode *)head)->next, (gpr_atm)n); GPR_ASSERT(gpr_atm_rel_cas(&((grpc_aelock_qnode *)head)->next, 0, (gpr_atm)n));
// gpr_atm_rel_store(&((grpc_aelock_qnode *)head)->next, (gpr_atm)n);
} }

@ -87,7 +87,7 @@ static void execute_many_loop(void *a) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
size_t n = 1; size_t n = 1;
for (size_t i = 0; i < 10; i++) { for (size_t i = 0; i < 10; i++) {
for (size_t j = 0; j < 1000; j++) { for (size_t j = 0; j < 10000; j++) {
ex_args c = {&args->ctr, n++}; ex_args c = {&args->ctr, n++};
grpc_aelock_execute(&exec_ctx, args->lock, check_one, &c, sizeof(c)); grpc_aelock_execute(&exec_ctx, args->lock, check_one, &c, sizeof(c));
grpc_exec_ctx_flush(&exec_ctx); grpc_exec_ctx_flush(&exec_ctx);

Loading…
Cancel
Save