From 60a9d2a7728895c1a5bfbc37c3bfa8fde35abe61 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 15 Aug 2012 13:07:04 -0600 Subject: [PATCH] This turns thread_state into a pseudovector and updates various bits of Emacs to cope. --- src/emacs.c | 1 + src/lisp.h | 3 +++ src/print.c | 12 ++++++++++++ src/thread.c | 22 +++++++++++++++++++--- src/thread.h | 3 +++ 5 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/emacs.c b/src/emacs.c index 443fe594795..ca9f201e8f5 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -1226,6 +1226,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem if (!initialized) { init_alloc_once (); + init_threads_once (); init_obarray (); init_eval_once (); init_charset_once (); diff --git a/src/lisp.h b/src/lisp.h index cbb5b51c783..2b3d40d3b29 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -365,6 +365,7 @@ enum pvec_type PVEC_WINDOW_CONFIGURATION, PVEC_SUBR, PVEC_OTHER, + PVEC_THREAD, /* These last 4 are special because we OR them in fns.c:internal_equal, so they have to use a disjoint bit pattern: if (!(size & (PVEC_COMPILED | PVEC_CHAR_TABLE @@ -603,6 +604,7 @@ clip_to_bounds (ptrdiff_t lower, EMACS_INT num, ptrdiff_t upper) #define XSETCHAR_TABLE(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_CHAR_TABLE)) #define XSETBOOL_VECTOR(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_BOOL_VECTOR)) #define XSETSUB_CHAR_TABLE(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_SUB_CHAR_TABLE)) +#define XSETTHREAD(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_THREAD)) /* Convenience macros for dealing with Lisp arrays. */ @@ -1701,6 +1703,7 @@ typedef struct { #define SUB_CHAR_TABLE_P(x) PSEUDOVECTORP (x, PVEC_SUB_CHAR_TABLE) #define BOOL_VECTOR_P(x) PSEUDOVECTORP (x, PVEC_BOOL_VECTOR) #define FRAMEP(x) PSEUDOVECTORP (x, PVEC_FRAME) +#define THREADP(x) PSEUDOVECTORP (x, PVEC_THREAD) /* Test for image (image . spec) */ #define IMAGEP(x) (CONSP (x) && EQ (XCAR (x), Qimage)) diff --git a/src/print.c b/src/print.c index 23ad6c0a256..4537521b9fa 100644 --- a/src/print.c +++ b/src/print.c @@ -1943,6 +1943,18 @@ print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag } PRINTCHAR ('>'); } + else if (THREADP (obj)) + { + strout ("#name)) + print_string (XTHREAD (obj)->name, printcharfun); + else + { + int len = sprintf (buf, "%p", XTHREAD (obj)); + strout (buf, len, len, printcharfun); + } + PRINTCHAR ('>'); + } else { ptrdiff_t size = ASIZE (obj); diff --git a/src/thread.c b/src/thread.c index 605a52cb2f9..7d2f81ec9ce 100644 --- a/src/thread.c +++ b/src/thread.c @@ -32,7 +32,7 @@ sys_mutex_t global_lock; static void mark_one_thread (struct thread_state *thread) { - register struct specbinding *bind; + struct specbinding *bind; struct handler *handler; Lisp_Object tem; @@ -48,7 +48,7 @@ mark_one_thread (struct thread_state *thread) mark_stack (thread->m_stack_bottom, thread->stack_top); #else { - register struct gcpro *tail; + struct gcpro *tail; for (tail = thread->m_gcprolist; tail; tail = tail->next) for (i = 0; i < tail->nvars; i++) mark_object (tail->var[i]); @@ -88,7 +88,13 @@ mark_threads_callback (void *ignore) struct thread_state *iter; for (iter = all_threads; iter; iter = iter->next_thread) - mark_one_thread (iter); + { + Lisp_Object thread_obj; + + XSETTHREAD (thread_obj, iter); + mark_object (thread_obj); + mark_one_thread (iter); + } } void @@ -107,6 +113,16 @@ unmark_threads (void) unmark_byte_stack (iter->m_byte_stack_list); } +void +init_threads_once (void) +{ + the_only_thread.header.size + = PSEUDOVECSIZE (struct thread_state, m_gcprolist); + XSETPVECTYPE (&the_only_thread, PVEC_THREAD); + the_only_thread.m_last_thing_searched = Qnil; + the_only_thread.m_saved_last_thing_searched = Qnil; +} + void init_threads (void) { diff --git a/src/thread.h b/src/thread.h index def05fdaec9..df26b887d1f 100644 --- a/src/thread.h +++ b/src/thread.h @@ -23,6 +23,8 @@ along with GNU Emacs. If not, see . */ struct thread_state { + struct vectorlike_header header; + /* The buffer in which the last search was performed, or Qt if the last search was done in a string; Qnil if no searching has been done yet. */ @@ -150,6 +152,7 @@ extern sys_mutex_t global_lock; extern void unmark_threads (void); +extern void init_threads_once (void); extern void init_threads (void); #endif /* THREAD_H */ -- 2.39.5