123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- #ifndef SCM_THREADS_H
- #define SCM_THREADS_H
- #include "libguile/__scm.h"
- #include "libguile/procs.h"
- #include "libguile/throw.h"
- #include "libguile/root.h"
- #include "libguile/dynstack.h"
- #include "libguile/iselect.h"
- #include "libguile/continuations.h"
- #if SCM_USE_PTHREAD_THREADS
- #include "libguile/pthread-threads.h"
- #endif
- #if SCM_USE_NULL_THREADS
- #include "libguile/null-threads.h"
- #endif
- SCM_API scm_t_bits scm_tc16_thread;
- SCM_API scm_t_bits scm_tc16_mutex;
- SCM_API scm_t_bits scm_tc16_condvar;
- typedef struct scm_i_thread {
- struct scm_i_thread *next_thread;
- SCM handle;
- scm_i_pthread_t pthread;
- SCM cleanup_handler;
- SCM join_queue;
- scm_i_pthread_mutex_t admin_mutex;
- SCM mutexes;
- scm_i_pthread_mutex_t *held_mutex;
- SCM result;
- int canceled;
- int exited;
-
- int guile_mode;
- SCM sleep_object;
- scm_i_pthread_mutex_t *sleep_mutex;
- scm_i_pthread_cond_t sleep_cond;
- int sleep_fd, sleep_pipe[2];
-
- void **freelists;
- void **pointerless_freelists;
-
- SCM dynamic_state;
-
- scm_t_dynstack dynstack;
-
- SCM active_asyncs;
- unsigned int block_asyncs;
- unsigned int pending_asyncs;
-
- SCM continuation_root;
- SCM_STACKITEM *continuation_base;
-
- struct scm_vm *vp;
- SCM_STACKITEM *base;
- scm_i_jmp_buf regs;
- #ifdef __ia64__
- void *register_backing_store_base;
- scm_t_contregs *pending_rbs_continuation;
- #endif
-
- int critical_section_level;
- } scm_i_thread;
- #define SCM_I_IS_THREAD(x) SCM_SMOB_PREDICATE (scm_tc16_thread, x)
- #define SCM_I_THREAD_DATA(x) ((scm_i_thread *) SCM_SMOB_DATA (x))
- #define SCM_VALIDATE_THREAD(pos, a) \
- scm_assert_smob_type (scm_tc16_thread, (a))
- #define SCM_VALIDATE_MUTEX(pos, a) \
- scm_assert_smob_type (scm_tc16_mutex, (a))
- #define SCM_VALIDATE_CONDVAR(pos, a) \
- scm_assert_smob_type (scm_tc16_condvar, (a))
- 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_INTERNAL void scm_i_reset_fluid (size_t);
- SCM_INTERNAL void scm_threads_prehistory (void *);
- SCM_INTERNAL void scm_init_threads (void);
- SCM_INTERNAL void scm_init_thread_procs (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_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_set_thread_cleanup_x (SCM thread, SCM proc);
- SCM_API SCM scm_thread_cleanup (SCM thread);
- 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_flags (SCM flags);
- SCM_API SCM scm_lock_mutex (SCM m);
- SCM_API SCM scm_lock_mutex_timed (SCM m, SCM timeout, SCM owner);
- 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_unlock_mutex_timed (SCM m, SCM cond, SCM timeout);
- 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);
- SCM_API void scm_dynwind_critical_section (SCM mutex);
- #ifdef BUILDING_LIBGUILE
- SCM_INTERNAL scm_i_pthread_key_t scm_i_thread_key;
- # ifdef SCM_HAVE_THREAD_STORAGE_CLASS
- SCM_INTERNAL SCM_THREAD_LOCAL scm_i_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_i_thread *) scm_i_pthread_getspecific (scm_i_thread_key))
- # endif /* !SCM_HAVE_THREAD_STORAGE_CLASS */
- #endif /* BUILDING_LIBGUILE */
- SCM_INTERNAL scm_i_pthread_mutex_t scm_i_misc_mutex;
- #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
- 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 */
|