summaryrefslogtreecommitdiff
path: root/src/thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/thread.c')
-rw-r--r--src/thread.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/thread.c b/src/thread.c
index 39a21518ec6..f060a002a3a 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -55,15 +55,20 @@ static void
post_acquire_global_lock (struct thread_state *self)
{
Lisp_Object buffer;
+ struct thread_state *prev_thread = current_thread;
- if (self != current_thread)
+ /* Do this early on, so that code below could signal errors (e.g.,
+ unbind_for_thread_switch might) correctly, because we are already
+ running in the context of the thread pointed by SELF. */
+ current_thread = self;
+
+ if (prev_thread != current_thread)
{
- /* CURRENT_THREAD is NULL if the previously current thread
+ /* PREV_THREAD is NULL if the previously current thread
exited. In this case, there is no reason to unbind, and
trying will crash. */
- if (current_thread != NULL)
- unbind_for_thread_switch ();
- current_thread = self;
+ if (prev_thread != NULL)
+ unbind_for_thread_switch (prev_thread);
rebind_for_thread_switch ();
}