aboutsummaryrefslogtreecommitdiffstats
path: root/src/thread.c
diff options
context:
space:
mode:
authorAlan Third2021-06-22 21:46:02 +0100
committerAlan Third2021-07-04 11:36:17 +0100
commit604133ee62b7475f5aa88bd0b2ad9f81145f4ec5 (patch)
tree67d4630598e36fed8334cd97fd49d763a01b36d4 /src/thread.c
parent7a13ddfda0b52d17d845ad390faa3c16005ef453 (diff)
downloademacs-604133ee62b7475f5aa88bd0b2ad9f81145f4ec5.tar.gz
emacs-604133ee62b7475f5aa88bd0b2ad9f81145f4ec5.zip
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.
Diffstat (limited to 'src/thread.c')
-rw-r--r--src/thread.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/thread.c b/src/thread.c
index f74f6111486..714b1cd903a 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/>. */
28#include "pdumper.h" 28#include "pdumper.h"
29#include "keyboard.h" 29#include "keyboard.h"
30 30
31#ifdef HAVE_NS
32#include "nsterm.h"
33#endif
34
31#if defined HAVE_GLIB && ! defined (HAVE_NS) 35#if defined HAVE_GLIB && ! defined (HAVE_NS)
32#include <xgselect.h> 36#include <xgselect.h>
33#else 37#else
@@ -735,6 +739,15 @@ run_thread (void *state)
735 struct thread_state *self = state; 739 struct thread_state *self = state;
736 struct thread_state **iter; 740 struct thread_state **iter;
737 741
742#ifdef HAVE_NS
743 /* Allocate an autorelease pool in case this thread calls any
744 Objective C code.
745
746 FIXME: In long running threads we may want to drain the pool
747 regularly instead of just at the end. */
748 void *pool = ns_alloc_autorelease_pool ();
749#endif
750
738 self->m_stack_bottom = self->stack_top = &stack_pos.c; 751 self->m_stack_bottom = self->stack_top = &stack_pos.c;
739 self->thread_id = sys_thread_self (); 752 self->thread_id = sys_thread_self ();
740 753
@@ -777,6 +790,10 @@ run_thread (void *state)
777 current_thread = NULL; 790 current_thread = NULL;
778 sys_cond_broadcast (&self->thread_condvar); 791 sys_cond_broadcast (&self->thread_condvar);
779 792
793#ifdef HAVE_NS
794 ns_release_autorelease_pool (pool);
795#endif
796
780 /* Unlink this thread from the list of all threads. Note that we 797 /* Unlink this thread from the list of all threads. Note that we
781 have to do this very late, after broadcasting our death. 798 have to do this very late, after broadcasting our death.
782 Otherwise the GC may decide to reap the thread_state object, 799 Otherwise the GC may decide to reap the thread_state object,