From c1f485cc31b829ce230a8955eb908b159da514b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kochma=C5=84ski?= Date: Thu, 17 Nov 2016 22:47:47 +0100 Subject: [PATCH] Simplify mp lambda lists Remove redundant keyword-name specification from make-locks recursive and remove dummy &key from barrier-wait (potentially not backward compatible with C code). --- src/c/symbols_list.h | 2 +- src/c/threads/barrier.d | 58 +++++++++++++++++++++-------------------- src/c/threads/mutex.d | 2 +- src/c/threads/process.d | 2 +- src/h/external.h | 2 +- 5 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/c/symbols_list.h b/src/c/symbols_list.h index fe3c73656..1651ab7bf 100755 --- a/src/c/symbols_list.h +++ b/src/c/symbols_list.h @@ -1603,7 +1603,7 @@ cl_symbols[] = { {MP_ "BARRIER", MP_ORDINARY, NULL, -1, OBJNULL}, {MP_ "MAKE-BARRIER", MP_ORDINARY, IF_MP(mp_make_barrier), -1, OBJNULL}, {MP_ "BARRIER-UNBLOCK", MP_ORDINARY, IF_MP(mp_barrier_unblock), -1, OBJNULL}, -{MP_ "BARRIER-WAIT", MP_ORDINARY, IF_MP(mp_barrier_wait), -1, OBJNULL}, +{MP_ "BARRIER-WAIT", MP_ORDINARY, IF_MP(mp_barrier_wait), 1, OBJNULL}, {MP_ "BARRIER-COUNT", MP_ORDINARY, IF_MP(mp_barrier_count), 1, OBJNULL}, {MP_ "BARRIER-NAME", MP_ORDINARY, IF_MP(mp_barrier_name), 1, OBJNULL}, {MP_ "BARRIER-ARRIVERS-COUNT", MP_ORDINARY, IF_MP(mp_barrier_arrivers_count), 1, OBJNULL}, diff --git a/src/c/threads/barrier.d b/src/c/threads/barrier.d index eb4053c82..9162f5505 100755 --- a/src/c/threads/barrier.d +++ b/src/c/threads/barrier.d @@ -131,34 +131,36 @@ decrement_counter(cl_fixnum *counter) } while (1); } -@(defun mp::barrier-wait (barrier &key) +cl_object +mp_barrier_wait(cl_object barrier) +{ cl_object output; cl_fixnum counter; - @ { - cl_object own_process = the_env->own_process; + cl_env_ptr the_env = ecl_process_env(); + cl_object own_process = the_env->own_process; - unlikely_if (ecl_t_of(barrier) != t_barrier) { - FEerror_not_a_barrier(barrier); - } - ecl_disable_interrupts_env(the_env); - counter = decrement_counter(&barrier->barrier.arrivers_count); - if (counter == 0) { - print_lock("barrier %p saturated", barrier, barrier); - /* There are (count-1) threads in the queue and we - * are the last one. We thus unblock all threads and - * proceed. */ - mp_barrier_unblock(1, barrier); - ecl_enable_interrupts_env(the_env); - output = @':unblocked'; - } else if (counter > 0) { - print_lock("barrier %p waiting", barrier, barrier); - ecl_enable_interrupts_env(the_env); - ecl_wait_on(the_env, barrier_wait_condition, barrier); - output = ECL_T; - } else { - print_lock("barrier %p pass-through", barrier, barrier); - /* Barrier disabled */ - output = ECL_NIL; - } - @(return output); - } @) + unlikely_if (ecl_t_of(barrier) != t_barrier) { + FEerror_not_a_barrier(barrier); + } + ecl_disable_interrupts_env(the_env); + counter = decrement_counter(&barrier->barrier.arrivers_count); + if (counter == 0) { + print_lock("barrier %p saturated", barrier, barrier); + /* There are (count-1) threads in the queue and we + * are the last one. We thus unblock all threads and + * proceed. */ + mp_barrier_unblock(1, barrier); + ecl_enable_interrupts_env(the_env); + output = @':unblocked'; + } else if (counter > 0) { + print_lock("barrier %p waiting", barrier, barrier); + ecl_enable_interrupts_env(the_env); + ecl_wait_on(the_env, barrier_wait_condition, barrier); + output = ECL_T; + } else { + print_lock("barrier %p pass-through", barrier, barrier); + /* Barrier disabled */ + output = ECL_NIL; + } + return output; +} diff --git a/src/c/threads/mutex.d b/src/c/threads/mutex.d index c6899d023..eb40358c3 100755 --- a/src/c/threads/mutex.d +++ b/src/c/threads/mutex.d @@ -53,7 +53,7 @@ ecl_make_lock(cl_object name, bool recursive) return output; } -@(defun mp::make-lock (&key name ((:recursive recursive) ECL_NIL)) +@(defun mp::make-lock (&key name (recursive ECL_NIL)) @ @(return ecl_make_lock(name, !Null(recursive))); @) diff --git a/src/c/threads/process.d b/src/c/threads/process.d index 944bd1607..df92d835a 100755 --- a/src/c/threads/process.d +++ b/src/c/threads/process.d @@ -628,7 +628,7 @@ mp_process_join(cl_object process) if (process->process.phase) { /* We try to acquire a lock that is only owned by the process * while it is active. */ - mp_barrier_wait(1, process->process.exit_barrier); + mp_barrier_wait(process->process.exit_barrier); } return cl_values_list(process->process.exit_values); } diff --git a/src/h/external.h b/src/h/external.h index 8ef216075..90c499959 100755 --- a/src/h/external.h +++ b/src/h/external.h @@ -1749,7 +1749,7 @@ extern ECL_API cl_object mp_make_barrier _ECL_ARGS((cl_narg, cl_object, ...)); extern ECL_API cl_object mp_barrier_count(cl_object); extern ECL_API cl_object mp_barrier_name(cl_object); extern ECL_API cl_object mp_barrier_arrivers_count(cl_object); -extern ECL_API cl_object mp_barrier_wait _ECL_ARGS((cl_narg, cl_object, ...)); +extern ECL_API cl_object mp_barrier_wait (cl_object); extern ECL_API cl_object mp_barrier_unblock _ECL_ARGS((cl_narg, cl_object, ...)); /* threads/mailbox.d */