#ifndef SCM_THREADS_H #define SCM_THREADS_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 . */ #include "libguile/procs.h" #include "libguile/throw.h" #include "libguile/dynstack.h" #include "libguile/iselect.h" #include "libguile/vm.h" #if SCM_USE_PTHREAD_THREADS #include "libguile/pthread-threads.h" #endif #if SCM_USE_NULL_THREADS #include "libguile/null-threads.h" #endif struct scm_thread; struct scm_thread_wake_data; static inline SCM scm_thread_handle (struct scm_thread *thread) { return SCM_PACK_POINTER (thread); } #define SCM_I_IS_THREAD(obj) SCM_HAS_TYP7 ((obj), scm_tc7_thread) #define SCM_I_THREAD_DATA(x) ((scm_thread *) SCM_UNPACK_POINTER (x)) #define SCM_VALIDATE_THREAD(pos, a) \ SCM_ASSERT_TYPE (SCM_I_IS_THREAD (a), (a), (pos), FUNC_NAME, "thread") SCM_API SCM scm_spawn_thread (scm_t_catch_body body, void *body_data, scm_t_catch_handler handler, void *handler_data); SCM_API void *scm_without_guile (void *(*func)(void *), void *data); SCM_API void *scm_with_guile (void *(*func)(void *), void *data); SCM_API SCM scm_call_with_new_thread (SCM thunk, SCM handler); SCM_API SCM scm_yield (void); SCM_API SCM scm_cancel_thread (SCM t); SCM_API SCM scm_join_thread (SCM t); SCM_API SCM scm_join_thread_timed (SCM t, SCM timeout, SCM timeoutval); SCM_API SCM scm_thread_p (SCM t); SCM_API SCM scm_make_mutex (void); SCM_API SCM scm_make_recursive_mutex (void); SCM_API SCM scm_make_mutex_with_kind (SCM kind); SCM_API SCM scm_lock_mutex (SCM m); SCM_API SCM scm_timed_lock_mutex (SCM m, SCM timeout); SCM_API void scm_dynwind_lock_mutex (SCM mutex); SCM_API SCM scm_try_mutex (SCM m); SCM_API SCM scm_unlock_mutex (SCM m); SCM_API SCM scm_mutex_p (SCM o); SCM_API SCM scm_mutex_locked_p (SCM m); SCM_API SCM scm_mutex_owner (SCM m); SCM_API SCM scm_mutex_level (SCM m); SCM_API SCM scm_make_condition_variable (void); SCM_API SCM scm_wait_condition_variable (SCM cond, SCM mutex); SCM_API SCM scm_timed_wait_condition_variable (SCM cond, SCM mutex, SCM abstime); SCM_API SCM scm_signal_condition_variable (SCM cond); SCM_API SCM scm_broadcast_condition_variable (SCM cond); SCM_API SCM scm_condition_variable_p (SCM o); SCM_API SCM scm_current_thread (void); SCM_API SCM scm_all_threads (void); SCM_API int scm_c_thread_exited_p (SCM thread); SCM_API SCM scm_thread_exited_p (SCM thread); /* Convenience functions for working with the pthread API in guile mode. */ #if SCM_USE_PTHREAD_THREADS SCM_API int scm_pthread_mutex_lock (pthread_mutex_t *mutex); SCM_API void scm_dynwind_pthread_mutex_lock (pthread_mutex_t *mutex); SCM_API int scm_pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex); SCM_API int scm_pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex, const scm_t_timespec *abstime); #endif /* More convenience functions. */ SCM_API unsigned int scm_std_sleep (unsigned int); SCM_API unsigned long scm_std_usleep (unsigned long); SCM_API SCM scm_total_processor_count (void); SCM_API SCM scm_current_processor_count (void); #endif /* SCM_THREADS_H */