aboutsummaryrefslogtreecommitdiffstats
path: root/src/thread.h
diff options
context:
space:
mode:
authorEli Zaretskii2016-12-04 19:59:17 +0200
committerEli Zaretskii2016-12-04 19:59:17 +0200
commitde4624c99ea5bbe38ad5aff7b6461cc5c740d0be (patch)
tree1b57de9e769cdb695cb2cecf157b50f7dea9cfe5 /src/thread.h
parenta486fabb41cdbaa5813c2687fd4008945297d71d (diff)
parente7bde34e939451d87fb42a36195086bdbe48b5e1 (diff)
downloademacs-de4624c99ea5bbe38ad5aff7b6461cc5c740d0be.tar.gz
emacs-de4624c99ea5bbe38ad5aff7b6461cc5c740d0be.zip
Merge branch 'concurrency'
Conflicts (resolved): configure.ac src/Makefile.in src/alloc.c src/bytecode.c src/emacs.c src/eval.c src/lisp.h src/process.c src/regex.c src/regex.h
Diffstat (limited to 'src/thread.h')
-rw-r--r--src/thread.h248
1 files changed, 248 insertions, 0 deletions
diff --git a/src/thread.h b/src/thread.h
new file mode 100644
index 00000000000..a089c7de573
--- /dev/null
+++ b/src/thread.h
@@ -0,0 +1,248 @@
1/* Thread definitions
2 Copyright (C) 2012, 2013 Free Software Foundation, Inc.
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
18
19#ifndef THREAD_H
20#define THREAD_H
21
22#include "regex.h"
23
24#ifdef WINDOWSNT
25#include <sys/socket.h>
26#endif
27
28#include "sysselect.h" /* FIXME */
29#include "systime.h" /* FIXME */
30
31struct thread_state
32{
33 struct vectorlike_header header;
34
35 /* The buffer in which the last search was performed, or
36 Qt if the last search was done in a string;
37 Qnil if no searching has been done yet. */
38 Lisp_Object m_last_thing_searched;
39#define last_thing_searched (current_thread->m_last_thing_searched)
40
41 Lisp_Object m_saved_last_thing_searched;
42#define saved_last_thing_searched (current_thread->m_saved_last_thing_searched)
43
44 /* The thread's name. */
45 Lisp_Object name;
46
47 /* The thread's function. */
48 Lisp_Object function;
49
50 /* If non-nil, this thread has been signalled. */
51 Lisp_Object error_symbol;
52 Lisp_Object error_data;
53
54 /* If we are waiting for some event, this holds the object we are
55 waiting on. */
56 Lisp_Object event_object;
57
58 /* m_byte_stack_list must be the first non-lisp field. */
59 /* A list of currently active byte-code execution value stacks.
60 Fbyte_code adds an entry to the head of this list before it starts
61 processing byte-code, and it removed the entry again when it is
62 done. Signalling an error truncates the list. */
63 struct byte_stack *m_byte_stack_list;
64#define byte_stack_list (current_thread->m_byte_stack_list)
65
66 /* An address near the bottom of the stack.
67 Tells GC how to save a copy of the stack. */
68 char *m_stack_bottom;
69#define stack_bottom (current_thread->m_stack_bottom)
70
71 /* An address near the top of the stack. */
72 char *stack_top;
73
74 struct catchtag *m_catchlist;
75#define catchlist (current_thread->m_catchlist)
76
77 /* Chain of condition handlers currently in effect.
78 The elements of this chain are contained in the stack frames
79 of Fcondition_case and internal_condition_case.
80 When an error is signaled (by calling Fsignal, below),
81 this chain is searched for an element that applies. */
82 struct handler *m_handlerlist;
83#define handlerlist (current_thread->m_handlerlist)
84
85 struct handler *m_handlerlist_sentinel;
86#define handlerlist_sentinel (current_thread->m_handlerlist_sentinel)
87
88 /* Current number of specbindings allocated in specpdl. */
89 ptrdiff_t m_specpdl_size;
90#define specpdl_size (current_thread->m_specpdl_size)
91
92 /* Pointer to beginning of specpdl. */
93 union specbinding *m_specpdl;
94#define specpdl (current_thread->m_specpdl)
95
96 /* Pointer to first unused element in specpdl. */
97 union specbinding *m_specpdl_ptr;
98#define specpdl_ptr (current_thread->m_specpdl_ptr)
99
100 /* Depth in Lisp evaluations and function calls. */
101 EMACS_INT m_lisp_eval_depth;
102#define lisp_eval_depth (current_thread->m_lisp_eval_depth)
103
104 /* This points to the current buffer. */
105 struct buffer *m_current_buffer;
106#define current_buffer (current_thread->m_current_buffer)
107
108 /* Every call to re_match, etc., must pass &search_regs as the regs
109 argument unless you can show it is unnecessary (i.e., if re_match
110 is certainly going to be called again before region-around-match
111 can be called).
112
113 Since the registers are now dynamically allocated, we need to make
114 sure not to refer to the Nth register before checking that it has
115 been allocated by checking search_regs.num_regs.
116
117 The regex code keeps track of whether it has allocated the search
118 buffer using bits in the re_pattern_buffer. This means that whenever
119 you compile a new pattern, it completely forgets whether it has
120 allocated any registers, and will allocate new registers the next
121 time you call a searching or matching function. Therefore, we need
122 to call re_set_registers after compiling a new pattern or after
123 setting the match registers, so that the regex functions will be
124 able to free or re-allocate it properly. */
125 struct re_registers m_search_regs;
126#define search_regs (current_thread->m_search_regs)
127
128 /* If non-zero the match data have been saved in saved_search_regs
129 during the execution of a sentinel or filter. */
130 bool m_search_regs_saved;
131#define search_regs_saved (current_thread->m_search_regs_saved)
132
133 struct re_registers m_saved_search_regs;
134#define saved_search_regs (current_thread->m_saved_search_regs)
135
136 /* This is the string or buffer in which we
137 are matching. It is used for looking up syntax properties.
138
139 If the value is a Lisp string object, we are matching text in that
140 string; if it's nil, we are matching text in the current buffer; if
141 it's t, we are matching text in a C string. */
142 Lisp_Object m_re_match_object;
143#define re_match_object (current_thread->m_re_match_object)
144
145 /* Set by `re_set_syntax' to the current regexp syntax to recognize. Can
146 also be assigned to arbitrarily: each pattern buffer stores its own
147 syntax, so it can be changed between regex compilations. */
148 reg_syntax_t m_re_syntax_options;
149#define re_syntax_options (current_thread->m_re_syntax_options)
150
151 /* Regexp to use to replace spaces, or NULL meaning don't. */
152 /* This ought to be a "const re_char *" but that is not available
153 outside regex.h. */
154 const void *m_whitespace_regexp;
155#define whitespace_regexp (current_thread->m_whitespace_regexp)
156
157 /* This variable is different from waiting_for_input in keyboard.c.
158 It is used to communicate to a lisp process-filter/sentinel (via the
159 function Fwaiting_for_user_input_p) whether Emacs was waiting
160 for user-input when that process-filter was called.
161 waiting_for_input cannot be used as that is by definition 0 when
162 lisp code is being evalled.
163 This is also used in record_asynch_buffer_change.
164 For that purpose, this must be 0
165 when not inside wait_reading_process_output. */
166 int m_waiting_for_user_input_p;
167#define waiting_for_user_input_p (current_thread->m_waiting_for_user_input_p)
168
169 /* The OS identifier for this thread. */
170 sys_thread_t thread_id;
171
172 /* The condition variable for this thread. This is associated with
173 the global lock. This thread broadcasts to it when it exits. */
174 sys_cond_t thread_condvar;
175
176 /* This thread might be waiting for some condition. If so, this
177 points to the condition. If the thread is interrupted, the
178 interrupter should broadcast to this condition. */
179 sys_cond_t *wait_condvar;
180
181 /* Threads are kept on a linked list. */
182 struct thread_state *next_thread;
183};
184
185/* A mutex in lisp is represented by a system condition variable.
186 The system mutex associated with this condition variable is the
187 global lock.
188
189 Using a condition variable lets us implement interruptibility for
190 lisp mutexes. */
191typedef struct
192{
193 /* The owning thread, or NULL if unlocked. */
194 struct thread_state *owner;
195 /* The lock count. */
196 unsigned int count;
197 /* The underlying system condition variable. */
198 sys_cond_t condition;
199} lisp_mutex_t;
200
201/* A mutex as a lisp object. */
202struct Lisp_Mutex
203{
204 struct vectorlike_header header;
205
206 /* The name of the mutex, or nil. */
207 Lisp_Object name;
208
209 /* The lower-level mutex object. */
210 lisp_mutex_t mutex;
211};
212
213/* A condition variable as a lisp object. */
214struct Lisp_CondVar
215{
216 struct vectorlike_header header;
217
218 /* The associated mutex. */
219 Lisp_Object mutex;
220
221 /* The name of the condition variable, or nil. */
222 Lisp_Object name;
223
224 /* The lower-level condition variable object. */
225 sys_cond_t cond;
226};
227
228extern struct thread_state *current_thread;
229
230extern void unmark_threads (void);
231extern void finalize_one_thread (struct thread_state *state);
232extern void finalize_one_mutex (struct Lisp_Mutex *);
233extern void finalize_one_condvar (struct Lisp_CondVar *);
234
235extern void init_threads_once (void);
236extern void init_threads (void);
237extern void syms_of_threads (void);
238
239typedef int select_func (int, fd_set *, fd_set *, fd_set *,
240 struct timespec *, sigset_t *);
241
242int thread_select (select_func *func, int max_fds, fd_set *rfds,
243 fd_set *wfds, fd_set *efds, struct timespec *timeout,
244 sigset_t *sigmask);
245
246bool thread_check_current_buffer (struct buffer *);
247
248#endif /* THREAD_H */