From: Giuseppe Scrivano Date: Thu, 17 Sep 2009 16:02:09 +0000 (+0200) Subject: Now it is possible to disable threading using "inhibit-yield". X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=c776b1b74b4b57a4e14dc6ca083d749be6cb42dc;p=emacs.git Now it is possible to disable threading using "inhibit-yield". It should be used in a similar way: (defmacro with-no-threading (&rest body) `(unwind-protect (inhibit-yield nil) (progn (inhibit-yield t) ,@body))) --- diff --git a/src/thread.c b/src/thread.c index 2bcea5c54a5..ad43c809d3b 100644 --- a/src/thread.c +++ b/src/thread.c @@ -16,6 +16,8 @@ static struct thread_state *all_threads = &primary_thread; __thread struct thread_state *current_thread = &primary_thread; +static int inhibit_yield_counter = 0; + pthread_mutex_t global_lock; static void @@ -95,6 +97,9 @@ unmark_threads (void) static void thread_yield_callback (char *end, void *ignore) { + if (inhibit_yield_counter) + return; + current_thread->stack_top = end; pthread_mutex_unlock (&global_lock); sched_yield (); @@ -279,6 +284,19 @@ user_thread_p (void) return 0; } +DEFUN ("inhibit-yield", Finhibit_yield, Sinhibit_yield, 1, 1, 0, + doc: /* Inhibit the yield function. */) + (val) + Lisp_Object val; +{ + if (!EQ (val, Qnil)) + inhibit_yield_counter++; + else if (inhibit_yield_counter > 0) + inhibit_yield_counter--; + + return Qnil; +} + int other_threads_p (void) @@ -299,4 +317,5 @@ syms_of_threads (void) { defsubr (&Srun_in_thread); defsubr (&Syield); + defsubr (&Sinhibit_yield); }