Move malloc_mutex initialisation/destruction:
authorIlya Zakharevich <ilya@math.berkeley.edu>
Tue, 25 Nov 1997 15:59:16 +0000 (15:59 +0000)
committerMalcolm Beattie <mbeattie@sable.ox.ac.uk>
Tue, 25 Nov 1997 15:59:16 +0000 (15:59 +0000)
Subject:  patch to 5.004_54 for pthreads with Perl's malloc

p4raw-id: //depot/perl@299

malloc.c
os2/os2.c
os2/os2ish.h
perl.c
perl.h
plan9/plan9ish.h
unixish.h
vms/vmsish.h

index 5f0c7fd18505a8a81fbae8e694e8a685a93d35b7..ae3773acc08d3ab86af3dd27f35d981dcc5e2935 100644 (file)
--- a/malloc.c
+++ b/malloc.c
@@ -191,6 +191,7 @@ emergency_sbrk(size)
     }
 
     if (!emergency_buffer) {           
+       dTHR;
        /* First offense, give a possibility to recover by dieing. */
        /* No malloc involved here: */
        GV **gvp = (GV**)hv_fetch(defstash, "^M", 2, 0);
index 8a292e30f25bc063c2ac246e5b3e7dae9d7fff49..44f99c4c249b1dd612b8d71c1afe3f9bd143ec40 100644 (file)
--- a/os2/os2.c
+++ b/os2/os2.c
@@ -1147,6 +1147,7 @@ Perl_OS2_init(char **env)
 {
     char *shell;
 
+    MALLOC_INIT;
     settmppath();
     OS2_Perl_data.xs_init = &Xs_OS2_init;
     if (environ == NULL) {
index b62e3d04d4bca772597579eb3005652672774fde..9a3d267ae5cb275e47e2c4c0c428a55f41c7b5ca 100644 (file)
@@ -74,7 +74,7 @@ void Perl_OS2_init(char **);
     _wildcard(argcp, argvp);                   \
     Perl_OS2_init(env);        } STMT_END
 
-#define PERL_SYS_TERM()
+#define PERL_SYS_TERM()                MALLOC_TERM
 
 /* #define PERL_SYS_TERM() STMT_START {        \
     if (Perl_HAB_set) WinTerminate(Perl_hab);  } STMT_END */
diff --git a/perl.c b/perl.c
index 381d5748a23e09804845849a8b966abe32ba304e..8257b364082d9efbc49bb9e855a08b47512e4120 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -134,7 +134,6 @@ perl_construct(register PerlInterpreter *sv_interp)
        if (pthread_key_create(&thr_key, 0))
            croak("panic: pthread_key_create");
 #endif
-       MUTEX_INIT(&malloc_mutex);
        MUTEX_INIT(&sv_mutex);
        /*
         * Safe to use basic SV functions from now on (though
@@ -529,7 +528,6 @@ perl_destruct(register PerlInterpreter *sv_interp)
     DEBUG_P(debprofdump());
 #ifdef USE_THREADS
     MUTEX_DESTROY(&sv_mutex);
-    MUTEX_DESTROY(&malloc_mutex);
     MUTEX_DESTROY(&eval_mutex);
     COND_DESTROY(&eval_cond);
 
diff --git a/perl.h b/perl.h
index 697765ea29013d354b81b4da118aefd274ea0189..0ffb04c74ba516061f36c0e7735869df4b2f6a3d 100644 (file)
--- a/perl.h
+++ b/perl.h
@@ -1343,6 +1343,14 @@ typedef Sighandler_t Sigsave_t;
 # define RUNOPS_DEFAULT runops_standard
 #endif
 
+#ifdef MYMALLOC
+#  define MALLOC_INIT MUTEX_INIT(&malloc_mutex)
+#  define MALLOC_TERM MUTEX_DESTROY(&malloc_mutex)
+#else
+#  define MALLOC_INIT
+#  define MALLOC_TERM
+#endif
+
 /*
  * These need prototyping here because <proto.h> isn't
  * included until after runops is initialised.
index 3a5ad5eb1a3e6fc149276251ce0a0b4be9ebf088..9c8bd5049f5e6174f4f5f14fd5ffa147dd7223de 100644 (file)
@@ -98,9 +98,9 @@
 #define ABORT() kill(getpid(),SIGABRT);
 
 #define BIT_BUCKET "/dev/null"
-#define PERL_SYS_INIT(c,v)
+#define PERL_SYS_INIT(c,v)     MALLOC_INIT
 #define dXSUB_SYS
-#define PERL_SYS_TERM()
+#define PERL_SYS_TERM()                MALLOC_TERM
 
 /*
  * fwrite1() should be a routine with the same calling sequence as fwrite(),
index a13e2bd86a5a1e6513a4dd04ad2c69660f4ec023..e4687ce50f34012c91f3a74c0f1fe145119a50e1 100644 (file)
--- a/unixish.h
+++ b/unixish.h
 #ifndef PERL_SYS_INIT
 #ifdef PERL_SCO5
 /* this should be set in a hint file, not here */
-#  define PERL_SYS_INIT(c,v)   fpsetmask(0)
+#  define PERL_SYS_INIT(c,v)   fpsetmask(0); MALLOC_INIT
 #else
-#  define PERL_SYS_INIT(c,v)
+#  define PERL_SYS_INIT(c,v)   MALLOC_INIT
 #endif
 #endif
 
 #ifndef PERL_SYS_TERM
-#define PERL_SYS_TERM()
+#define PERL_SYS_TERM()                MALLOC_TERM
 #endif
 
 #define BIT_BUCKET "/dev/null"
index 410031cca3d3a3476d70372fe977829517e77a4f..f0de8079200858ab4cba5b5c5dd615e8802e467a 100644 (file)
 #endif
 
 #define BIT_BUCKET "_NLA0:"
-#define PERL_SYS_INIT(c,v)  vms_image_init((c),(v))
-#define PERL_SYS_TERM()
+#define PERL_SYS_INIT(c,v)     vms_image_init((c),(v)), MALLOC_INIT
+#define PERL_SYS_TERM()                MALLOC_TERM
 #define dXSUB_SYS
 #define HAS_KILL
 #define HAS_WAIT