From 0bc0dcf5237324d58c83d021b279533ee2e3172b Mon Sep 17 00:00:00 2001 From: Juan Jose Garcia Ripoll Date: Sun, 29 Jul 2012 22:03:32 +0200 Subject: [PATCH] Remove statements that attempted at prioritizing the waiting queue and a bogus optimization that layed outside the appropriate locks --- src/c/threads/mutex.d | 2 +- src/c/threads/queue.d | 35 ++++++++++++++--------------------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/c/threads/mutex.d b/src/c/threads/mutex.d index b7212f8b0..3452bc894 100755 --- a/src/c/threads/mutex.d +++ b/src/c/threads/mutex.d @@ -165,7 +165,7 @@ mp_get_lock_wait(cl_object lock) unlikely_if (ecl_t_of(lock) != t_lock) { FEerror_not_a_lock(lock); } - if (lock->lock.queue_list != ECL_NIL || get_lock_inner(env, lock) == ECL_NIL) { + if (get_lock_inner(env, lock) == ECL_NIL) { ecl_wait_on(env, get_lock_inner, lock); } @(return ECL_T) diff --git a/src/c/threads/queue.d b/src/c/threads/queue.d index 41cd035ff..434e65934 100755 --- a/src/c/threads/queue.d +++ b/src/c/threads/queue.d @@ -167,15 +167,14 @@ ecl_wait_on_timed(cl_env_ptr env, cl_object (*condition)(cl_env_ptr, cl_object), * function is invoked. We must thus spin over short * intervals of time to ensure that we check the * condition periodically. */ - do { + while (Null(output = condition(the_env, o))) { ecl_musleep(waiting_time(iteration++, &start), 1); - } while (Null(output = condition(the_env, o))); + } ecl_bds_unwind1(the_env); } ECL_UNWIND_PROTECT_EXIT { /* 4) At this point we wrap up. We remove ourselves * from the queue and unblock the lisp interrupt * signal. Note that we recover the cons for later use.*/ - cl_object firstone = o->queue.list; wait_queue_delete(the_env, o, own_process); own_process->process.waiting_for = ECL_NIL; own_process->process.queue_record = record; @@ -188,7 +187,7 @@ ecl_wait_on_timed(cl_env_ptr env, cl_object (*condition)(cl_env_ptr, cl_object), * condition. This is needed for objects, such as * semaphores, where the condition may be satisfied * more than once. */ - if (/*Null(output) &&*/ (firstone == record)) { + if (Null(output)) { ecl_wakeup_waiters(the_env, o, ECL_WAKEUP_ONE); } } ECL_UNWIND_PROTECT_END; @@ -262,20 +261,16 @@ ecl_wait_on(cl_env_ptr env, cl_object (*condition)(cl_env_ptr, cl_object), cl_ob * might have missed a wakeup event if that happened * between 0) and 2), which is why we start with the * check*/ - if (/*(o->queue.list != record && o->d.t != t_condition_variable) ||*/ - Null(output = condition(the_env, o))) + while (Null(output = condition(the_env, o))) { - print_lock("suspending %p", o, o); - do { - /* This will wait until we get a signal that - * demands some code being executed. Note that - * this includes our communication signals and - * the signals used by the GC. Note also that - * as a consequence we might throw / return - * which is why need to protect it all with - * UNWIND-PROTECT. */ - sigsuspend(&original); - } while (Null(output = condition(the_env, o))); + /* This will wait until we get a signal that + * demands some code being executed. Note that + * this includes our communication signals and + * the signals used by the GC. Note also that + * as a consequence we might throw / return + * which is why need to protect it all with + * UNWIND-PROTECT. */ + sigsuspend(&original); } } ECL_UNWIND_PROTECT_EXIT { /* 4) At this point we wrap up. We remove ourselves @@ -294,7 +289,7 @@ ecl_wait_on(cl_env_ptr env, cl_object (*condition)(cl_env_ptr, cl_object), cl_ob * condition. This is needed for objects, such as * semaphores, where the condition may be satisfied * more than once. */ - if (/*Null(output) &&*/ (firstone == record)) { + if (Null(output)) { ecl_wakeup_waiters(the_env, o, ECL_WAKEUP_ONE); } @@ -311,11 +306,9 @@ ecl_wait_on(cl_env_ptr env, cl_object (*condition)(cl_env_ptr, cl_object), cl_ob void ecl_wakeup_waiters(cl_env_ptr the_env, cl_object q, int flags) { - if (Null(q->queue.list)) - return; ecl_disable_interrupts_env(the_env); ecl_get_spinlock(the_env, &q->queue.spinlock); - { + if (q->queue.list != ECL_NIL) { /* We scan the list of waiting processes, awaking one * or more, depending on flags. In running through the list * we eliminate zombie processes --- they should not be here