diff src/profile.c @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents c0965ff3b039
children 9f59509498e1
line wrap: on
line diff
--- a/src/profile.c	Mon Aug 13 09:00:04 2007 +0200
+++ b/src/profile.c	Mon Aug 13 09:02:59 2007 +0200
@@ -63,63 +63,38 @@
 Lisp_Object QSprocessing_events_at_top_level;
 Lisp_Object QSunknown;
 
-/* We use inside_profiling to prevent the handler from writing to
-   the table while another routine is operating on it.  We also set
-   inside_profiling in case the timeout between signal calls is short
-   enough to catch us while we're already in there. */
-static volatile int inside_profiling;
-
 static SIGTYPE
 sigprof_handler (int signo)
 {
-  /* Don't do anything if we are shutting down, or are doing a maphash
-     or clrhash on the table. */
-  if (!inside_profiling && !preparing_for_armageddon)
-    {
-      Lisp_Object fun;
+  Lisp_Object fun;
 
-      /* If something below causes an error to be signaled, we'll
-	 not correctly reset this flag.  But we'll be in worse shape
-	 than that anyways, since we'll longjmp back to the last
-	 condition case. */
-      inside_profiling = 1;
-
-      if (profiling_redisplay_flag)
-	fun = QSin_redisplay;
-      else if (gc_in_progress)
-	fun = QSin_garbage_collection;
-      else if (backtrace_list)
-	{
-	  fun = *backtrace_list->function;
+  if (profiling_redisplay_flag)
+    fun = QSin_redisplay;
+  else if (gc_in_progress)
+    fun = QSin_garbage_collection;
+  else if (backtrace_list)
+    {
+      fun = *backtrace_list->function;
 
-	  /* #### dmoore - why do we need to unmark it, we aren't in GC. */
-	  XUNMARK (fun);
-	  if (!GC_SYMBOLP (fun) && !GC_COMPILED_FUNCTIONP (fun))
-	    fun = QSunknown;
-	}
-      else
-	fun = QSprocessing_events_at_top_level;
+      XUNMARK (fun);
+      if (!GC_SYMBOLP (fun) && !GC_COMPILED_FUNCTIONP (fun))
+        fun = QSunknown;
+    }
+  else
+    fun = QSprocessing_events_at_top_level;
 
-      {
-	/* #### see comment about memory allocation in start-profiling.
-	   Allocating memory in a signal handler is BAD BAD BAD.
-	   If you are using the non-mmap rel-alloc code, you might
-	   lose because of this.  Even worse, if the memory allocation 
-	   fails, the `error' generated whacks everything hard. */
-	long count;
-	CONST void *vval;
+  {
+    long count;
+    CONST void *vval;
     
-	if (gethash (LISP_TO_VOID (fun), big_profile_table, &vval))
-	  count = (long) vval;
-	else
-	  count = 0;
-	count++;
-	vval = (CONST void *) count;
-	puthash (LISP_TO_VOID (fun), (void *) vval, big_profile_table);
-      }
-      
-      inside_profiling = 0;
-    }
+    if (gethash (LISP_TO_VOID (fun), big_profile_table, &vval))
+      count = (long) vval;
+    else
+      count = 0;
+    count++;
+    vval = (CONST void *) count;
+    puthash (LISP_TO_VOID (fun), (void *) vval, big_profile_table);
+  }
 }
 
 DEFUN ("start-profiling", Fstart_profiling, 0, 1, 0, /*
@@ -135,7 +110,6 @@
 */
        (microsecs))
 {
-  /* This function can GC */
   int msecs;
   struct itimerval foo;
 
@@ -162,7 +136,6 @@
   EMACS_NORMALIZE_TIME (foo.it_value);
   foo.it_interval = foo.it_value;
   profiling_active = 1;
-  inside_profiling = 0;
   setitimer (ITIMER_PROF, &foo, 0);
   return Qnil;
 }
@@ -172,7 +145,6 @@
 */
        ())
 {
-  /* This function does not GC */
   struct itimerval foo;
 
   foo.it_value.tv_sec = 0;
@@ -184,13 +156,6 @@
   return Qnil;
 }
 
-static Lisp_Object
-profile_lock_unwind (Lisp_Object ignore)
-{
-  inside_profiling = 0;	
-  return Qnil;
-}
-
 struct get_profiling_info_closure
 {
   Lisp_Object accum;
@@ -201,7 +166,7 @@
 			    void *void_val,
 			    void *void_closure)
 {
-  /* This function does not GC */
+  /* This function can GC */
   Lisp_Object key;
   struct get_profiling_info_closure *closure = void_closure;
   EMACS_INT val;
@@ -218,18 +183,11 @@
 */
        ())
 {
-  /* This function does not GC */
   struct get_profiling_info_closure closure;
 
   closure.accum = Qnil;
   if (big_profile_table)
-    {
-      int count = specpdl_depth ();
-      record_unwind_protect (profile_lock_unwind, Qnil);
-      inside_profiling = 1;
-      maphash (get_profiling_info_maphash, big_profile_table, &closure);
-      unbind_to (count, Qnil);
-    }
+    maphash (get_profiling_info_maphash, big_profile_table, &closure);
   return closure.accum;
 }
 
@@ -243,6 +201,7 @@
 			     void *void_val,
 			     void *void_closure)
 {
+  /* This function can GC */
   Lisp_Object key;
   struct mark_profiling_info_closure *closure = void_closure;
 
@@ -253,16 +212,11 @@
 void
 mark_profiling_info (void (*markfun) (Lisp_Object))
 {
-  /* This function does not GC (if markfun doesn't) */
   struct mark_profiling_info_closure closure;
 
   closure.markfun = markfun;
   if (big_profile_table)
-    {
-      inside_profiling = 1;
-      maphash (mark_profiling_info_maphash, big_profile_table, &closure);
-      inside_profiling = 0;
-    }
+    maphash (mark_profiling_info_maphash, big_profile_table, &closure);
 }
 
 DEFUN ("clear-profiling-info", Fclear_profiling_info, 0, 0, 0, /*
@@ -270,13 +224,8 @@
 */
        ())
 {
-  /* This function does not GC */
   if (big_profile_table)
-    {
-      inside_profiling = 1;
-      clrhash (big_profile_table);
-      inside_profiling = 0;
-    }
+    clrhash (big_profile_table);
   return Qnil;
 }
 
@@ -309,8 +258,6 @@
 */ );
   default_profiling_interval = 1000;
 
-  inside_profiling = 0;
-
   QSin_redisplay = build_string ("(in redisplay)");
   staticpro (&QSin_redisplay);
   QSin_garbage_collection = build_string ("(in garbage collection)");