1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-29 22:40:34 +02:00
Conflicts:
	libguile/guardians.c
This commit is contained in:
Andy Wingo 2013-11-28 16:03:58 +01:00
commit 6683f204ba

View file

@ -40,7 +40,6 @@
* monsters we had... * monsters we had...
* *
* Rewritten for the Boehm-Demers-Weiser GC by Ludovic Courtès. * Rewritten for the Boehm-Demers-Weiser GC by Ludovic Courtès.
* FIXME: This is currently not thread-safe.
*/ */
/* Uncomment the following line to debug guardian finalization. */ /* Uncomment the following line to debug guardian finalization. */
@ -71,6 +70,7 @@ static scm_t_bits tc16_guardian;
typedef struct t_guardian typedef struct t_guardian
{ {
scm_i_pthread_mutex_t mutex;
unsigned long live; unsigned long live;
SCM zombies; SCM zombies;
struct t_guardian *next; struct t_guardian *next;
@ -146,6 +146,9 @@ finalize_guarded (void *ptr, void *finalizer_data)
} }
g = GUARDIAN_DATA (guardian); g = GUARDIAN_DATA (guardian);
scm_i_pthread_mutex_lock_block_asyncs (&g->mutex);
if (g->live == 0) if (g->live == 0)
abort (); abort ();
@ -159,7 +162,8 @@ finalize_guarded (void *ptr, void *finalizer_data)
g->zombies = zombies; g->zombies = zombies;
g->live--; g->live--;
g->zombies = zombies;
scm_i_pthread_mutex_unlock_unblock_asyncs (&g->mutex);
} }
if (scm_is_true (proxied_finalizer)) if (scm_is_true (proxied_finalizer))
@ -210,6 +214,8 @@ scm_i_guard (SCM guardian, SCM obj)
void *prev_data; void *prev_data;
SCM guardians_for_obj, finalizer_data; SCM guardians_for_obj, finalizer_data;
scm_i_pthread_mutex_lock_block_asyncs (&g->mutex);
g->live++; g->live++;
/* Note: GUARDIANS_FOR_OBJ holds weak references to guardians so /* Note: GUARDIANS_FOR_OBJ holds weak references to guardians so
@ -253,6 +259,8 @@ scm_i_guard (SCM guardian, SCM obj)
SCM_PACK_POINTER (prev_data)); SCM_PACK_POINTER (prev_data));
SCM_SETCAR (finalizer_data, proxied_finalizer); SCM_SETCAR (finalizer_data, proxied_finalizer);
} }
scm_i_pthread_mutex_unlock_unblock_asyncs (&g->mutex);
} }
} }
@ -262,6 +270,8 @@ scm_i_get_one_zombie (SCM guardian)
t_guardian *g = GUARDIAN_DATA (guardian); t_guardian *g = GUARDIAN_DATA (guardian);
SCM res = SCM_BOOL_F; SCM res = SCM_BOOL_F;
scm_i_pthread_mutex_lock_block_asyncs (&g->mutex);
if (!scm_is_null (g->zombies)) if (!scm_is_null (g->zombies))
{ {
/* Note: We return zombies in reverse order. */ /* Note: We return zombies in reverse order. */
@ -269,6 +279,8 @@ scm_i_get_one_zombie (SCM guardian)
g->zombies = SCM_CDR (g->zombies); g->zombies = SCM_CDR (g->zombies);
} }
scm_i_pthread_mutex_unlock_unblock_asyncs (&g->mutex);
return res; return res;
} }
@ -339,6 +351,8 @@ SCM_DEFINE (scm_make_guardian, "make-guardian", 0, 0, 0,
t_guardian *g = scm_gc_malloc (sizeof (t_guardian), "guardian"); t_guardian *g = scm_gc_malloc (sizeof (t_guardian), "guardian");
SCM z; SCM z;
scm_i_pthread_mutex_init (&g->mutex, NULL);
/* A tconc starts out with one tail pair. */ /* A tconc starts out with one tail pair. */
g->live = 0; g->live = 0;
g->zombies = SCM_EOL; g->zombies = SCM_EOL;