};
verify (GCALIGNED (union aligned_thread_state));
-static union aligned_thread_state main_thread;
+static union aligned_thread_state main_thread
+ = {{
+ .header.size = PVECHEADERSIZE (PVEC_THREAD,
+ PSEUDOVECSIZE (struct thread_state,
+ event_object),
+ VECSIZE (struct thread_state)),
+ .m_last_thing_searched = LISPSYM_INITIALLY (Qnil),
+ .m_saved_last_thing_searched = LISPSYM_INITIALLY (Qnil),
+ .name = LISPSYM_INITIALLY (Qnil),
+ .function = LISPSYM_INITIALLY (Qnil),
+ .result = LISPSYM_INITIALLY (Qnil),
+ .error_symbol = LISPSYM_INITIALLY (Qnil),
+ .error_data = LISPSYM_INITIALLY (Qnil),
+ .event_object = LISPSYM_INITIALLY (Qnil),
+ }};
struct thread_state *current_thread = &main_thread.s;
informational only. */)
(Lisp_Object name)
{
- struct Lisp_Mutex *mutex;
- Lisp_Object result;
-
if (!NILP (name))
CHECK_STRING (name);
- mutex = ALLOCATE_PSEUDOVECTOR (struct Lisp_Mutex, name, PVEC_MUTEX);
- memset ((char *) mutex + offsetof (struct Lisp_Mutex, mutex),
- 0, sizeof (struct Lisp_Mutex) - offsetof (struct Lisp_Mutex,
- mutex));
+ struct Lisp_Mutex *mutex
+ = ALLOCATE_ZEROED_PSEUDOVECTOR (struct Lisp_Mutex, name, PVEC_MUTEX);
mutex->name = name;
lisp_mutex_init (&mutex->mutex);
+ Lisp_Object result;
XSETMUTEX (result, mutex);
return result;
}
informational only. */)
(Lisp_Object mutex, Lisp_Object name)
{
- struct Lisp_CondVar *condvar;
- Lisp_Object result;
-
CHECK_MUTEX (mutex);
if (!NILP (name))
CHECK_STRING (name);
- condvar = ALLOCATE_PSEUDOVECTOR (struct Lisp_CondVar, name, PVEC_CONDVAR);
- memset ((char *) condvar + offsetof (struct Lisp_CondVar, cond),
- 0, sizeof (struct Lisp_CondVar) - offsetof (struct Lisp_CondVar,
- cond));
+ struct Lisp_CondVar *condvar
+ = ALLOCATE_ZEROED_PSEUDOVECTOR (struct Lisp_CondVar, name, PVEC_CONDVAR);
condvar->mutex = mutex;
condvar->name = name;
sys_cond_init (&condvar->cond);
+ Lisp_Object result;
XSETCONDVAR (result, condvar);
return result;
}
mark_object (tem);
}
- mark_object (thread->m_last_thing_searched);
-
- if (!NILP (thread->m_saved_last_thing_searched))
- mark_object (thread->m_saved_last_thing_searched);
+ /* No need to mark Lisp_Object members like m_last_thing_searched,
+ as mark_threads_callback does that by calling mark_object. */
}
static void
If NAME is given, it must be a string; it names the new thread. */)
(Lisp_Object function, Lisp_Object name)
{
- sys_thread_t thr;
- struct thread_state *new_thread;
- Lisp_Object result;
- const char *c_name = NULL;
- size_t offset = offsetof (struct thread_state, m_stack_bottom);
-
/* Can't start a thread in temacs. */
if (!initialized)
emacs_abort ();
if (!NILP (name))
CHECK_STRING (name);
- new_thread = ALLOCATE_PSEUDOVECTOR (struct thread_state, event_object,
- PVEC_THREAD);
- memset ((char *) new_thread + offset, 0,
- sizeof (struct thread_state) - offset);
-
+ struct thread_state *new_thread
+ = ALLOCATE_ZEROED_PSEUDOVECTOR (struct thread_state, event_object,
+ PVEC_THREAD);
new_thread->function = function;
new_thread->name = name;
- new_thread->m_last_thing_searched = Qnil; /* copy from parent? */
- new_thread->m_saved_last_thing_searched = Qnil;
+ /* Perhaps copy m_last_thing_searched from parent? */
new_thread->m_current_buffer = current_thread->m_current_buffer;
- new_thread->result = Qnil;
- new_thread->error_symbol = Qnil;
- new_thread->error_data = Qnil;
- new_thread->event_object = Qnil;
new_thread->m_specpdl_size = 50;
new_thread->m_specpdl = xmalloc ((1 + new_thread->m_specpdl_size)
new_thread->next_thread = all_threads;
all_threads = new_thread;
- if (!NILP (name))
- c_name = SSDATA (ENCODE_UTF_8 (name));
-
+ char const *c_name = !NILP (name) ? SSDATA (ENCODE_UTF_8 (name)) : NULL;
+ sys_thread_t thr;
if (! sys_thread_create (&thr, c_name, run_thread, new_thread))
{
/* Restore the previous situation. */
}
/* FIXME: race here where new thread might not be filled in? */
+ Lisp_Object result;
XSETTHREAD (result, new_thread);
return result;
}
\f
-static void
-init_main_thread (void)
-{
- main_thread.s.header.size
- = PSEUDOVECSIZE (struct thread_state, event_object);
- XSETPVECTYPE (&main_thread.s, PVEC_THREAD);
- main_thread.s.m_last_thing_searched = Qnil;
- main_thread.s.m_saved_last_thing_searched = Qnil;
- main_thread.s.name = Qnil;
- main_thread.s.function = Qnil;
- main_thread.s.result = Qnil;
- main_thread.s.error_symbol = Qnil;
- main_thread.s.error_data = Qnil;
- main_thread.s.event_object = Qnil;
-}
-
bool
main_thread_p (const void *ptr)
{
return sys_thread_equal (sys_thread_self (), current_thread->thread_id);
}
-void
-init_threads_once (void)
-{
- init_main_thread ();
-}
-
void
init_threads (void)
{
- init_main_thread ();
sys_cond_init (&main_thread.s.thread_condvar);
sys_mutex_init (&global_lock);
sys_mutex_lock (&global_lock);