YAMAMOTO Mitsuharu
address@hidden
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 1 Aug 2007 10:35:05 -0000
*************** extern void _free_internal_nolock PP ((_
*** 242,249 ****
#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
--- 242,256 ----
#ifdef USE_PTHREAD
extern pthread_mutex_t _malloc_mutex, _aligned_blocks_mutex;
! extern int _malloc_mutex_disabled_p;
! #define LOCK() \
! do { \
! if (!_malloc_mutex_disabled_p) pthread_mutex_lock (&_malloc_mutex); \
! } while (0)
! #define UNLOCK() \
! do { \
! if (!_malloc_mutex_disabled_p) pthread_mutex_unlock (&_malloc_mutex); \
! } while (0)
#define LOCK_ALIGNED_BLOCKS() pthread_mutex_lock (&_aligned_blocks_mutex)
#define UNLOCK_ALIGNED_BLOCKS() pthread_mutex_unlock
(&_aligned_blocks_mutex)
#else
*************** register_heapinfo ()
*** 563,568 ****
--- 570,576 ----
#ifdef USE_PTHREAD
pthread_mutex_t _malloc_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t _aligned_blocks_mutex = PTHREAD_MUTEX_INITIALIZER;
+ int _malloc_mutex_disabled_p;
#endif
static void
*************** __malloc_initialize ()
*** 617,622 ****
--- 625,641 ----
malloc_initialize_1 ();
+ /* Some pthread implementations call malloc for statically
+ initialized mutexes when they are used first. To avoid such a
+ situation, we initialize mutexes here with temporarily disabling
+ the use of mutexes. */
+ #ifdef USE_PTHREAD
+ _malloc_mutex_disabled_p = 1;
+ pthread_mutex_init (&_malloc_mutex, NULL);
+ pthread_mutex_init (&_aligned_blocks_mutex, NULL);
+ _malloc_mutex_disabled_p = 0;
+ #endif
+
return __malloc_initialized;
}
_______________________________________________
Emacs-devel mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/emacs-devel