From: YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
To: "Jan Djärv" <jan.h.d@swipnet.se>
Cc: keramida@ceid.upatras.gr, cyd@stupidchicken.com, emacs-devel@gnu.org
Subject: Re: Pretest?
Date: Mon, 19 Mar 2007 18:31:03 +0900 [thread overview]
Message-ID: <wllkhty3zc.wl%mituharu@math.s.chiba-u.ac.jp> (raw)
In-Reply-To: <45FE430A.5070703@swipnet.se>
>>>>> On Mon, 19 Mar 2007 09:00:10 +0100, Jan Djärv <jan.h.d@swipnet.se> said:
> A thing to do after the release might be to synchronize with the
> thread safe malloc in glibc.
What do we do before the release? Possible options would be:
1) Use the system malloc library (and abandon emacs_blocked_*) if
HAVE_GTK_AND_PTHREAD.
2) Modify src/gmalloc.c to make it thread safe.
I just tried the latter, but I can't test it myself.
YAMAMOTO Mitsuharu
mituharu@math.s.chiba-u.ac.jp
Index: src/gmalloc.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/gmalloc.c,v
retrieving revision 1.20
diff -c -p -r1.20 gmalloc.c
*** src/gmalloc.c 21 Jan 2007 04:18:16 -0000 1.20
--- src/gmalloc.c 19 Mar 2007 09:18:53 -0000
***************
*** 1,6 ****
--- 1,9 ----
/* This file is no longer automatically generated from libc. */
#define _MALLOC_INTERNAL
+ #ifdef HAVE_GTK_AND_PTHREAD
+ #define USE_PTHREAD
+ #endif
/* The malloc headers and source files from the C library follow here. */
*************** Fifth Floor, Boston, MA 02110-1301, USA.
*** 73,78 ****
--- 76,85 ----
#include <unistd.h>
#endif
+ #ifdef USE_PTHREAD
+ #include <pthread.h>
+ #endif
+
#endif /* _MALLOC_INTERNAL. */
*************** extern __ptr_t _malloc_internal PP ((__m
*** 229,234 ****
--- 236,244 ----
extern __ptr_t _realloc_internal PP ((__ptr_t __ptr, __malloc_size_t __size));
extern void _free_internal PP ((__ptr_t __ptr));
+ #ifdef USE_PTHREAD
+ extern pthread_mutex_t _malloc_mutex;
+ #endif
#endif /* _MALLOC_INTERNAL. */
/* Given an address in the middle of a malloc'd object,
*************** register_heapinfo ()
*** 536,548 ****
_heapinfo[block + blocks].busy.info.size = -blocks;
}
! /* Set everything up and remember that we have. */
! int
! __malloc_initialize ()
! {
! if (__malloc_initialized)
! return 0;
#ifdef GC_MCHECK
mcheck (NULL);
#endif
--- 546,559 ----
_heapinfo[block + blocks].busy.info.size = -blocks;
}
! #ifdef USE_PTHREAD
! static pthread_once_t malloc_init_once_control = PTHREAD_ONCE_INIT;
! pthread_mutex_t _malloc_mutex;
! #endif
+ static void
+ malloc_initialize_1 ()
+ {
#ifdef GC_MCHECK
mcheck (NULL);
#endif
*************** __malloc_initialize ()
*** 550,559 ****
if (__malloc_initialize_hook)
(*__malloc_initialize_hook) ();
heapsize = HEAP / BLOCKSIZE;
_heapinfo = (malloc_info *) align (heapsize * sizeof (malloc_info));
if (_heapinfo == NULL)
! return 0;
memset (_heapinfo, 0, heapsize * sizeof (malloc_info));
_heapinfo[0].free.size = 0;
_heapinfo[0].free.next = _heapinfo[0].free.prev = 0;
--- 561,581 ----
if (__malloc_initialize_hook)
(*__malloc_initialize_hook) ();
+ #ifdef USE_PTHREAD
+ {
+ pthread_mutexattr_t attr;
+
+ pthread_mutexattr_init (&attr);
+ pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
+ pthread_mutex_init (&_malloc_mutex, &attr);
+ pthread_mutexattr_destroy (&attr);
+ }
+ #endif
+
heapsize = HEAP / BLOCKSIZE;
_heapinfo = (malloc_info *) align (heapsize * sizeof (malloc_info));
if (_heapinfo == NULL)
! return;
memset (_heapinfo, 0, heapsize * sizeof (malloc_info));
_heapinfo[0].free.size = 0;
_heapinfo[0].free.next = _heapinfo[0].free.prev = 0;
*************** __malloc_initialize ()
*** 565,571 ****
__malloc_initialized = 1;
PROTECT_MALLOC_STATE (1);
! return 1;
}
static int morecore_recursing;
--- 587,609 ----
__malloc_initialized = 1;
PROTECT_MALLOC_STATE (1);
! return;
! }
!
! /* Set everything up and remember that we have. */
! int
! __malloc_initialize ()
! {
! #ifdef USE_PTHREAD
! pthread_once (&malloc_init_once_control, malloc_initialize_1);
! #else
! if (__malloc_initialized)
! return 0;
!
! malloc_initialize_1 ();
! #endif
!
! return __malloc_initialized;
}
static int morecore_recursing;
*************** _malloc_internal (size)
*** 708,713 ****
--- 746,754 ----
return NULL;
#endif
+ #ifdef USE_PTHREAD
+ pthread_mutex_lock (&_malloc_mutex);
+ #endif
PROTECT_MALLOC_STATE (0);
if (size < sizeof (struct list))
*************** _malloc_internal (size)
*** 765,771 ****
if (result == NULL)
{
PROTECT_MALLOC_STATE (1);
! return NULL;
}
/* Link all fragments but the first into the free list. */
--- 806,812 ----
if (result == NULL)
{
PROTECT_MALLOC_STATE (1);
! goto out;
}
/* Link all fragments but the first into the free list. */
*************** _malloc_internal (size)
*** 831,837 ****
}
result = morecore (wantblocks * BLOCKSIZE);
if (result == NULL)
! return NULL;
block = BLOCK (result);
/* Put the new block at the end of the free list. */
_heapinfo[block].free.size = wantblocks;
--- 872,878 ----
}
result = morecore (wantblocks * BLOCKSIZE);
if (result == NULL)
! goto out;
block = BLOCK (result);
/* Put the new block at the end of the free list. */
_heapinfo[block].free.size = wantblocks;
*************** _malloc_internal (size)
*** 886,891 ****
--- 927,936 ----
}
PROTECT_MALLOC_STATE (1);
+ out:
+ #ifdef USE_PTHREAD
+ pthread_mutex_unlock (&_malloc_mutex);
+ #endif
return result;
}
*************** _free_internal (ptr)
*** 996,1001 ****
--- 1041,1049 ----
if (ptr == NULL)
return;
+ #ifdef USE_PTHREAD
+ pthread_mutex_lock (&_malloc_mutex);
+ #endif
PROTECT_MALLOC_STATE (0);
for (l = _aligned_blocks; l != NULL; l = l->next)
*************** _free_internal (ptr)
*** 1221,1226 ****
--- 1269,1277 ----
}
PROTECT_MALLOC_STATE (1);
+ #ifdef USE_PTHREAD
+ pthread_mutex_unlock (&_malloc_mutex);
+ #endif
}
/* Return memory to the heap. */
*************** _realloc_internal (ptr, size)
*** 1384,1389 ****
--- 1435,1443 ----
block = BLOCK (ptr);
+ #ifdef USE_PTHREAD
+ pthread_mutex_lock (&_malloc_mutex);
+ #endif
PROTECT_MALLOC_STATE (0);
type = _heapinfo[block].busy.type;
*************** _realloc_internal (ptr, size)
*** 1398,1404 ****
{
memcpy (result, ptr, size);
_free_internal (ptr);
! return result;
}
}
--- 1452,1458 ----
{
memcpy (result, ptr, size);
_free_internal (ptr);
! goto out;
}
}
*************** _realloc_internal (ptr, size)
*** 1451,1457 ****
(void) _malloc_internal (blocks * BLOCKSIZE);
_free_internal (previous);
}
! return NULL;
}
if (ptr != result)
memmove (result, ptr, blocks * BLOCKSIZE);
--- 1505,1511 ----
(void) _malloc_internal (blocks * BLOCKSIZE);
_free_internal (previous);
}
! goto out;
}
if (ptr != result)
memmove (result, ptr, blocks * BLOCKSIZE);
*************** _realloc_internal (ptr, size)
*** 1471,1477 ****
and copy the lesser of the new size and the old. */
result = _malloc_internal (size);
if (result == NULL)
! return NULL;
memcpy (result, ptr, min (size, (__malloc_size_t) 1 << type));
_free_internal (ptr);
}
--- 1525,1531 ----
and copy the lesser of the new size and the old. */
result = _malloc_internal (size);
if (result == NULL)
! goto out;
memcpy (result, ptr, min (size, (__malloc_size_t) 1 << type));
_free_internal (ptr);
}
*************** _realloc_internal (ptr, size)
*** 1479,1484 ****
--- 1533,1542 ----
}
PROTECT_MALLOC_STATE (1);
+ out:
+ #ifdef USE_PTHREAD
+ pthread_mutex_unlock (&_malloc_mutex);
+ #endif
return result;
}
next prev parent reply other threads:[~2007-03-19 9:31 UTC|newest]
Thread overview: 91+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-23 9:30 Pretest? Juanma Barranquero
2007-02-23 18:06 ` Pretest? Eli Zaretskii
2007-02-23 18:48 ` Pretest? Chong Yidong
2007-02-23 19:36 ` Pretest? Eli Zaretskii
2007-02-24 15:40 ` Pretest? Chong Yidong
2007-02-24 19:07 ` Pretest? Eli Zaretskii
2007-02-25 4:05 ` Pretest? Richard Stallman
2007-02-25 19:33 ` Pretest? Chong Yidong
2007-03-01 23:38 ` Pretest? Chong Yidong
2007-03-02 1:12 ` Pretest? Lennart Borgman (gmail)
2007-03-02 2:01 ` Pretest? Juanma Barranquero
2007-03-02 8:20 ` Pretest? David Kastrup
2007-03-02 9:23 ` Pretest? Juanma Barranquero
2007-03-03 11:40 ` Pretest? Eli Zaretskii
2007-03-04 0:28 ` Pretest? Giorgos Keramidas
2007-03-04 20:25 ` Pretest? Chong Yidong
2007-03-04 20:32 ` Pretest? Giorgos Keramidas
2007-03-04 20:38 ` Pretest? David Kastrup
2007-03-04 20:47 ` Pretest? Giorgos Keramidas
2007-03-05 7:15 ` Pretest? Jan Djärv
2007-03-15 10:39 ` Pretest? YAMAMOTO Mitsuharu
2007-03-15 11:04 ` Pretest? Jan Djärv
2007-03-15 12:08 ` Pretest? YAMAMOTO Mitsuharu
2007-03-16 7:52 ` Pretest? Jan Djärv
2007-03-19 8:00 ` Pretest? Jan Djärv
2007-03-19 9:31 ` YAMAMOTO Mitsuharu [this message]
2007-03-19 21:16 ` Pretest? Giorgos Keramidas
2007-03-20 7:33 ` Pretest? Jan Djärv
2007-03-27 8:07 ` Pretest? Jan Djärv
2007-03-28 8:24 ` Pretest? YAMAMOTO Mitsuharu
2007-03-05 7:13 ` Pretest? Jan Djärv
2007-03-06 9:38 ` Pretest? Piet van Oostrum
2007-03-07 1:03 ` Pretest? Richard Stallman
2007-03-14 7:21 ` Pretest? Piet van Oostrum
2007-03-15 0:39 ` Pretest? YAMAMOTO Mitsuharu
2007-03-15 5:31 ` Pretest? Richard Stallman
2007-03-15 9:33 ` Pretest? YAMAMOTO Mitsuharu
2007-03-16 5:20 ` Pretest? Richard Stallman
2007-03-19 9:53 ` Pretest? YAMAMOTO Mitsuharu
2007-03-19 10:05 ` Pretest? Kim F. Storm
2007-03-19 21:57 ` Pretest? Richard Stallman
2007-03-20 9:18 ` Pretest? YAMAMOTO Mitsuharu
2007-03-15 1:38 ` Pretest? Richard Stallman
-- strict thread matches above, loose matches on Subject: below --
2007-02-23 18:15 cygwin succesfull straight build Eli Zaretskii
2007-03-07 1:26 ` Pretest? Angelo Graziosi
2007-03-08 19:40 ` Pretest? Chong Yidong
2007-03-09 13:59 ` Pretest? Giorgos Keramidas
2007-03-09 14:44 ` Pretest? Chong Yidong
2007-03-09 17:07 ` Pretest? Christian Faulhammer
2007-03-09 17:35 ` Pretest? Juanma Barranquero
2007-03-09 18:33 ` Pretest? Chong Yidong
2007-03-09 17:49 ` Pretest? Eli Zaretskii
2007-03-09 18:07 ` Pretest? Giorgos Keramidas
2007-03-09 21:26 ` Pretest? Richard Stallman
2007-03-12 10:39 ` Pretest? Juanma Barranquero
2007-03-12 10:42 ` Pretest? David Kastrup
2007-03-12 11:46 ` Pretest? Juanma Barranquero
2007-03-12 14:53 ` Pretest? Stefan Monnier
2007-03-12 15:46 ` Pretest? Juanma Barranquero
2007-03-12 15:53 ` Pretest? David Kastrup
2007-03-12 20:55 ` Pretest? Chong Yidong
2007-03-12 21:32 ` Pretest? Juanma Barranquero
2007-03-13 1:03 ` Pretest? Chong Yidong
2007-03-13 9:37 ` Pretest? Juanma Barranquero
2007-03-13 2:43 ` Pretest? Richard Stallman
2007-03-13 9:43 ` Pretest? Juanma Barranquero
2007-03-13 9:52 ` Pretest? Andreas Schwab
2007-03-13 10:09 ` Pretest? David Kastrup
2007-03-13 10:23 ` Pretest? Juanma Barranquero
2007-03-19 5:15 ` Pretest? Richard Stallman
2007-03-14 3:24 ` Pretest? Richard Stallman
2007-03-14 7:10 ` Pretest? David Kastrup
2007-03-14 13:39 ` Pretest? Stefan Monnier
2007-03-14 14:04 ` Pretest? David Kastrup
2007-03-14 14:19 ` Pretest? Stefan Monnier
2007-03-14 9:18 ` Pretest? Juanma Barranquero
2007-03-14 9:32 ` Pretest? David Kastrup
2007-03-14 9:44 ` Pretest? Juanma Barranquero
2007-03-14 10:07 ` Pretest? David Kastrup
2007-03-14 10:17 ` Pretest? Juanma Barranquero
2007-03-14 13:56 ` Pretest? Chong Yidong
2007-03-14 14:24 ` Pretest? Stefan Monnier
2007-03-15 1:38 ` Pretest? Richard Stallman
2007-03-15 10:04 ` Pretest? Juanma Barranquero
2007-03-16 5:20 ` Pretest? Richard Stallman
2007-03-15 15:44 ` Pretest? Chong Yidong
2007-03-16 5:21 ` Pretest? Richard Stallman
2007-03-16 7:36 ` Pretest? David Kastrup
2007-02-26 2:39 Pretest? Nick Roberts
2007-02-26 7:19 ` Pretest? David Kastrup
2007-02-26 9:07 ` Pretest? Nick Roberts
2007-02-26 8:47 ` Pretest? Richard Stallman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=wllkhty3zc.wl%mituharu@math.s.chiba-u.ac.jp \
--to=mituharu@math.s.chiba-u.ac.jp \
--cc=cyd@stupidchicken.com \
--cc=emacs-devel@gnu.org \
--cc=jan.h.d@swipnet.se \
--cc=keramida@ceid.upatras.gr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.