bug-gnu-emacs
[Top][All Lists]
Advanced

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

Re: High CPU load


From: YAMAMOTO Mitsuharu
Subject: Re: High CPU load
Date: Thu, 29 Nov 2007 11:21:20 +0900
User-agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.8 (Shij┼Ź) APEL/10.6 Emacs/23.0.50 (sparc-sun-solaris2.8) MULE/5.0 (SAKAKI)

>>>>> On Thu, 29 Nov 2007 01:09:20 +0000, David Reitter <address@hidden> 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
                                address@hidden

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;




reply via email to

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