mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-07-01 15:20:34 +02:00
Allows us to inline the "struct scm_dynamic_state", avoiding an untagged traced allocation. * libguile/threads-internal.h: New file. * libguile/Makefile.am (noinst_HEADERS): Add new file. Adapt all users, notably of SCM_I_CURRENT_THREAD and scm_i_misc_mutex.
130 lines
4 KiB
C
130 lines
4 KiB
C
#ifndef SCM_THREADS_INTERNAL_H
|
||
#define SCM_THREADS_INTERNAL_H
|
||
|
||
/* Copyright 1996-1998,2000-2004,2006-2009,2011-2014,2018-2019,2025
|
||
Free Software Foundation, Inc.
|
||
|
||
This file is part of Guile.
|
||
|
||
Guile is free software: you can redistribute it and/or modify it
|
||
under the terms of the GNU Lesser General Public License as published
|
||
by the Free Software Foundation, either version 3 of the License, or
|
||
(at your option) any later version.
|
||
|
||
Guile is distributed in the hope that it will be useful, but WITHOUT
|
||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||
License for more details.
|
||
|
||
You should have received a copy of the GNU Lesser General Public
|
||
License along with Guile. If not, see
|
||
<https://www.gnu.org/licenses/>. */
|
||
|
||
|
||
|
||
#include "libguile/fluids-internal.h"
|
||
#include "libguile/threads.h"
|
||
|
||
|
||
|
||
struct gc_mutator;
|
||
|
||
struct scm_thread {
|
||
scm_t_bits tag;
|
||
|
||
struct scm_thread *next_thread;
|
||
|
||
/* VM state for this thread. */
|
||
struct scm_vm vm;
|
||
|
||
/* For system asyncs.
|
||
*/
|
||
SCM pending_asyncs; /* The thunks to be run at the next
|
||
safe point. Accessed atomically. */
|
||
unsigned int block_asyncs; /* Non-zero means that asyncs should
|
||
not be run. */
|
||
|
||
/* Every thread is a mutator for the GC. */
|
||
struct gc_mutator *mutator;
|
||
|
||
scm_i_pthread_t pthread;
|
||
|
||
SCM result;
|
||
int exited;
|
||
|
||
/* Boolean indicating whether the thread is in guile mode. */
|
||
int guile_mode;
|
||
/* Boolean indicating whether to call GC_unregister_my_thread () when
|
||
this thread exits. */
|
||
int needs_unregister;
|
||
|
||
struct scm_thread_wake_data *wake;
|
||
scm_i_pthread_cond_t sleep_cond;
|
||
int sleep_pipe[2];
|
||
|
||
/* Other thread local things.
|
||
*/
|
||
struct scm_dynamic_state dynamic_state;
|
||
|
||
/* The dynamic stack. */
|
||
scm_t_dynstack dynstack;
|
||
|
||
/* The current continuation root and the stack base for it.
|
||
|
||
The continuation root is an arbitrary but unique object that
|
||
identifies a dynamic extent. Continuations created during that
|
||
extent can also only be invoked during it.
|
||
|
||
We use pairs where the car is the thread handle and the cdr links
|
||
to the previous pair. This might be used for better error
|
||
messages but is not essential for identifying continuation roots.
|
||
|
||
The continuation base is the far end of the stack upto which it
|
||
needs to be copied.
|
||
*/
|
||
SCM continuation_root;
|
||
SCM_STACKITEM *continuation_base;
|
||
|
||
/* Stack base. Used when checking for C stack overflow. */
|
||
SCM_STACKITEM *base;
|
||
|
||
/* For joinable threads, a cond to wait on joining, and a lock to
|
||
protect the results. #f if not joinable. */
|
||
SCM join_cond;
|
||
SCM join_lock;
|
||
SCM join_results;
|
||
|
||
/* JIT state; NULL until this thread needs to JIT-compile something. */
|
||
struct scm_jit_state *jit_state;
|
||
};
|
||
|
||
SCM_INTERNAL void scm_init_threads (void);
|
||
SCM_INTERNAL void scm_init_threads_default_dynamic_state (void);
|
||
|
||
SCM_INTERNAL void scm_i_dynwind_pthread_mutex_lock_block_asyncs (scm_i_pthread_mutex_t *mutex);
|
||
|
||
SCM_INTERNAL int scm_i_print_thread (SCM t, SCM port, scm_print_state *pstate);
|
||
SCM_INTERNAL int scm_i_print_mutex (SCM m, SCM port, scm_print_state *pstate);
|
||
SCM_INTERNAL int scm_i_print_condition_variable (SCM cv, SCM port,
|
||
scm_print_state *pstate);
|
||
|
||
/* Though we don't need the key for SCM_I_CURRENT_THREAD if we have TLS,
|
||
we do use it for cleanup purposes. */
|
||
SCM_INTERNAL scm_i_pthread_key_t scm_i_thread_key;
|
||
|
||
#ifdef SCM_HAVE_THREAD_STORAGE_CLASS
|
||
|
||
SCM_INTERNAL SCM_THREAD_LOCAL scm_thread *scm_i_current_thread;
|
||
# define SCM_I_CURRENT_THREAD (scm_i_current_thread)
|
||
|
||
#else /* !SCM_HAVE_THREAD_STORAGE_CLASS */
|
||
|
||
# define SCM_I_CURRENT_THREAD \
|
||
((scm_thread *) scm_i_pthread_getspecific (scm_i_thread_key))
|
||
|
||
#endif /* !SCM_HAVE_THREAD_STORAGE_CLASS */
|
||
|
||
SCM_INTERNAL scm_i_pthread_mutex_t scm_i_misc_mutex;
|
||
|
||
|
||
#endif /* SCM_THREADS_INTERNAL_H */
|