1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 03:30:27 +02:00

* gc-malloc.c (malloc_mutex): New mutex.

(scm_gc_init_malloc): Initialize it.
(scm_realloc): Serialize call to realloc
(scm_calloc): Same for calloc.
Thanks to Wolfgang Jaehrling!
(Now we have to make sure all calls to malloc/realloc are made
through scm_malloc.)
This commit is contained in:
Mikael Djurfeldt 2002-12-10 20:09:45 +00:00
parent 5b5947a2b5
commit 3cdde9d667
2 changed files with 20 additions and 0 deletions

View file

@ -1,5 +1,13 @@
2002-12-10 Mikael Djurfeldt <mdj@kvast.blakulla.net>
* gc-malloc.c (malloc_mutex): New mutex.
(scm_gc_init_malloc): Initialize it.
(scm_realloc): Serialize call to realloc
(scm_calloc): Same for calloc.
Thanks to Wolfgang Jaehrling!
(Now we have to make sure all calls to malloc/realloc are made
through scm_malloc.)
* threads.c (really_launch): Release heap (to prevent deadlock).
(create_thread): Release heap before locking thread admin mutex.

View file

@ -99,6 +99,8 @@ extern unsigned long * __libc_ia64_register_backing_store_base;
static int scm_i_minyield_malloc;
static scm_t_mutex malloc_mutex;
void
scm_gc_init_malloc (void)
{
@ -114,6 +116,8 @@ scm_gc_init_malloc (void)
if (scm_mtrigger < 0)
scm_mtrigger = SCM_DEFAULT_INIT_MALLOC_LIMIT;
scm_i_plugin_mutex_init (&malloc_mutex, 0);
}
@ -126,7 +130,9 @@ scm_realloc (void *mem, size_t size)
{
void *ptr;
scm_i_plugin_mutex_lock (&malloc_mutex);
SCM_SYSCALL (ptr = realloc (mem, size));
scm_i_plugin_mutex_lock (&malloc_mutex);
if (ptr)
return ptr;
@ -134,7 +140,9 @@ scm_realloc (void *mem, size_t size)
scm_i_sweep_all_segments ("realloc");
scm_i_plugin_mutex_lock (&malloc_mutex);
SCM_SYSCALL (ptr = realloc (mem, size));
scm_i_plugin_mutex_unlock (&malloc_mutex);
if (ptr)
{
scm_i_thread_wake_up ();
@ -146,7 +154,9 @@ scm_realloc (void *mem, size_t size)
scm_i_thread_wake_up ();
scm_i_plugin_mutex_lock (&malloc_mutex);
SCM_SYSCALL (ptr = realloc (mem, size));
scm_i_plugin_mutex_unlock (&malloc_mutex);
if (ptr)
return ptr;
@ -172,7 +182,9 @@ scm_calloc (size_t sz)
By default, try to use calloc, as it is likely more efficient than
calling memset by hand.
*/
scm_i_plugin_mutex_lock (&malloc_mutex);
SCM_SYSCALL(ptr= calloc (sz, 1));
scm_i_plugin_mutex_unlock (&malloc_mutex);
if (ptr)
return ptr;