* threads.c (do_thread_exit, scm_cancel_thread,
[bpt/guile.git] / libguile / threads.h
index ad38653..b19fbe3 100644 (file)
@@ -3,7 +3,7 @@
 #ifndef SCM_THREADS_H
 #define SCM_THREADS_H
 
-/* Copyright (C) 1996,1997,1998,2000,2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 1996,1997,1998,2000,2001, 2002, 2003, 2004, 2006, 2007, 2008 Free Software Foundation, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -17,7 +17,7 @@
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 \f
@@ -49,9 +49,14 @@ typedef struct scm_i_thread {
 
   SCM handle;
   scm_i_pthread_t pthread;
-  
+
+  SCM cleanup_handler;
   SCM join_queue;
+
+  scm_i_pthread_mutex_t admin_mutex;
+
   SCM result;
+  int canceled;
   int exited;
 
   SCM sleep_object;
@@ -69,6 +74,8 @@ typedef struct scm_i_thread {
   */
   SCM freelist, freelist2;
   int clear_freelists_p; /* set if GC was done while thread was asleep */
+  int gc_running_p;      /* non-zero while this thread does GC or a
+                           sweep. */
 
   /* Other thread local things.
    */
@@ -80,8 +87,6 @@ typedef struct scm_i_thread {
    */
   SCM active_asyncs;            /* The thunks to be run at the next
                                    safe point */
-  SCM signal_asyncs;            /* The pre-queued cells for signal handlers.
-                                 */
   unsigned int block_asyncs;    /* Non-zero means that asyncs should 
                                    not be run. */
   unsigned int pending_asyncs;  /* Non-zero means that asyncs might be pending.
@@ -123,27 +128,12 @@ typedef struct scm_i_thread {
 SCM_API SCM scm_spawn_thread (scm_t_catch_body body, void *body_data,
                              scm_t_catch_handler handler, void *handler_data);
 
-typedef void *scm_t_guile_ticket;
-SCM_API void scm_enter_guile (scm_t_guile_ticket ticket);
-SCM_API scm_t_guile_ticket scm_leave_guile (void);
 SCM_API void *scm_without_guile (void *(*func)(void *), void *data);
-
 SCM_API void *scm_with_guile (void *(*func)(void *), void *data);
+
 SCM_API void *scm_i_with_guile_and_parent (void *(*func)(void *), void *data,
                                           SCM parent);
 
-/* Critical sections */
-
-/* XXX - every critical section needs to be examined and protected
-   with scm_frame_critical_section, say.
-*/
-
-extern scm_i_pthread_mutex_t scm_i_critical_section_mutex;
-
-#define SCM_CRITICAL_SECTION_START \
-  scm_i_pthread_mutex_lock (&scm_i_critical_section_mutex)
-#define SCM_CRITICAL_SECTION_END \
-  scm_i_pthread_mutex_unlock (&scm_i_critical_section_mutex)
 
 extern int scm_i_thread_go_to_sleep;
 
@@ -151,7 +141,6 @@ void scm_i_thread_put_to_sleep (void);
 void scm_i_thread_wake_up (void);
 void scm_i_thread_invalidate_freelists (void);
 void scm_i_thread_sleep_for_gc (void);
-SCM_API void scm_i_frame_single_threaded (void);
 
 void scm_threads_prehistory (SCM_STACKITEM *);
 void scm_threads_init_first_thread (void);
@@ -169,11 +158,15 @@ do { \
 
 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_make_mutex (void);
 SCM_API SCM scm_make_recursive_mutex (void);
 SCM_API SCM scm_lock_mutex (SCM m);
+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);
 
@@ -190,7 +183,7 @@ 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_frame_critical_section (void);
+SCM_API void scm_dynwind_critical_section (SCM mutex);
 
 #define SCM_I_CURRENT_THREAD \
   ((scm_i_thread *) scm_i_pthread_getspecific (scm_i_thread_key))
@@ -210,7 +203,7 @@ SCM_API 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_frame_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,