emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: emacs-unicode-2 bootstrap on FreeBSD (temacs coredump)


From: YAMAMOTO Mitsuharu
Subject: Re: emacs-unicode-2 bootstrap on FreeBSD (temacs coredump)
Date: Mon, 06 Aug 2007 19:04:08 +0900
User-agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.8 (Shijō) APEL/10.6 Emacs/22.1.50 (sparc-sun-solaris2.8) MULE/5.0 (SAKAKI)

>>>>> On Mon, 06 Aug 2007 17:47:55 +0900, YAMAMOTO Mitsuharu <address@hidden> 
>>>>> said:

> How about deferring mutex initializations until an interactive
> session starts?  Could you try the patch below?

(UN)LOCK_ALIGNED_BLOCKS was not conditionalized.  Please try this one
instead.

                                     YAMAMOTO Mitsuharu
                                address@hidden

Index: src/emacs.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/emacs.c,v
retrieving revision 1.404
diff -c -p -r1.404 emacs.c
*** src/emacs.c 26 Jul 2007 05:27:51 -0000      1.404
--- src/emacs.c 6 Aug 2007 09:34:26 -0000
*************** main (argc, argv
*** 1164,1169 ****
--- 1164,1176 ----
        setpgrp ();
  #endif
  #endif
+ #if defined (HAVE_GTK_AND_PTHREAD) && !defined (SYSTEM_MALLOC) && !defined 
(DOUG_LEA_MALLOC)
+       {
+       extern void malloc_enable_thread P_ ((void));
+ 
+       malloc_enable_thread ();
+       }
+ #endif
      }
  
    init_signals ();
Index: src/gmalloc.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/gmalloc.c,v
retrieving revision 1.24
diff -c -p -r1.24 gmalloc.c
*** src/gmalloc.c       29 Jul 2007 10:12:21 -0000      1.24
--- src/gmalloc.c       6 Aug 2007 09:34:26 -0000
*************** extern __ptr_t memalign PP ((__malloc_si
*** 136,141 ****
--- 136,145 ----
  extern __ptr_t valloc PP ((__malloc_size_t __size));
  #endif
  
+ #ifdef USE_PTHREAD
+ /* Set up mutexes and make malloc etc. thread-safe.  */
+ extern void malloc_enable_thread PP ((void));
+ #endif
  
  #ifdef _MALLOC_INTERNAL
  
*************** extern void _free_internal_nolock PP ((_
*** 242,251 ****
  
  #ifdef USE_PTHREAD
  extern pthread_mutex_t _malloc_mutex, _aligned_blocks_mutex;
! #define LOCK()     pthread_mutex_lock (&_malloc_mutex)
! #define UNLOCK()   pthread_mutex_unlock (&_malloc_mutex)
! #define LOCK_ALIGNED_BLOCKS()     pthread_mutex_lock (&_aligned_blocks_mutex)
! #define UNLOCK_ALIGNED_BLOCKS()   pthread_mutex_unlock 
(&_aligned_blocks_mutex)
  #else
  #define LOCK()
  #define UNLOCK()
--- 246,272 ----
  
  #ifdef USE_PTHREAD
  extern pthread_mutex_t _malloc_mutex, _aligned_blocks_mutex;
! extern int _malloc_thread_enabled_p;
! #define LOCK()                                        \
!   do {                                                \
!     if (_malloc_thread_enabled_p)             \
!       pthread_mutex_lock (&_malloc_mutex);    \
!   } while (0)
! #define UNLOCK()                              \
!   do {                                                \
!     if (_malloc_thread_enabled_p)             \
!       pthread_mutex_unlock (&_malloc_mutex);  \
!   } while (0)
! #define LOCK_ALIGNED_BLOCKS()                         \
!   do {                                                        \
!     if (_malloc_thread_enabled_p)                     \
!       pthread_mutex_lock (&_aligned_blocks_mutex);    \
!   } while (0)
! #define UNLOCK_ALIGNED_BLOCKS()                               \
!   do {                                                        \
!     if (_malloc_thread_enabled_p)                     \
!       pthread_mutex_unlock (&_aligned_blocks_mutex);  \
!   } while (0)
  #else
  #define LOCK()
  #define UNLOCK()
*************** register_heapinfo ()
*** 563,568 ****
--- 584,630 ----
  #ifdef USE_PTHREAD
  pthread_mutex_t _malloc_mutex = PTHREAD_MUTEX_INITIALIZER;
  pthread_mutex_t _aligned_blocks_mutex = PTHREAD_MUTEX_INITIALIZER;
+ int _malloc_thread_enabled_p;
+ 
+ static void
+ malloc_atfork_handler_prepare ()
+ {
+   LOCK ();
+   LOCK_ALIGNED_BLOCKS ();
+ }
+ 
+ static void
+ malloc_atfork_handler_parent ()
+ {
+   UNLOCK_ALIGNED_BLOCKS ();
+   UNLOCK ();
+ }
+ 
+ static void
+ malloc_atfork_handler_child ()
+ {
+   UNLOCK_ALIGNED_BLOCKS ();
+   UNLOCK ();
+ }
+ 
+ /* Set up mutexes and make malloc etc. thread-safe.  */
+ void
+ malloc_enable_thread ()
+ {
+   if (_malloc_thread_enabled_p)
+     return;
+ 
+   /* Some pthread implementations call malloc for statically
+      initialized mutexes when they are used first.  To avoid such a
+      situation, we initialize mutexes here while their use is
+      disabled in malloc etc.  */
+   pthread_mutex_init (&_malloc_mutex, NULL);
+   pthread_mutex_init (&_aligned_blocks_mutex, NULL);
+   pthread_atfork (malloc_atfork_handler_prepare,
+                 malloc_atfork_handler_parent,
+                 malloc_atfork_handler_child);
+   _malloc_thread_enabled_p = 1;
+ }
  #endif
  
  static void




reply via email to

[Prev in Thread] Current Thread [Next in Thread]