diff --git a/src/c/threads/condition_variable.d b/src/c/threads/condition_variable.d index f9b81c746..9de49dc08 100644 --- a/src/c/threads/condition_variable.d +++ b/src/c/threads/condition_variable.d @@ -24,7 +24,8 @@ cl_object mp_make_condition_variable(void) { cl_object output = ecl_alloc_object(t_condition_variable); - ecl_make_atomic_queue(output); + output->condition_variable.queue_list = Cnil; + output->condition_variable.queue_spinlock = Cnil; output->condition_variable.lock = Cnil; @(return output) } diff --git a/src/c/threads/mutex.d b/src/c/threads/mutex.d index 601f51b48..987c69d6c 100644 --- a/src/c/threads/mutex.d +++ b/src/c/threads/mutex.d @@ -49,7 +49,8 @@ ecl_make_lock(cl_object name, bool recursive) output->lock.owner = Cnil; output->lock.counter = 0; output->lock.recursive = recursive; - ecl_make_atomic_queue(output); + output->lock.queue_list = Cnil; + output->lock.queue_spinlock = Cnil; return output; } @@ -155,7 +156,7 @@ mp_get_lock_nowait(cl_object lock) cl_object mp_get_lock_wait(cl_object lock) { - if (ecl_atomic_queue_list(lock) != Cnil || + if (lock->lock.queue_list != Cnil || mp_get_lock_nowait(lock) == Cnil) { ecl_wait_on(get_lock_inner, lock); } diff --git a/src/c/threads/queue.d b/src/c/threads/queue.d index ddd5c1006..c4471f72c 100644 --- a/src/c/threads/queue.d +++ b/src/c/threads/queue.d @@ -47,15 +47,8 @@ ecl_giveup_spinlock(cl_object *lock) *lock = Cnil; } -void -ecl_make_atomic_queue(cl_object q) -{ - q->queue.list = Cnil; - q->queue.spinlock = Cnil; -} - static ECL_INLINE void -ecl_atomic_queue_nconc(cl_env_ptr the_env, cl_object q, cl_object new_tail) +wait_queue_nconc(cl_env_ptr the_env, cl_object q, cl_object new_tail) { ecl_get_spinlock(the_env, &q->queue.spinlock); q->queue.list = ecl_nconc(q->queue.list, new_tail); @@ -63,7 +56,7 @@ ecl_atomic_queue_nconc(cl_env_ptr the_env, cl_object q, cl_object new_tail) } static ECL_INLINE cl_object -ecl_atomic_queue_pop_all(cl_env_ptr the_env, cl_object q) +wait_queue_pop_all(cl_env_ptr the_env, cl_object q) { cl_object output; ecl_disable_interrupts_env(the_env); @@ -78,7 +71,7 @@ ecl_atomic_queue_pop_all(cl_env_ptr the_env, cl_object q) } static ECL_INLINE void -ecl_atomic_queue_delete(cl_env_ptr the_env, cl_object q, cl_object item) +wait_queue_delete(cl_env_ptr the_env, cl_object q, cl_object item) { ecl_get_spinlock(the_env, &q->queue.spinlock); q->queue.list = ecl_delete_eq(item, q->queue.list); @@ -115,7 +108,7 @@ ecl_wait_on(cl_object (*condition)(cl_env_ptr, cl_object), cl_object o) /* 2) Now we add ourselves to the queue. In order to avoid a * call to the GC, we try to reuse records. */ - ecl_atomic_queue_nconc(the_env, o, record); + wait_queue_nconc(the_env, o, record); own_process->process.waiting_for = o; CL_UNWIND_PROTECT_BEGIN(the_env) { @@ -141,7 +134,7 @@ ecl_wait_on(cl_object (*condition)(cl_env_ptr, cl_object), cl_object o) /* 4) At this point we wrap up. We remove ourselves from the queue and restore signals, which were */ own_process->process.waiting_for = Cnil; - ecl_atomic_queue_delete(the_env, o, own_process); + wait_queue_delete(the_env, o, own_process); own_process->process.queue_record = record; ECL_RPLACD(record, Cnil); pthread_sigmask(SIG_SETMASK, NULL, &original); @@ -160,7 +153,7 @@ wakeup_this(cl_object p, int flags) static void wakeup_all(cl_env_ptr the_env, cl_object q, int flags) { - cl_object queue = ecl_atomic_queue_pop_all(the_env, q); + cl_object queue = wait_queue_pop_all(the_env, q); queue = cl_nreverse(queue); while (!Null(queue)) { cl_object process = ECL_CONS_CAR(queue); diff --git a/src/h/internal.h b/src/h/internal.h index cd14e0ace..2f5782cb7 100644 --- a/src/h/internal.h +++ b/src/h/internal.h @@ -467,9 +467,6 @@ extern void print_lock(char *s, cl_object lock, ...); extern void ecl_get_spinlock(cl_env_ptr env, cl_object *lock); extern void ecl_giveup_spinlock(cl_object *lock); -extern void ecl_make_atomic_queue(cl_object); -#define ecl_atomic_queue_list(queue) ((queue)->lock.queue_list) - extern void ecl_wait_on(cl_object (*condition)(cl_env_ptr, cl_object), cl_object o); extern void ecl_wakeup_waiters(cl_env_ptr the_env, cl_object o, bool all); #endif