mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-26 05:00:28 +02:00
Weak sets and tables no longer vacuum after GC
These tables will be implemented differently after Whippet. * libguile/weak-set.c (do_vacuum_weak_set, vacuum_all_weak_sets): Remove. (scm_c_make_weak_set, scm_init_weak_set): Don't keep a table of all weak sets. * libguile/weak-table.c (do_vacuum_weak_table, vacuum_all_weak_tables): Remove. (scm_c_make_weak_table, scm_init_weak_table): No table of all tables.
This commit is contained in:
parent
9774b3e551
commit
604a8e8540
2 changed files with 2 additions and 77 deletions
|
@ -1,4 +1,4 @@
|
|||
/* Copyright 2011-2013,2018
|
||||
/* Copyright 2011-2013,2018,2025
|
||||
Free Software Foundation, Inc.
|
||||
|
||||
This file is part of Guile.
|
||||
|
@ -689,32 +689,6 @@ scm_i_weak_set_print (SCM exp, SCM port, scm_print_state *pstate)
|
|||
scm_puts (">", port);
|
||||
}
|
||||
|
||||
static void
|
||||
do_vacuum_weak_set (SCM set)
|
||||
{
|
||||
scm_t_weak_set *s;
|
||||
|
||||
s = SCM_WEAK_SET (set);
|
||||
|
||||
/* We should always be able to grab this lock, because we are run from
|
||||
a finalizer, which runs in another thread (or an async, which is
|
||||
mostly equivalent). */
|
||||
scm_i_pthread_mutex_lock (&s->lock);
|
||||
vacuum_weak_set (s);
|
||||
scm_i_pthread_mutex_unlock (&s->lock);
|
||||
}
|
||||
|
||||
static scm_i_pthread_mutex_t all_weak_sets_lock = SCM_I_PTHREAD_MUTEX_INITIALIZER;
|
||||
static SCM all_weak_sets = SCM_EOL;
|
||||
|
||||
static void
|
||||
vacuum_all_weak_sets (void)
|
||||
{
|
||||
scm_i_pthread_mutex_lock (&all_weak_sets_lock);
|
||||
scm_i_visit_weak_list (&all_weak_sets, do_vacuum_weak_set);
|
||||
scm_i_pthread_mutex_unlock (&all_weak_sets_lock);
|
||||
}
|
||||
|
||||
SCM
|
||||
scm_c_make_weak_set (unsigned long k)
|
||||
{
|
||||
|
@ -722,10 +696,6 @@ scm_c_make_weak_set (unsigned long k)
|
|||
|
||||
ret = make_weak_set (k);
|
||||
|
||||
scm_i_pthread_mutex_lock (&all_weak_sets_lock);
|
||||
all_weak_sets = scm_i_weak_cons (ret, all_weak_sets);
|
||||
scm_i_pthread_mutex_unlock (&all_weak_sets_lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -902,6 +872,4 @@ void
|
|||
scm_init_weak_set ()
|
||||
{
|
||||
#include "weak-set.x"
|
||||
|
||||
scm_i_register_async_gc_callback (vacuum_all_weak_sets);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright 2011-2014,2017-2018
|
||||
/* Copyright 2011-2014,2017-2018,2025
|
||||
Free Software Foundation, Inc.
|
||||
|
||||
This file is part of Guile.
|
||||
|
@ -458,43 +458,6 @@ scm_i_weak_table_print (SCM exp, SCM port, scm_print_state *pstate)
|
|||
scm_puts (">", port);
|
||||
}
|
||||
|
||||
static void
|
||||
do_vacuum_weak_table (SCM table)
|
||||
{
|
||||
scm_t_weak_table *t;
|
||||
|
||||
t = SCM_WEAK_TABLE (table);
|
||||
|
||||
/* Unlike weak sets, the weak table interface allows custom predicates
|
||||
to call out to arbitrary Scheme. There are two ways that this code
|
||||
can be re-entrant, then: calling weak hash procedures while in a
|
||||
custom predicate, or via finalizers run explicitly by (gc) or in an
|
||||
async (for non-threaded Guile). We add a restriction that
|
||||
prohibits the first case, by convention. But since we can't
|
||||
prohibit the second case, here we trylock instead of lock. In any
|
||||
case, if the mutex is held by another thread, then the table is in
|
||||
active use, so the next user of the table will handle the vacuum
|
||||
for us. */
|
||||
if (scm_i_pthread_mutex_trylock (&t->lock) == 0)
|
||||
{
|
||||
vacuum_weak_table (t);
|
||||
scm_i_pthread_mutex_unlock (&t->lock);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static scm_i_pthread_mutex_t all_weak_tables_lock = SCM_I_PTHREAD_MUTEX_INITIALIZER;
|
||||
static SCM all_weak_tables = SCM_EOL;
|
||||
|
||||
static void
|
||||
vacuum_all_weak_tables (void)
|
||||
{
|
||||
scm_i_pthread_mutex_lock (&all_weak_tables_lock);
|
||||
scm_i_visit_weak_list (&all_weak_tables, do_vacuum_weak_table);
|
||||
scm_i_pthread_mutex_unlock (&all_weak_tables_lock);
|
||||
}
|
||||
|
||||
SCM
|
||||
scm_c_make_weak_table (unsigned long k, scm_t_weak_table_kind kind)
|
||||
{
|
||||
|
@ -502,10 +465,6 @@ scm_c_make_weak_table (unsigned long k, scm_t_weak_table_kind kind)
|
|||
|
||||
ret = make_weak_table (k, kind);
|
||||
|
||||
scm_i_pthread_mutex_lock (&all_weak_tables_lock);
|
||||
all_weak_tables = scm_i_weak_cons (ret, all_weak_tables);
|
||||
scm_i_pthread_mutex_unlock (&all_weak_tables_lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -840,6 +799,4 @@ void
|
|||
scm_init_weak_table ()
|
||||
{
|
||||
#include "weak-table.x"
|
||||
|
||||
scm_i_register_async_gc_callback (vacuum_all_weak_tables);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue