* [PATCH 05/10] make thread_state into a real lisp object
@ 2012-08-09 19:41 Tom Tromey
0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2012-08-09 19:41 UTC (permalink / raw)
To: Emacs discussions
This turns thread_state into a pseudovector and updates various bits
of Emacs to cope.
I don't think this patch will actually compile without a later patch as
well. I haven't really been trying that, the patch splitting is really
just to make them easier to reason about.
In particular, this code refers to the thread's name, but that field
isn't added yet.
I can fix this up if you want each patch to build properly.
---
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 443fe59..ca9f201 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 fbde5bb..7d0a3dc 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -364,6 +364,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
@@ -602,6 +603,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. */
@@ -1700,6 +1702,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 718e6a9..d879239 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 ("#<thread ", -1, -1, printcharfun);
+ if (STRINGP (XTHREAD (obj)->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 605a52c..7d2f81e 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
@@ -108,6 +114,16 @@ unmark_threads (void)
}
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)
{
sys_mutex_init (&global_lock);
diff --git a/src/thread.h b/src/thread.h
index def05fd..df26b88 100644
--- a/src/thread.h
+++ b/src/thread.h
@@ -23,6 +23,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
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 */
--
1.7.7.6
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2012-08-09 19:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-09 19:41 [PATCH 05/10] make thread_state into a real lisp object Tom Tromey
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.