From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: YAMAMOTO Mitsuharu Newsgroups: gmane.emacs.devel Subject: Re: Pretest? Date: Mon, 19 Mar 2007 18:31:03 +0900 Organization: Faculty of Science, Chiba University Message-ID: References: <45EBC39C.1080706@swipnet.se> <45F92841.3090600@swipnet.se> <20070315.210810.236560633.mituharu@math.s.chiba-u.ac.jp> <45FA4CD2.1010406@swipnet.se> <45FE430A.5070703@swipnet.se> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: sea.gmane.org 1174296690 17322 80.91.229.12 (19 Mar 2007 09:31:30 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 19 Mar 2007 09:31:30 +0000 (UTC) Cc: keramida@ceid.upatras.gr, cyd@stupidchicken.com, emacs-devel@gnu.org To: Jan =?ISO-8859-1?Q?Dj=E4rv?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Mar 19 10:31:21 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HTED1-00034e-QC for ged-emacs-devel@m.gmane.org; Mon, 19 Mar 2007 10:31:20 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HTEET-000225-Pi for ged-emacs-devel@m.gmane.org; Mon, 19 Mar 2007 04:32:49 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HTEEQ-000220-Ck for emacs-devel@gnu.org; Mon, 19 Mar 2007 05:32:46 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HTEEN-00021o-Pv for emacs-devel@gnu.org; Mon, 19 Mar 2007 05:32:45 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HTEEN-00021l-Jv for emacs-devel@gnu.org; Mon, 19 Mar 2007 04:32:43 -0500 Original-Received: from ntp.math.s.chiba-u.ac.jp ([133.82.132.2] helo=mathmail.math.s.chiba-u.ac.jp) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1HTECu-0001Kh-6k for emacs-devel@gnu.org; Mon, 19 Mar 2007 05:31:13 -0400 Original-Received: from church.math.s.chiba-u.ac.jp (church [133.82.132.36]) by mathmail.math.s.chiba-u.ac.jp (Postfix) with ESMTP id B81122C5F; Mon, 19 Mar 2007 18:31:03 +0900 (JST) In-Reply-To: <45FE430A.5070703@swipnet.se> User-Agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.8 (=?ISO-8859-4?Q?Shij=F2?=) APEL/10.6 Emacs/22.0.95 (sparc-sun-solaris2.8) MULE/5.0 (SAKAKI) X-detected-kernel: NetBSD 3.0 (DF) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:68086 Archived-At: >>>>> On Mon, 19 Mar 2007 09:00:10 +0100, Jan Dj=E4rv = 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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. */ =20 #define _MALLOC_INTERNAL + #ifdef HAVE_GTK_AND_PTHREAD + #define USE_PTHREAD + #endif =20 /* The malloc headers and source files from the C library follow here. */ =20 *************** Fifth Floor, Boston, MA 02110-1301, USA. *** 73,78 **** --- 76,85 ---- #include #endif =20 + #ifdef USE_PTHREAD + #include + #endif +=20 #endif /* _MALLOC_INTERNAL. */ =20 =20 *************** extern __ptr_t _malloc_internal PP ((__m *** 229,234 **** --- 236,244 ---- extern __ptr_t _realloc_internal PP ((__ptr_t __ptr, __malloc_size_t __si= ze)); extern void _free_internal PP ((__ptr_t __ptr)); =20 + #ifdef USE_PTHREAD + extern pthread_mutex_t _malloc_mutex; + #endif #endif /* _MALLOC_INTERNAL. */ =20 /* Given an address in the middle of a malloc'd object, *************** register_heapinfo () *** 536,548 **** _heapinfo[block + blocks].busy.info.size =3D -blocks; } =20 ! /* Set everything up and remember that we have. */ ! int ! __malloc_initialize () ! { ! if (__malloc_initialized) ! return 0; =20 #ifdef GC_MCHECK mcheck (NULL); #endif --- 546,559 ---- _heapinfo[block + blocks].busy.info.size =3D -blocks; } =20 ! #ifdef USE_PTHREAD ! static pthread_once_t malloc_init_once_control =3D PTHREAD_ONCE_INIT; ! pthread_mutex_t _malloc_mutex; ! #endif =20 + static void + malloc_initialize_1 () + { #ifdef GC_MCHECK mcheck (NULL); #endif *************** __malloc_initialize () *** 550,559 **** if (__malloc_initialize_hook) (*__malloc_initialize_hook) (); =20 heapsize =3D HEAP / BLOCKSIZE; _heapinfo =3D (malloc_info *) align (heapsize * sizeof (malloc_info)); if (_heapinfo =3D=3D NULL) ! return 0; memset (_heapinfo, 0, heapsize * sizeof (malloc_info)); _heapinfo[0].free.size =3D 0; _heapinfo[0].free.next =3D _heapinfo[0].free.prev =3D 0; --- 561,581 ---- if (__malloc_initialize_hook) (*__malloc_initialize_hook) (); =20 + #ifdef USE_PTHREAD + { + pthread_mutexattr_t attr; +=20 + pthread_mutexattr_init (&attr); + pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init (&_malloc_mutex, &attr); + pthread_mutexattr_destroy (&attr); + } + #endif +=20 heapsize =3D HEAP / BLOCKSIZE; _heapinfo =3D (malloc_info *) align (heapsize * sizeof (malloc_info)); if (_heapinfo =3D=3D NULL) ! return; memset (_heapinfo, 0, heapsize * sizeof (malloc_info)); _heapinfo[0].free.size =3D 0; _heapinfo[0].free.next =3D _heapinfo[0].free.prev =3D 0; *************** __malloc_initialize () *** 565,571 **** =20 __malloc_initialized =3D 1; PROTECT_MALLOC_STATE (1); ! return 1; } =20 static int morecore_recursing; --- 587,609 ---- =20 __malloc_initialized =3D 1; PROTECT_MALLOC_STATE (1); ! return; ! } !=20 ! /* 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; !=20 ! malloc_initialize_1 (); ! #endif !=20 ! return __malloc_initialized; } =20 static int morecore_recursing; *************** _malloc_internal (size) *** 708,713 **** --- 746,754 ---- return NULL; #endif =20 + #ifdef USE_PTHREAD + pthread_mutex_lock (&_malloc_mutex); + #endif PROTECT_MALLOC_STATE (0); =20 if (size < sizeof (struct list)) *************** _malloc_internal (size) *** 765,771 **** if (result =3D=3D NULL) { PROTECT_MALLOC_STATE (1); ! return NULL; } =20 /* Link all fragments but the first into the free list. */ --- 806,812 ---- if (result =3D=3D NULL) { PROTECT_MALLOC_STATE (1); ! goto out; } =20 /* Link all fragments but the first into the free list. */ *************** _malloc_internal (size) *** 831,837 **** } result =3D morecore (wantblocks * BLOCKSIZE); if (result =3D=3D NULL) ! return NULL; block =3D BLOCK (result); /* Put the new block at the end of the free list. */ _heapinfo[block].free.size =3D wantblocks; --- 872,878 ---- } result =3D morecore (wantblocks * BLOCKSIZE); if (result =3D=3D NULL) ! goto out; block =3D BLOCK (result); /* Put the new block at the end of the free list. */ _heapinfo[block].free.size =3D wantblocks; *************** _malloc_internal (size) *** 886,891 **** --- 927,936 ---- } =20 PROTECT_MALLOC_STATE (1); + out: + #ifdef USE_PTHREAD + pthread_mutex_unlock (&_malloc_mutex); + #endif return result; } =20 *************** _free_internal (ptr) *** 996,1001 **** --- 1041,1049 ---- if (ptr =3D=3D NULL) return; =20 + #ifdef USE_PTHREAD + pthread_mutex_lock (&_malloc_mutex); + #endif PROTECT_MALLOC_STATE (0); =20 for (l =3D _aligned_blocks; l !=3D NULL; l =3D l->next) *************** _free_internal (ptr) *** 1221,1226 **** --- 1269,1277 ---- } =20 PROTECT_MALLOC_STATE (1); + #ifdef USE_PTHREAD + pthread_mutex_unlock (&_malloc_mutex); + #endif } =20 /* Return memory to the heap. */ *************** _realloc_internal (ptr, size) *** 1384,1389 **** --- 1435,1443 ---- =20 block =3D BLOCK (ptr); =20 + #ifdef USE_PTHREAD + pthread_mutex_lock (&_malloc_mutex); + #endif PROTECT_MALLOC_STATE (0); =20 type =3D _heapinfo[block].busy.type; *************** _realloc_internal (ptr, size) *** 1398,1404 **** { memcpy (result, ptr, size); _free_internal (ptr); ! return result; } } =20 --- 1452,1458 ---- { memcpy (result, ptr, size); _free_internal (ptr); ! goto out; } } =20 *************** _realloc_internal (ptr, size) *** 1451,1457 **** (void) _malloc_internal (blocks * BLOCKSIZE); _free_internal (previous); } ! return NULL; } if (ptr !=3D result) memmove (result, ptr, blocks * BLOCKSIZE); --- 1505,1511 ---- (void) _malloc_internal (blocks * BLOCKSIZE); _free_internal (previous); } ! goto out; } if (ptr !=3D result) memmove (result, ptr, blocks * BLOCKSIZE); *************** _realloc_internal (ptr, size) *** 1471,1477 **** and copy the lesser of the new size and the old. */ result =3D _malloc_internal (size); if (result =3D=3D 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 =3D _malloc_internal (size); if (result =3D=3D NULL) ! goto out; memcpy (result, ptr, min (size, (__malloc_size_t) 1 << type)); _free_internal (ptr); } *************** _realloc_internal (ptr, size) *** 1479,1484 **** --- 1533,1542 ---- } =20 PROTECT_MALLOC_STATE (1); + out: + #ifdef USE_PTHREAD + pthread_mutex_unlock (&_malloc_mutex); + #endif return result; } =20