diff options
author | Andy Wingo <wingo@pobox.com> | 2009-11-08 11:29:48 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2009-11-26 00:25:07 +0100 |
commit | 2c38adf863f3aa378d1d37d907d493bc76204c47 (patch) | |
tree | 5d0ab91a5bdf98d888c5ff0d8c24948f26377568 | |
parent | 51f66c912078a25ab0380c8fc070abb73d178d98 (diff) | |
download | guile-2c38adf863f3aa378d1d37d907d493bc76204c47.tar.gz |
remove locking in method memoization
* libguile/goops.c (scm_memoize_method): Don't lock around method
memoization, as the new protocol will be reeentrant and lock-free.
-rw-r--r-- | libguile/goops.c | 42 |
1 files changed, 4 insertions, 38 deletions
diff --git a/libguile/goops.c b/libguile/goops.c index d9e0525fe..5984b6d13 100644 --- a/libguile/goops.c +++ b/libguile/goops.c @@ -2222,51 +2222,17 @@ scm_sys_compute_applicable_methods (SCM gf, SCM args) SCM_SYMBOL (sym_compute_applicable_methods, "compute-applicable-methods"); SCM_VARIABLE_INIT (var_compute_applicable_methods, "compute-applicable-methods", scm_c_define_gsubr (s_sys_compute_applicable_methods, 2, 0, 0, scm_sys_compute_applicable_methods)); -static void -lock_cache_mutex (void *m) -{ - SCM mutex = SCM_PACK ((scm_t_bits) m); - scm_lock_mutex (mutex); -} - -static void -unlock_cache_mutex (void *m) -{ - SCM mutex = SCM_PACK ((scm_t_bits) m); - scm_unlock_mutex (mutex); -} - -static SCM -call_memoize_method (void *a) +SCM +scm_memoize_method (SCM cache, SCM args) { - SCM args = SCM_PACK ((scm_t_bits) a); - SCM gf = SCM_CAR (args); - SCM x = SCM_CADR (args); - /* First check if another thread has inserted a method between - * the cache miss and locking the mutex. - */ - SCM cmethod = scm_mcache_lookup_cmethod (x, SCM_CDDR (args)); - if (scm_is_true (cmethod)) - return cmethod; + SCM gf = SCM_CAR (scm_last_pair (cache)); if (SCM_UNLIKELY (scm_is_false (var_memoize_method_x))) var_memoize_method_x = scm_permanent_object (scm_module_variable (scm_module_goops, sym_memoize_method_x)); - return scm_call_3 (SCM_VARIABLE_REF (var_memoize_method_x), gf, SCM_CDDR (args), x); -} - -SCM -scm_memoize_method (SCM x, SCM args) -{ - SCM gf = SCM_CAR (scm_last_pair (x)); - return scm_internal_dynamic_wind ( - lock_cache_mutex, - call_memoize_method, - unlock_cache_mutex, - (void *) SCM_UNPACK (scm_cons2 (gf, x, args)), - (void *) SCM_UNPACK (SCM_SLOT (gf, scm_si_cache_mutex))); + return scm_call_3 (SCM_VARIABLE_REF (var_memoize_method_x), gf, args, cache); } /****************************************************************************** |