[Top][All Lists]

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

master 604133e 1/3: Fix thread memory management under NS

From: Alan Third
Subject: master 604133e 1/3: Fix thread memory management under NS
Date: Sun, 4 Jul 2021 06:39:59 -0400 (EDT)

branch: master
commit 604133ee62b7475f5aa88bd0b2ad9f81145f4ec5
Author: Alan Third <alan@idiocy.org>
Commit: Alan Third <alan@idiocy.org>

    Fix thread memory management under NS
    * src/thread.c (run_thread): Allocate an autorelease pool so that any
    autoreleased Objective C objects are correctly released.
 src/thread.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/thread.c b/src/thread.c
index f74f611..714b1cd 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -28,6 +28,10 @@ along with GNU Emacs.  If not, see 
<https://www.gnu.org/licenses/>.  */
 #include "pdumper.h"
 #include "keyboard.h"
+#ifdef HAVE_NS
+#include "nsterm.h"
 #if defined HAVE_GLIB && ! defined (HAVE_NS)
 #include <xgselect.h>
@@ -735,6 +739,15 @@ run_thread (void *state)
   struct thread_state *self = state;
   struct thread_state **iter;
+#ifdef HAVE_NS
+  /* Allocate an autorelease pool in case this thread calls any
+     Objective C code.
+     FIXME: In long running threads we may want to drain the pool
+     regularly instead of just at the end.  */
+  void *pool = ns_alloc_autorelease_pool ();
   self->m_stack_bottom = self->stack_top = &stack_pos.c;
   self->thread_id = sys_thread_self ();
@@ -777,6 +790,10 @@ run_thread (void *state)
   current_thread = NULL;
   sys_cond_broadcast (&self->thread_condvar);
+#ifdef HAVE_NS
+  ns_release_autorelease_pool (pool);
   /* Unlink this thread from the list of all threads.  Note that we
      have to do this very late, after broadcasting our death.
      Otherwise the GC may decide to reap the thread_state object,

reply via email to

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