From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: YAMAMOTO Mitsuharu Newsgroups: gmane.emacs.bugs Subject: Re: High CPU load Date: Thu, 29 Nov 2007 11:21:20 +0900 Organization: Faculty of Science, Chiba University Message-ID: References: <50C9A1E3-35A9-4B7D-8F86-46E9995D6D35@gmail.com> <20071127.220645.53363870.mituharu@math.s.chiba-u.ac.jp> <26C09430-463C-4F04-972D-36039C495E74@gmail.com> <2720AEE2-B989-4F54-81DC-B25A72E0BF6E@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII X-Trace: ger.gmane.org 1196302980 17800 80.91.229.12 (29 Nov 2007 02:23:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 29 Nov 2007 02:23:00 +0000 (UTC) Cc: bug-gnu-emacs@gnu.org, Ugur Ozdemir , Seiji Zenitani To: David Reitter Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Nov 29 03:23:08 2007 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IxZ3S-0002XU-Nv for geb-bug-gnu-emacs@m.gmane.org; Thu, 29 Nov 2007 03:23:07 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IxZ3D-0000Uu-24 for geb-bug-gnu-emacs@m.gmane.org; Wed, 28 Nov 2007 21:22:51 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IxZ1o-0007Oh-Fp for bug-gnu-emacs@gnu.org; Wed, 28 Nov 2007 21:21:24 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IxZ1n-0007Nn-Lh for bug-gnu-emacs@gnu.org; Wed, 28 Nov 2007 21:21:24 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IxZ1n-0007Nf-FW for bug-gnu-emacs@gnu.org; Wed, 28 Nov 2007 21:21:23 -0500 Original-Received: from mathmail.math.s.chiba-u.ac.jp ([133.82.132.2]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IxZ1m-0003Hr-Q0 for bug-gnu-emacs@gnu.org; Wed, 28 Nov 2007 21:21:23 -0500 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 CB0602C44; Thu, 29 Nov 2007 11:21:20 +0900 (JST) In-Reply-To: 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/23.0.50 (sparc-sun-solaris2.8) MULE/5.0 (SAKAKI) X-detected-kernel: by monty-python.gnu.org: NetBSD 3.0 (DF) X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:17087 Archived-At: >>>>> On Thu, 29 Nov 2007 01:09:20 +0000, David Reitter said: > On 29 Nov 2007, at 00:33, YAMAMOTO Mitsuharu wrote: >> >> 1. Create 7 instances of shell buffers using C-u M-x shell >> repeatedly. >> 2. Kill all the shell buffers. >> 3. Open a file dialog and cancel it. > This does not produce the problem on Aquamacs. You may need to adjust the number of shell buffers to create/kill using the output of `lsof' command so the reuse of a file descriptor can happen between Emacs and SystemNotification threads. >> Please try the following patch. It invalidates CFSocket objects every >> time to avoid the above situation. > Okay, but your patch doesn't apply to version 1.77.2.3 of mac.c > despite some nudging. (I don't understand why, though.) Could you send > another one, please? Invalidation of CFSocket in every sys_select call turned out to be problematic in another situation, anyway. Here is another patch that the invalidation is done via emacs_close call. YAMAMOTO Mitsuharu mituharu@math.s.chiba-u.ac.jp Index: src/mac.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/mac.c,v retrieving revision 1.77.2.3 diff -c -p -r1.77.2.3 mac.c *** src/mac.c 1 Aug 2007 22:20:41 -0000 1.77.2.3 --- src/mac.c 29 Nov 2007 02:11:40 -0000 *************** extern int noninteractive; *** 5009,5014 **** --- 5009,5016 ---- #if SELECT_USE_CFSOCKET #define SELECT_TIMEOUT_THRESHOLD_RUNLOOP 0.2 + static CFMutableDictionaryRef mac_cf_sockets; + static void socket_callback (s, type, address, data, info) CFSocketRef s; *************** select_and_poll_event (nfds, rfds, wfds, *** 5079,5084 **** --- 5081,5110 ---- } int + mac_try_close_socket (fd) + int fd; + { + #if SELECT_USE_CFSOCKET + if (mac_cf_sockets) + { + void *key = (void *) fd; + CFSocketRef socket = + (CFSocketRef) CFDictionaryGetValue (mac_cf_sockets, key); + + if (socket) + { + CFSocketInvalidate (socket); + CFDictionaryRemoveValue (mac_cf_sockets, key); + + return 1; + } + } + #endif + + return 0; + } + + int sys_select (nfds, rfds, wfds, efds, timeout) int nfds; SELECT_TYPE *rfds, *wfds, *efds; *************** sys_select (nfds, rfds, wfds, efds, time *** 5156,5161 **** --- 5182,5192 ---- CFDictionaryCreateMutable (NULL, 0, NULL, &kCFTypeDictionaryValueCallBacks); + if (mac_cf_sockets == NULL) + mac_cf_sockets = + CFDictionaryCreateMutable (NULL, 0, NULL, + &kCFTypeDictionaryValueCallBacks); + for (minfd = 1; ; minfd++) /* nfds-1 works as a sentinel. */ if (FD_ISSET (minfd, rfds) || (wfds && FD_ISSET (minfd, wfds))) break; *************** sys_select (nfds, rfds, wfds, efds, time *** 5167,5173 **** CFRunLoopSourceRef source = (CFRunLoopSourceRef) CFDictionaryGetValue (sources, key); ! if (source == NULL) { CFSocketRef socket = CFSocketCreateWithNative (NULL, fd, --- 5198,5204 ---- CFRunLoopSourceRef source = (CFRunLoopSourceRef) CFDictionaryGetValue (sources, key); ! if (source == NULL || !CFRunLoopSourceIsValid (source)) { CFSocketRef socket = CFSocketCreateWithNative (NULL, fd, *************** sys_select (nfds, rfds, wfds, efds, time *** 5177,5182 **** --- 5208,5214 ---- if (socket == NULL) continue; + CFDictionaryAddValue (mac_cf_sockets, key, socket); source = CFSocketCreateRunLoopSource (NULL, socket, 0); CFRelease (socket); if (source == NULL) Index: src/sysdep.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/sysdep.c,v retrieving revision 1.279.2.1 diff -c -p -r1.279.2.1 sysdep.c *** src/sysdep.c 25 Jul 2007 05:15:36 -0000 1.279.2.1 --- src/sysdep.c 29 Nov 2007 02:11:40 -0000 *************** emacs_close (fd) *** 3320,3325 **** --- 3320,3334 ---- int did_retry = 0; register int rtnval; + #if defined (MAC_OSX) && defined (HAVE_CARBON) + { + extern int mac_try_close_socket P_ ((int)); + + if (mac_try_close_socket (fd)) + return 0; + } + #endif + while ((rtnval = close (fd)) == -1 && (errno == EINTR)) did_retry = 1;