mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 11:50:28 +02:00
Revert "with a threaded guile, lock weak sets and tables during a fork"
This reverts commit f609480611
.
This commit is contained in:
parent
44b76a785c
commit
81b80b9610
4 changed files with 28 additions and 194 deletions
|
@ -382,7 +382,6 @@ scm_i_init_guile (void *base)
|
||||||
|
|
||||||
scm_storage_prehistory ();
|
scm_storage_prehistory ();
|
||||||
scm_threads_prehistory (base); /* requires storage_prehistory */
|
scm_threads_prehistory (base); /* requires storage_prehistory */
|
||||||
scm_weak_set_prehistory (); /* requires storage_prehistory */
|
|
||||||
scm_weak_table_prehistory (); /* requires storage_prehistory */
|
scm_weak_table_prehistory (); /* requires storage_prehistory */
|
||||||
#ifdef GUILE_DEBUG_MALLOC
|
#ifdef GUILE_DEBUG_MALLOC
|
||||||
scm_debug_malloc_prehistory ();
|
scm_debug_malloc_prehistory ();
|
||||||
|
|
|
@ -650,74 +650,6 @@ weak_set_remove_x (scm_t_weak_set *set, unsigned long hash,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
lock_weak_set (scm_t_weak_set *set)
|
|
||||||
{
|
|
||||||
scm_i_pthread_mutex_lock (&set->lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
unlock_weak_set (scm_t_weak_set *set)
|
|
||||||
{
|
|
||||||
scm_i_pthread_mutex_unlock (&set->lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* A weak set of weak sets, for use in the pthread_atfork handler. */
|
|
||||||
static SCM all_weak_sets = SCM_BOOL_F;
|
|
||||||
|
|
||||||
#if SCM_USE_PTHREAD_THREADS
|
|
||||||
|
|
||||||
static void
|
|
||||||
lock_all_weak_sets (void)
|
|
||||||
{
|
|
||||||
scm_t_weak_set *s;
|
|
||||||
scm_t_weak_entry *entries;
|
|
||||||
unsigned long k, size;
|
|
||||||
scm_t_weak_entry copy;
|
|
||||||
|
|
||||||
s = SCM_WEAK_SET (all_weak_sets);
|
|
||||||
lock_weak_set (s);
|
|
||||||
size = s->size;
|
|
||||||
entries = s->entries;
|
|
||||||
|
|
||||||
for (k = 0; k < size; k++)
|
|
||||||
if (entries[k].hash)
|
|
||||||
{
|
|
||||||
copy_weak_entry (&entries[k], ©);
|
|
||||||
if (copy.key)
|
|
||||||
lock_weak_set (SCM_WEAK_SET (SCM_PACK (copy.key)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
unlock_all_weak_sets (void)
|
|
||||||
{
|
|
||||||
scm_t_weak_set *s;
|
|
||||||
scm_t_weak_entry *entries;
|
|
||||||
unsigned long k, size;
|
|
||||||
scm_t_weak_entry copy;
|
|
||||||
|
|
||||||
s = SCM_WEAK_SET (all_weak_sets);
|
|
||||||
size = s->size;
|
|
||||||
entries = s->entries;
|
|
||||||
|
|
||||||
for (k = 0; k < size; k++)
|
|
||||||
if (entries[k].hash)
|
|
||||||
{
|
|
||||||
copy_weak_entry (&entries[k], ©);
|
|
||||||
if (copy.key)
|
|
||||||
unlock_weak_set (SCM_WEAK_SET (SCM_PACK (copy.key)));
|
|
||||||
}
|
|
||||||
|
|
||||||
unlock_weak_set (s);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* SCM_USE_PTHREAD_THREADS */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static SCM
|
static SCM
|
||||||
make_weak_set (unsigned long k)
|
make_weak_set (unsigned long k)
|
||||||
{
|
{
|
||||||
|
@ -764,7 +696,7 @@ do_vacuum_weak_set (SCM set)
|
||||||
if (scm_i_pthread_mutex_trylock (&s->lock) == 0)
|
if (scm_i_pthread_mutex_trylock (&s->lock) == 0)
|
||||||
{
|
{
|
||||||
vacuum_weak_set (s);
|
vacuum_weak_set (s);
|
||||||
unlock_weak_set (s);
|
scm_i_pthread_mutex_unlock (&s->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -829,9 +761,6 @@ scm_c_make_weak_set (unsigned long k)
|
||||||
|
|
||||||
scm_c_register_weak_gc_callback (ret, do_vacuum_weak_set);
|
scm_c_register_weak_gc_callback (ret, do_vacuum_weak_set);
|
||||||
|
|
||||||
if (scm_is_true (all_weak_sets))
|
|
||||||
scm_weak_set_add_x (all_weak_sets, ret);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -846,12 +775,12 @@ scm_weak_set_clear_x (SCM set)
|
||||||
{
|
{
|
||||||
scm_t_weak_set *s = SCM_WEAK_SET (set);
|
scm_t_weak_set *s = SCM_WEAK_SET (set);
|
||||||
|
|
||||||
lock_weak_set (s);
|
scm_i_pthread_mutex_lock (&s->lock);
|
||||||
|
|
||||||
memset (s->entries, 0, sizeof (scm_t_weak_entry) * s->size);
|
memset (s->entries, 0, sizeof (scm_t_weak_entry) * s->size);
|
||||||
s->n_items = 0;
|
s->n_items = 0;
|
||||||
|
|
||||||
unlock_weak_set (s);
|
scm_i_pthread_mutex_unlock (&s->lock);
|
||||||
|
|
||||||
return SCM_UNSPECIFIED;
|
return SCM_UNSPECIFIED;
|
||||||
}
|
}
|
||||||
|
@ -864,11 +793,11 @@ scm_c_weak_set_lookup (SCM set, unsigned long raw_hash,
|
||||||
SCM ret;
|
SCM ret;
|
||||||
scm_t_weak_set *s = SCM_WEAK_SET (set);
|
scm_t_weak_set *s = SCM_WEAK_SET (set);
|
||||||
|
|
||||||
lock_weak_set (s);
|
scm_i_pthread_mutex_lock (&s->lock);
|
||||||
|
|
||||||
ret = weak_set_lookup (s, raw_hash, pred, closure, dflt);
|
ret = weak_set_lookup (s, raw_hash, pred, closure, dflt);
|
||||||
|
|
||||||
unlock_weak_set (s);
|
scm_i_pthread_mutex_unlock (&s->lock);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -881,11 +810,11 @@ scm_c_weak_set_add_x (SCM set, unsigned long raw_hash,
|
||||||
SCM ret;
|
SCM ret;
|
||||||
scm_t_weak_set *s = SCM_WEAK_SET (set);
|
scm_t_weak_set *s = SCM_WEAK_SET (set);
|
||||||
|
|
||||||
lock_weak_set (s);
|
scm_i_pthread_mutex_lock (&s->lock);
|
||||||
|
|
||||||
ret = weak_set_add_x (s, raw_hash, pred, closure, obj);
|
ret = weak_set_add_x (s, raw_hash, pred, closure, obj);
|
||||||
|
|
||||||
unlock_weak_set (s);
|
scm_i_pthread_mutex_unlock (&s->lock);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -897,11 +826,11 @@ scm_c_weak_set_remove_x (SCM set, unsigned long raw_hash,
|
||||||
{
|
{
|
||||||
scm_t_weak_set *s = SCM_WEAK_SET (set);
|
scm_t_weak_set *s = SCM_WEAK_SET (set);
|
||||||
|
|
||||||
lock_weak_set (s);
|
scm_i_pthread_mutex_lock (&s->lock);
|
||||||
|
|
||||||
weak_set_remove_x (s, raw_hash, pred, closure);
|
weak_set_remove_x (s, raw_hash, pred, closure);
|
||||||
|
|
||||||
unlock_weak_set (s);
|
scm_i_pthread_mutex_unlock (&s->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -936,7 +865,7 @@ scm_c_weak_set_fold (scm_t_set_fold_fn proc, void *closure,
|
||||||
|
|
||||||
s = SCM_WEAK_SET (set);
|
s = SCM_WEAK_SET (set);
|
||||||
|
|
||||||
lock_weak_set (s);
|
scm_i_pthread_mutex_lock (&s->lock);
|
||||||
|
|
||||||
size = s->size;
|
size = s->size;
|
||||||
entries = s->entries;
|
entries = s->entries;
|
||||||
|
@ -952,14 +881,14 @@ scm_c_weak_set_fold (scm_t_set_fold_fn proc, void *closure,
|
||||||
if (copy.key)
|
if (copy.key)
|
||||||
{
|
{
|
||||||
/* Release set lock while we call the function. */
|
/* Release set lock while we call the function. */
|
||||||
unlock_weak_set (s);
|
scm_i_pthread_mutex_unlock (&s->lock);
|
||||||
init = proc (closure, SCM_PACK (copy.key), init);
|
init = proc (closure, SCM_PACK (copy.key), init);
|
||||||
lock_weak_set (s);
|
scm_i_pthread_mutex_lock (&s->lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unlock_weak_set (s);
|
scm_i_pthread_mutex_unlock (&s->lock);
|
||||||
|
|
||||||
return init;
|
return init;
|
||||||
}
|
}
|
||||||
|
@ -1004,17 +933,6 @@ scm_weak_set_map_to_list (SCM proc, SCM set)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
scm_weak_set_prehistory (void)
|
|
||||||
{
|
|
||||||
#if SCM_USE_PTHREAD_THREADS
|
|
||||||
all_weak_sets = scm_c_make_weak_set (0);
|
|
||||||
pthread_atfork (lock_all_weak_sets, unlock_all_weak_sets, unlock_all_weak_sets);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
scm_init_weak_set ()
|
scm_init_weak_set ()
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#ifndef SCM_WEAK_SET_H
|
#ifndef SCM_WEAK_SET_H
|
||||||
#define SCM_WEAK_SET_H
|
#define SCM_WEAK_SET_H
|
||||||
|
|
||||||
/* Copyright (C) 2011, 2012 Free Software Foundation, Inc.
|
/* Copyright (C) 2011 Free Software Foundation, Inc.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public License
|
* modify it under the terms of the GNU Lesser General Public License
|
||||||
|
@ -57,10 +57,7 @@ SCM_INTERNAL SCM scm_weak_set_fold (SCM proc, SCM init, SCM set);
|
||||||
SCM_INTERNAL SCM scm_weak_set_for_each (SCM proc, SCM set);
|
SCM_INTERNAL SCM scm_weak_set_for_each (SCM proc, SCM set);
|
||||||
SCM_INTERNAL SCM scm_weak_set_map_to_list (SCM proc, SCM set);
|
SCM_INTERNAL SCM scm_weak_set_map_to_list (SCM proc, SCM set);
|
||||||
|
|
||||||
SCM_INTERNAL void scm_i_weak_set_lock (SCM set);
|
|
||||||
SCM_INTERNAL void scm_i_weak_set_unlock (SCM set);
|
|
||||||
SCM_INTERNAL void scm_i_weak_set_print (SCM exp, SCM port, scm_print_state *pstate);
|
SCM_INTERNAL void scm_i_weak_set_print (SCM exp, SCM port, scm_print_state *pstate);
|
||||||
SCM_INTERNAL void scm_weak_set_prehistory (void);
|
|
||||||
SCM_INTERNAL void scm_init_weak_set (void);
|
SCM_INTERNAL void scm_init_weak_set (void);
|
||||||
|
|
||||||
#endif /* SCM_WEAK_SET_H */
|
#endif /* SCM_WEAK_SET_H */
|
||||||
|
|
|
@ -772,79 +772,10 @@ weak_table_remove_x (scm_t_weak_table *table, unsigned long hash,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
lock_weak_table (scm_t_weak_table *table)
|
|
||||||
{
|
|
||||||
scm_i_pthread_mutex_lock (&table->lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
unlock_weak_table (scm_t_weak_table *table)
|
|
||||||
{
|
|
||||||
scm_i_pthread_mutex_unlock (&table->lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* A weak table of weak tables, for use in the pthread_atfork handler. */
|
|
||||||
static SCM all_weak_tables = SCM_BOOL_F;
|
|
||||||
|
|
||||||
#if SCM_USE_PTHREAD_THREADS
|
|
||||||
|
|
||||||
static void
|
|
||||||
lock_all_weak_tables (void)
|
|
||||||
{
|
|
||||||
scm_t_weak_table *s;
|
|
||||||
scm_t_weak_entry *entries;
|
|
||||||
unsigned long k, size;
|
|
||||||
scm_t_weak_entry copy;
|
|
||||||
|
|
||||||
s = SCM_WEAK_TABLE (all_weak_tables);
|
|
||||||
lock_weak_table (s);
|
|
||||||
size = s->size;
|
|
||||||
entries = s->entries;
|
|
||||||
|
|
||||||
for (k = 0; k < size; k++)
|
|
||||||
if (entries[k].hash)
|
|
||||||
{
|
|
||||||
copy_weak_entry (&entries[k], ©);
|
|
||||||
if (copy.key)
|
|
||||||
lock_weak_table (SCM_WEAK_TABLE (SCM_PACK (copy.key)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
unlock_all_weak_tables (void)
|
|
||||||
{
|
|
||||||
scm_t_weak_table *s;
|
|
||||||
scm_t_weak_entry *entries;
|
|
||||||
unsigned long k, size;
|
|
||||||
scm_t_weak_entry copy;
|
|
||||||
|
|
||||||
s = SCM_WEAK_TABLE (all_weak_tables);
|
|
||||||
size = s->size;
|
|
||||||
entries = s->entries;
|
|
||||||
|
|
||||||
for (k = 0; k < size; k++)
|
|
||||||
if (entries[k].hash)
|
|
||||||
{
|
|
||||||
copy_weak_entry (&entries[k], ©);
|
|
||||||
if (copy.key)
|
|
||||||
unlock_weak_table (SCM_WEAK_TABLE (SCM_PACK (copy.key)));
|
|
||||||
}
|
|
||||||
|
|
||||||
unlock_weak_table (s);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* SCM_USE_PTHREAD_THREADS */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static SCM
|
static SCM
|
||||||
make_weak_table (unsigned long k, scm_t_weak_table_kind kind)
|
make_weak_table (unsigned long k, scm_t_weak_table_kind kind)
|
||||||
{
|
{
|
||||||
scm_t_weak_table *table;
|
scm_t_weak_table *table;
|
||||||
SCM ret;
|
|
||||||
|
|
||||||
int i = 0, n = k ? k : 31;
|
int i = 0, n = k ? k : 31;
|
||||||
while (i + 1 < HASHTABLE_SIZE_N && n > hashtable_size[i])
|
while (i + 1 < HASHTABLE_SIZE_N && n > hashtable_size[i])
|
||||||
|
@ -862,12 +793,7 @@ make_weak_table (unsigned long k, scm_t_weak_table_kind kind)
|
||||||
table->min_size_index = i;
|
table->min_size_index = i;
|
||||||
scm_i_pthread_mutex_init (&table->lock, NULL);
|
scm_i_pthread_mutex_init (&table->lock, NULL);
|
||||||
|
|
||||||
ret = scm_cell (scm_tc7_weak_table, (scm_t_bits)table);
|
return scm_cell (scm_tc7_weak_table, (scm_t_bits)table);
|
||||||
|
|
||||||
if (scm_is_true (all_weak_tables))
|
|
||||||
scm_weak_table_putq_x (all_weak_tables, ret, SCM_BOOL_T);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -891,7 +817,7 @@ do_vacuum_weak_table (SCM table)
|
||||||
if (scm_i_pthread_mutex_trylock (&t->lock) == 0)
|
if (scm_i_pthread_mutex_trylock (&t->lock) == 0)
|
||||||
{
|
{
|
||||||
vacuum_weak_table (t);
|
vacuum_weak_table (t);
|
||||||
unlock_weak_table (t);
|
scm_i_pthread_mutex_unlock (&t->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -978,11 +904,11 @@ scm_c_weak_table_ref (SCM table, unsigned long raw_hash,
|
||||||
|
|
||||||
t = SCM_WEAK_TABLE (table);
|
t = SCM_WEAK_TABLE (table);
|
||||||
|
|
||||||
lock_weak_table (t);
|
scm_i_pthread_mutex_lock (&t->lock);
|
||||||
|
|
||||||
ret = weak_table_ref (t, raw_hash, pred, closure, dflt);
|
ret = weak_table_ref (t, raw_hash, pred, closure, dflt);
|
||||||
|
|
||||||
unlock_weak_table (t);
|
scm_i_pthread_mutex_unlock (&t->lock);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -1000,11 +926,11 @@ scm_c_weak_table_put_x (SCM table, unsigned long raw_hash,
|
||||||
|
|
||||||
t = SCM_WEAK_TABLE (table);
|
t = SCM_WEAK_TABLE (table);
|
||||||
|
|
||||||
lock_weak_table (t);
|
scm_i_pthread_mutex_lock (&t->lock);
|
||||||
|
|
||||||
weak_table_put_x (t, raw_hash, pred, closure, key, value);
|
weak_table_put_x (t, raw_hash, pred, closure, key, value);
|
||||||
|
|
||||||
unlock_weak_table (t);
|
scm_i_pthread_mutex_unlock (&t->lock);
|
||||||
}
|
}
|
||||||
#undef FUNC_NAME
|
#undef FUNC_NAME
|
||||||
|
|
||||||
|
@ -1020,11 +946,11 @@ scm_c_weak_table_remove_x (SCM table, unsigned long raw_hash,
|
||||||
|
|
||||||
t = SCM_WEAK_TABLE (table);
|
t = SCM_WEAK_TABLE (table);
|
||||||
|
|
||||||
lock_weak_table (t);
|
scm_i_pthread_mutex_lock (&t->lock);
|
||||||
|
|
||||||
weak_table_remove_x (t, raw_hash, pred, closure);
|
weak_table_remove_x (t, raw_hash, pred, closure);
|
||||||
|
|
||||||
unlock_weak_table (t);
|
scm_i_pthread_mutex_unlock (&t->lock);
|
||||||
}
|
}
|
||||||
#undef FUNC_NAME
|
#undef FUNC_NAME
|
||||||
|
|
||||||
|
@ -1072,12 +998,12 @@ scm_weak_table_clear_x (SCM table)
|
||||||
|
|
||||||
t = SCM_WEAK_TABLE (table);
|
t = SCM_WEAK_TABLE (table);
|
||||||
|
|
||||||
lock_weak_table (t);
|
scm_i_pthread_mutex_lock (&t->lock);
|
||||||
|
|
||||||
memset (t->entries, 0, sizeof (scm_t_weak_entry) * t->size);
|
memset (t->entries, 0, sizeof (scm_t_weak_entry) * t->size);
|
||||||
t->n_items = 0;
|
t->n_items = 0;
|
||||||
|
|
||||||
unlock_weak_table (t);
|
scm_i_pthread_mutex_unlock (&t->lock);
|
||||||
|
|
||||||
return SCM_UNSPECIFIED;
|
return SCM_UNSPECIFIED;
|
||||||
}
|
}
|
||||||
|
@ -1093,7 +1019,7 @@ scm_c_weak_table_fold (scm_t_table_fold_fn proc, void *closure,
|
||||||
|
|
||||||
t = SCM_WEAK_TABLE (table);
|
t = SCM_WEAK_TABLE (table);
|
||||||
|
|
||||||
lock_weak_table (t);
|
scm_i_pthread_mutex_lock (&t->lock);
|
||||||
|
|
||||||
size = t->size;
|
size = t->size;
|
||||||
entries = t->entries;
|
entries = t->entries;
|
||||||
|
@ -1109,16 +1035,16 @@ scm_c_weak_table_fold (scm_t_table_fold_fn proc, void *closure,
|
||||||
if (copy.key && copy.value)
|
if (copy.key && copy.value)
|
||||||
{
|
{
|
||||||
/* Release table lock while we call the function. */
|
/* Release table lock while we call the function. */
|
||||||
unlock_weak_table (t);
|
scm_i_pthread_mutex_unlock (&t->lock);
|
||||||
init = proc (closure,
|
init = proc (closure,
|
||||||
SCM_PACK (copy.key), SCM_PACK (copy.value),
|
SCM_PACK (copy.key), SCM_PACK (copy.value),
|
||||||
init);
|
init);
|
||||||
lock_weak_table (t);
|
scm_i_pthread_mutex_lock (&t->lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unlock_weak_table (t);
|
scm_i_pthread_mutex_unlock (&t->lock);
|
||||||
|
|
||||||
return init;
|
return init;
|
||||||
}
|
}
|
||||||
|
@ -1273,12 +1199,6 @@ scm_weak_table_prehistory (void)
|
||||||
GC_new_kind (GC_new_free_list (),
|
GC_new_kind (GC_new_free_list (),
|
||||||
GC_MAKE_PROC (GC_new_proc (mark_weak_value_table), 0),
|
GC_MAKE_PROC (GC_new_proc (mark_weak_value_table), 0),
|
||||||
0, 0);
|
0, 0);
|
||||||
|
|
||||||
#if SCM_USE_PTHREAD_THREADS
|
|
||||||
all_weak_tables = scm_c_make_weak_table (0, SCM_WEAK_TABLE_KIND_KEY);
|
|
||||||
pthread_atfork (lock_all_weak_tables, unlock_all_weak_tables,
|
|
||||||
unlock_all_weak_tables);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue