This adds thread-blocker, a function to examine what a thread is
[emacs.git] / src / thread.h
blobd21887a09289b983614536487b90b3979c8d9176
1 /* Thread definitions
2 Copyright (C) 2012 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19 #ifndef THREAD_H
20 #define THREAD_H
22 #include "regex.h"
24 struct thread_state
26 struct vectorlike_header header;
28 /* The buffer in which the last search was performed, or
29 Qt if the last search was done in a string;
30 Qnil if no searching has been done yet. */
31 Lisp_Object m_last_thing_searched;
32 #define last_thing_searched (current_thread->m_last_thing_searched)
34 Lisp_Object m_saved_last_thing_searched;
35 #define saved_last_thing_searched (current_thread->m_saved_last_thing_searched)
37 /* The thread's name. */
38 Lisp_Object name;
40 /* The thread's function. */
41 Lisp_Object function;
43 /* If non-nil, this thread has been signalled. */
44 Lisp_Object error_symbol;
45 Lisp_Object error_data;
47 /* If we are waiting for some event, this holds the object we are
48 waiting on. */
49 Lisp_Object event_object;
51 /* m_gcprolist must be the first non-lisp field. */
52 /* Recording what needs to be marked for gc. */
53 struct gcpro *m_gcprolist;
54 #define gcprolist (current_thread->m_gcprolist)
56 /* A list of currently active byte-code execution value stacks.
57 Fbyte_code adds an entry to the head of this list before it starts
58 processing byte-code, and it removed the entry again when it is
59 done. Signalling an error truncates the list analoguous to
60 gcprolist. */
61 struct byte_stack *m_byte_stack_list;
62 #define byte_stack_list (current_thread->m_byte_stack_list)
64 /* An address near the bottom of the stack.
65 Tells GC how to save a copy of the stack. */
66 char *m_stack_bottom;
67 #define stack_bottom (current_thread->m_stack_bottom)
69 /* An address near the top of the stack. */
70 char *stack_top;
72 struct backtrace *m_backtrace_list;
73 #define backtrace_list (current_thread->m_backtrace_list)
75 struct catchtag *m_catchlist;
76 #define catchlist (current_thread->m_catchlist)
78 /* Chain of condition handlers currently in effect.
79 The elements of this chain are contained in the stack frames
80 of Fcondition_case and internal_condition_case.
81 When an error is signaled (by calling Fsignal, below),
82 this chain is searched for an element that applies. */
83 struct handler *m_handlerlist;
84 #define handlerlist (current_thread->m_handlerlist)
86 /* Count levels of GCPRO to detect failure to UNGCPRO. */
87 int m_gcpro_level;
88 #define gcpro_level (current_thread->m_gcpro_level)
90 /* Current number of specbindings allocated in specpdl. */
91 ptrdiff_t m_specpdl_size;
92 #define specpdl_size (current_thread->m_specpdl_size)
94 /* Pointer to beginning of specpdl. */
95 struct specbinding *m_specpdl;
96 #define specpdl (current_thread->m_specpdl)
98 /* Pointer to first unused element in specpdl. */
99 struct specbinding *m_specpdl_ptr;
100 #define specpdl_ptr (current_thread->m_specpdl_ptr)
102 /* Pointer to the first "saved" element in specpdl. When this
103 thread is swapped out, the current values of all specpdl bindings
104 are pushed onto the specpdl; then these are popped again when
105 switching back to this thread. */
106 struct specbinding *m_saved_specpdl_ptr;
108 /* Depth in Lisp evaluations and function calls. */
109 EMACS_INT m_lisp_eval_depth;
110 #define lisp_eval_depth (current_thread->m_lisp_eval_depth)
112 /* This points to the current buffer. */
113 struct buffer *m_current_buffer;
114 #define current_buffer (current_thread->m_current_buffer)
116 /* Every call to re_match, etc., must pass &search_regs as the regs
117 argument unless you can show it is unnecessary (i.e., if re_match
118 is certainly going to be called again before region-around-match
119 can be called).
121 Since the registers are now dynamically allocated, we need to make
122 sure not to refer to the Nth register before checking that it has
123 been allocated by checking search_regs.num_regs.
125 The regex code keeps track of whether it has allocated the search
126 buffer using bits in the re_pattern_buffer. This means that whenever
127 you compile a new pattern, it completely forgets whether it has
128 allocated any registers, and will allocate new registers the next
129 time you call a searching or matching function. Therefore, we need
130 to call re_set_registers after compiling a new pattern or after
131 setting the match registers, so that the regex functions will be
132 able to free or re-allocate it properly. */
133 struct re_registers m_search_regs;
134 #define search_regs (current_thread->m_search_regs)
136 /* If non-zero the match data have been saved in saved_search_regs
137 during the execution of a sentinel or filter. */
138 int m_search_regs_saved;
139 #define search_regs_saved (current_thread->m_search_regs_saved)
141 struct re_registers m_saved_search_regs;
142 #define saved_search_regs (current_thread->m_saved_search_regs)
144 /* This is the string or buffer in which we
145 are matching. It is used for looking up syntax properties. */
146 Lisp_Object m_re_match_object;
147 #define re_match_object (current_thread->m_re_match_object)
149 /* Set by `re_set_syntax' to the current regexp syntax to recognize. Can
150 also be assigned to arbitrarily: each pattern buffer stores its own
151 syntax, so it can be changed between regex compilations. */
152 reg_syntax_t m_re_syntax_options;
153 #define re_syntax_options (current_thread->m_re_syntax_options)
155 /* Regexp to use to replace spaces, or NULL meaning don't. */
156 /*re_char*/ unsigned char *m_whitespace_regexp;
157 #define whitespace_regexp (current_thread->m_whitespace_regexp)
159 /* The OS identifier for this thread. */
160 sys_thread_t thread_id;
162 /* The condition variable for this thread. This is associated with
163 the global lock. This thread broadcasts to it when it exits. */
164 sys_cond_t thread_condvar;
166 /* This thread might be waiting for some condition. If so, this
167 points to the condition. If the thread is interrupted, the
168 interrupter should broadcast to this condition. */
169 sys_cond_t *wait_condvar;
171 /* Threads are kept on a linked list. */
172 struct thread_state *next_thread;
175 struct Lisp_Mutex
177 struct vectorlike_header header;
179 Lisp_Object name;
181 lisp_mutex_t mutex;
184 extern struct thread_state *current_thread;
186 extern sys_mutex_t global_lock;
187 extern void post_acquire_global_lock (struct thread_state *);
189 extern void unmark_threads (void);
190 extern void finalize_one_thread (struct thread_state *state);
191 extern void finalize_one_mutex (struct Lisp_Mutex *);
193 extern void init_threads_once (void);
194 extern void init_threads (void);
195 extern void syms_of_threads (void);
197 #endif /* THREAD_H */