2 Copyright (C) 2012-2016 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/>. */
22 #include <sys/types.h> /* for ssize_t used by regex.h */
26 #include <sys/socket.h>
29 #include "sysselect.h" /* FIXME */
30 #include "systime.h" /* FIXME */
34 struct vectorlike_header header
;
36 /* The buffer in which the last search was performed, or
37 Qt if the last search was done in a string;
38 Qnil if no searching has been done yet. */
39 Lisp_Object m_last_thing_searched
;
40 #define last_thing_searched (current_thread->m_last_thing_searched)
42 Lisp_Object m_saved_last_thing_searched
;
43 #define saved_last_thing_searched (current_thread->m_saved_last_thing_searched)
45 /* The thread's name. */
48 /* The thread's function. */
51 /* If non-nil, this thread has been signaled. */
52 Lisp_Object error_symbol
;
53 Lisp_Object error_data
;
55 /* If we are waiting for some event, this holds the object we are
57 Lisp_Object event_object
;
59 /* m_byte_stack_list must be the first non-lisp field. */
60 /* A list of currently active byte-code execution value stacks.
61 Fbyte_code adds an entry to the head of this list before it starts
62 processing byte-code, and it removed the entry again when it is
63 done. Signaling an error truncates the list. */
64 struct byte_stack
*m_byte_stack_list
;
65 #define byte_stack_list (current_thread->m_byte_stack_list)
67 /* An address near the bottom of the stack.
68 Tells GC how to save a copy of the stack. */
70 #define stack_bottom (current_thread->m_stack_bottom)
72 /* An address near the top of the stack. */
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),
82 this chain is searched for an element that applies. */
83 struct handler
*m_handlerlist
;
84 #define handlerlist (current_thread->m_handlerlist)
86 struct handler
*m_handlerlist_sentinel
;
87 #define handlerlist_sentinel (current_thread->m_handlerlist_sentinel)
89 /* Current number of specbindings allocated in specpdl. */
90 ptrdiff_t m_specpdl_size
;
91 #define specpdl_size (current_thread->m_specpdl_size)
93 /* Pointer to beginning of specpdl. */
94 union specbinding
*m_specpdl
;
95 #define specpdl (current_thread->m_specpdl)
97 /* Pointer to first unused element in specpdl. */
98 union specbinding
*m_specpdl_ptr
;
99 #define specpdl_ptr (current_thread->m_specpdl_ptr)
101 /* Depth in Lisp evaluations and function calls. */
102 EMACS_INT m_lisp_eval_depth
;
103 #define lisp_eval_depth (current_thread->m_lisp_eval_depth)
105 /* This points to the current buffer. */
106 struct buffer
*m_current_buffer
;
107 #define current_buffer (current_thread->m_current_buffer)
109 /* Every call to re_match, etc., must pass &search_regs as the regs
110 argument unless you can show it is unnecessary (i.e., if re_match
111 is certainly going to be called again before region-around-match
114 Since the registers are now dynamically allocated, we need to make
115 sure not to refer to the Nth register before checking that it has
116 been allocated by checking search_regs.num_regs.
118 The regex code keeps track of whether it has allocated the search
119 buffer using bits in the re_pattern_buffer. This means that whenever
120 you compile a new pattern, it completely forgets whether it has
121 allocated any registers, and will allocate new registers the next
122 time you call a searching or matching function. Therefore, we need
123 to call re_set_registers after compiling a new pattern or after
124 setting the match registers, so that the regex functions will be
125 able to free or re-allocate it properly. */
126 struct re_registers m_search_regs
;
127 #define search_regs (current_thread->m_search_regs)
129 /* If non-zero the match data have been saved in saved_search_regs
130 during the execution of a sentinel or filter. */
131 bool m_search_regs_saved
;
132 #define search_regs_saved (current_thread->m_search_regs_saved)
134 struct re_registers m_saved_search_regs
;
135 #define saved_search_regs (current_thread->m_saved_search_regs)
137 /* This is the string or buffer in which we
138 are matching. It is used for looking up syntax properties.
140 If the value is a Lisp string object, we are matching text in that
141 string; if it's nil, we are matching text in the current buffer; if
142 it's t, we are matching text in a C string. */
143 Lisp_Object m_re_match_object
;
144 #define re_match_object (current_thread->m_re_match_object)
146 /* This member is different from waiting_for_input.
147 It is used to communicate to a lisp process-filter/sentinel (via the
148 function Fwaiting_for_user_input_p) whether Emacs was waiting
149 for user-input when that process-filter was called.
150 waiting_for_input cannot be used as that is by definition 0 when
151 lisp code is being evalled.
152 This is also used in record_asynch_buffer_change.
153 For that purpose, this must be 0
154 when not inside wait_reading_process_output. */
155 int m_waiting_for_user_input_p
;
156 #define waiting_for_user_input_p (current_thread->m_waiting_for_user_input_p)
158 /* True while doing kbd input. */
159 bool m_waiting_for_input
;
160 #define waiting_for_input (current_thread->m_waiting_for_input)
162 /* The OS identifier for this thread. */
163 sys_thread_t thread_id
;
165 /* The condition variable for this thread. This is associated with
166 the global lock. This thread broadcasts to it when it exits. */
167 sys_cond_t thread_condvar
;
169 /* This thread might be waiting for some condition. If so, this
170 points to the condition. If the thread is interrupted, the
171 interrupter should broadcast to this condition. */
172 sys_cond_t
*wait_condvar
;
174 /* This thread might have released the global lock. If so, this is
175 non-zero. When a thread runs outside thread_select with this
176 flag non-zero, it means it has been interrupted by SIGINT while
177 in thread_select, and didn't have a chance of acquiring the lock.
178 It must do so ASAP. */
179 int not_holding_lock
;
181 /* Threads are kept on a linked list. */
182 struct thread_state
*next_thread
;
185 /* A mutex in lisp is represented by a system condition variable.
186 The system mutex associated with this condition variable is the
189 Using a condition variable lets us implement interruptibility for
193 /* The owning thread, or NULL if unlocked. */
194 struct thread_state
*owner
;
195 /* The lock count. */
197 /* The underlying system condition variable. */
198 sys_cond_t condition
;
201 /* A mutex as a lisp object. */
204 struct vectorlike_header header
;
206 /* The name of the mutex, or nil. */
209 /* The lower-level mutex object. */
213 /* A condition variable as a lisp object. */
216 struct vectorlike_header header
;
218 /* The associated mutex. */
221 /* The name of the condition variable, or nil. */
224 /* The lower-level condition variable object. */
228 extern struct thread_state
*current_thread
;
230 extern void unmark_threads (void);
231 extern void finalize_one_thread (struct thread_state
*state
);
232 extern void finalize_one_mutex (struct Lisp_Mutex
*);
233 extern void finalize_one_condvar (struct Lisp_CondVar
*);
234 extern void maybe_reacquire_global_lock (void);
236 extern void init_threads_once (void);
237 extern void init_threads (void);
238 extern void syms_of_threads (void);
239 extern bool primary_thread_p (void *);
241 typedef int select_func (int, fd_set
*, fd_set
*, fd_set
*,
242 const struct timespec
*, const sigset_t
*);
244 int thread_select (select_func
*func
, int max_fds
, fd_set
*rfds
,
245 fd_set
*wfds
, fd_set
*efds
, struct timespec
*timeout
,
248 bool thread_check_current_buffer (struct buffer
*);
250 #endif /* THREAD_H */