Use libpng-config --ldflags, not --libs
[emacs.git] / src / thread.h
blobb8524014ea43786f31097a0dfdca6a725ad3f9d8
1 /* Thread definitions
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/>. */
19 #ifndef THREAD_H
20 #define THREAD_H
22 #include <sys/types.h> /* for ssize_t used by regex.h */
23 #include "regex.h"
25 #ifdef WINDOWSNT
26 #include <sys/socket.h>
27 #endif
29 #include "sysselect.h" /* FIXME */
30 #include "systime.h" /* FIXME */
32 struct thread_state
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. */
46 Lisp_Object name;
48 /* The thread's function. */
49 Lisp_Object 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
56 waiting on. */
57 Lisp_Object event_object;
59 /* m_stack_bottom must be the first non-Lisp field. */
60 /* An address near the bottom of the stack.
61 Tells GC how to save a copy of the stack. */
62 char *m_stack_bottom;
63 #define stack_bottom (current_thread->m_stack_bottom)
65 /* An address near the top of the stack. */
66 char *stack_top;
68 struct catchtag *m_catchlist;
69 #define catchlist (current_thread->m_catchlist)
71 /* Chain of condition handlers currently in effect.
72 The elements of this chain are contained in the stack frames
73 of Fcondition_case and internal_condition_case.
74 When an error is signaled (by calling Fsignal),
75 this chain is searched for an element that applies. */
76 struct handler *m_handlerlist;
77 #define handlerlist (current_thread->m_handlerlist)
79 struct handler *m_handlerlist_sentinel;
80 #define handlerlist_sentinel (current_thread->m_handlerlist_sentinel)
82 /* Current number of specbindings allocated in specpdl. */
83 ptrdiff_t m_specpdl_size;
84 #define specpdl_size (current_thread->m_specpdl_size)
86 /* Pointer to beginning of specpdl. */
87 union specbinding *m_specpdl;
88 #define specpdl (current_thread->m_specpdl)
90 /* Pointer to first unused element in specpdl. */
91 union specbinding *m_specpdl_ptr;
92 #define specpdl_ptr (current_thread->m_specpdl_ptr)
94 /* Depth in Lisp evaluations and function calls. */
95 EMACS_INT m_lisp_eval_depth;
96 #define lisp_eval_depth (current_thread->m_lisp_eval_depth)
98 /* This points to the current buffer. */
99 struct buffer *m_current_buffer;
100 #define current_buffer (current_thread->m_current_buffer)
102 /* Every call to re_match, etc., must pass &search_regs as the regs
103 argument unless you can show it is unnecessary (i.e., if re_match
104 is certainly going to be called again before region-around-match
105 can be called).
107 Since the registers are now dynamically allocated, we need to make
108 sure not to refer to the Nth register before checking that it has
109 been allocated by checking search_regs.num_regs.
111 The regex code keeps track of whether it has allocated the search
112 buffer using bits in the re_pattern_buffer. This means that whenever
113 you compile a new pattern, it completely forgets whether it has
114 allocated any registers, and will allocate new registers the next
115 time you call a searching or matching function. Therefore, we need
116 to call re_set_registers after compiling a new pattern or after
117 setting the match registers, so that the regex functions will be
118 able to free or re-allocate it properly. */
119 struct re_registers m_search_regs;
120 #define search_regs (current_thread->m_search_regs)
122 /* If non-zero the match data have been saved in saved_search_regs
123 during the execution of a sentinel or filter. */
124 bool m_search_regs_saved;
125 #define search_regs_saved (current_thread->m_search_regs_saved)
127 struct re_registers m_saved_search_regs;
128 #define saved_search_regs (current_thread->m_saved_search_regs)
130 /* This is the string or buffer in which we
131 are matching. It is used for looking up syntax properties.
133 If the value is a Lisp string object, we are matching text in that
134 string; if it's nil, we are matching text in the current buffer; if
135 it's t, we are matching text in a C string. */
136 Lisp_Object m_re_match_object;
137 #define re_match_object (current_thread->m_re_match_object)
139 /* This member is different from waiting_for_input.
140 It is used to communicate to a lisp process-filter/sentinel (via the
141 function Fwaiting_for_user_input_p) whether Emacs was waiting
142 for user-input when that process-filter was called.
143 waiting_for_input cannot be used as that is by definition 0 when
144 lisp code is being evalled.
145 This is also used in record_asynch_buffer_change.
146 For that purpose, this must be 0
147 when not inside wait_reading_process_output. */
148 int m_waiting_for_user_input_p;
149 #define waiting_for_user_input_p (current_thread->m_waiting_for_user_input_p)
151 /* True while doing kbd input. */
152 bool m_waiting_for_input;
153 #define waiting_for_input (current_thread->m_waiting_for_input)
155 /* The OS identifier for this thread. */
156 sys_thread_t thread_id;
158 /* The condition variable for this thread. This is associated with
159 the global lock. This thread broadcasts to it when it exits. */
160 sys_cond_t thread_condvar;
162 /* This thread might be waiting for some condition. If so, this
163 points to the condition. If the thread is interrupted, the
164 interrupter should broadcast to this condition. */
165 sys_cond_t *wait_condvar;
167 /* This thread might have released the global lock. If so, this is
168 non-zero. When a thread runs outside thread_select with this
169 flag non-zero, it means it has been interrupted by SIGINT while
170 in thread_select, and didn't have a chance of acquiring the lock.
171 It must do so ASAP. */
172 int not_holding_lock;
174 /* Threads are kept on a linked list. */
175 struct thread_state *next_thread;
178 /* A mutex in lisp is represented by a system condition variable.
179 The system mutex associated with this condition variable is the
180 global lock.
182 Using a condition variable lets us implement interruptibility for
183 lisp mutexes. */
184 typedef struct
186 /* The owning thread, or NULL if unlocked. */
187 struct thread_state *owner;
188 /* The lock count. */
189 unsigned int count;
190 /* The underlying system condition variable. */
191 sys_cond_t condition;
192 } lisp_mutex_t;
194 /* A mutex as a lisp object. */
195 struct Lisp_Mutex
197 struct vectorlike_header header;
199 /* The name of the mutex, or nil. */
200 Lisp_Object name;
202 /* The lower-level mutex object. */
203 lisp_mutex_t mutex;
206 /* A condition variable as a lisp object. */
207 struct Lisp_CondVar
209 struct vectorlike_header header;
211 /* The associated mutex. */
212 Lisp_Object mutex;
214 /* The name of the condition variable, or nil. */
215 Lisp_Object name;
217 /* The lower-level condition variable object. */
218 sys_cond_t cond;
221 extern struct thread_state *current_thread;
223 extern void finalize_one_thread (struct thread_state *state);
224 extern void finalize_one_mutex (struct Lisp_Mutex *);
225 extern void finalize_one_condvar (struct Lisp_CondVar *);
226 extern void maybe_reacquire_global_lock (void);
228 extern void init_threads_once (void);
229 extern void init_threads (void);
230 extern void syms_of_threads (void);
231 extern bool primary_thread_p (void *);
233 typedef int select_func (int, fd_set *, fd_set *, fd_set *,
234 const struct timespec *, const sigset_t *);
236 int thread_select (select_func *func, int max_fds, fd_set *rfds,
237 fd_set *wfds, fd_set *efds, struct timespec *timeout,
238 sigset_t *sigmask);
240 bool thread_check_current_buffer (struct buffer *);
242 #endif /* THREAD_H */