Skip to content
Snippets Groups Projects
Commit dfbb1c08 authored by Craig Tiller's avatar Craig Tiller
Browse files

Almost working......

parent 2743ba94
No related branches found
No related tags found
No related merge requests found
...@@ -67,23 +67,30 @@ static void finish(grpc_exec_ctx *exec_ctx, grpc_aelock *lock) { ...@@ -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: ...@@ -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: ...@@ -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) { ...@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment