Miscellaneous 'sendfile' fixes and improved tests.
[bpt/guile.git] / libguile / async.h
dissimilarity index 95%
index ff67c7d..ceb2b96 100644 (file)
-/* classes: h_files */
-
-#ifndef ASYNCH
-#define ASYNCH
-/*     Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
- * 
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- * 
- * This program 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 General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this software; see the file COPYING.  If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307 USA
- *
- * As a special exception, the Free Software Foundation gives permission
- * for additional uses of the text contained in its release of GUILE.
- *
- * The exception is that, if you link the GUILE library with other files
- * to produce an executable, this does not by itself cause the
- * resulting executable to be covered by the GNU General Public License.
- * Your use of that executable is in no way restricted on account of
- * linking the GUILE library code into it.
- *
- * This exception does not however invalidate any other reasons why
- * the executable file might be covered by the GNU General Public License.
- *
- * This exception applies only to the code released by the
- * Free Software Foundation under the name GUILE.  If you copy
- * code from other Free Software Foundation releases into a copy of
- * GUILE, as the General Public License permits, the exception does
- * not apply to the code that you add in this way.  To avoid misleading
- * anyone as to the status of such modified files, you must delete
- * this exception notice from them.
- *
- * If you write modifications of your own for GUILE, it is your choice
- * whether to permit this exception to apply to your modifications.
- * If you do not wish that, delete this exception notice.  */
-
-/* Software engineering face-lift by Greg J. Badros, 11-Dec-1999,
-   gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */
-\f
-
-#include "libguile/__scm.h"
-
-
-\f
-#define SCM_ASYNCP(X)  (SCM_NIMP(X) && (scm_tc16_async == SCM_GCTYP16 (X)))
-#define SCM_ASYNC(X)   ((struct scm_async *)SCM_CDR (X))
-
-struct scm_async
-{
-  int got_it;                  /* needs to be delivered? */
-  SCM thunk;                   /* the handler. */
-};
-
-\f
-
-extern unsigned int scm_mask_ints;
-extern SCM scm_gc_async;
-\f
-
-extern int scm_asyncs_pending (void);
-extern void scm_async_click (void);
-extern void scm_switch (void);
-extern SCM scm_async (SCM thunk);
-extern SCM scm_system_async (SCM thunk);
-extern SCM scm_async_mark (SCM a);
-extern SCM scm_system_async_mark (SCM a);
-extern SCM scm_run_asyncs (SCM list_of_a);
-extern SCM scm_noop (SCM args);
-extern SCM scm_set_tick_rate (SCM n);
-extern SCM scm_set_switch_rate (SCM n);
-extern SCM scm_unmask_signals (void);
-extern SCM scm_mask_signals (void);
-extern void scm_init_async (void);
-
-#endif  /* ASYNCH */
+/* classes: h_files */
+
+#ifndef SCM_ASYNC_H
+#define SCM_ASYNC_H
+
+/* Copyright (C) 1995,1996,1997,1998,2000,2001, 2002, 2004, 2005, 2006, 2008, 2009 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 License
+ * as published by the Free Software Foundation; either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This library 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 this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+\f
+
+#include "libguile/__scm.h"
+#include "libguile/root.h"
+#include "libguile/threads.h"
+
+\f
+
+SCM_API void scm_async_click (void);
+SCM_API void scm_switch (void);
+SCM_API SCM scm_async (SCM thunk);
+SCM_API SCM scm_async_mark (SCM a);
+SCM_API SCM scm_system_async_mark (SCM a);
+SCM_API SCM scm_system_async_mark_for_thread (SCM a, SCM thread);
+SCM_INTERNAL void scm_i_queue_async_cell (SCM cell, scm_i_thread *);
+SCM_INTERNAL int scm_i_setup_sleep (scm_i_thread *,
+                                   SCM obj, scm_i_pthread_mutex_t *m,
+                                   int fd);
+SCM_INTERNAL void scm_i_reset_sleep (scm_i_thread *);
+SCM_API SCM scm_run_asyncs (SCM list_of_a);
+SCM_API SCM scm_noop (SCM args);
+SCM_API SCM scm_call_with_blocked_asyncs (SCM proc);
+SCM_API SCM scm_call_with_unblocked_asyncs (SCM proc);
+void *scm_c_call_with_blocked_asyncs (void *(*p) (void *d), void *d);
+void *scm_c_call_with_unblocked_asyncs (void *(*p) (void *d), void *d);
+void scm_dynwind_block_asyncs (void);
+void scm_dynwind_unblock_asyncs (void);
+
+/* Critical sections */
+
+/* XXX - every critical section needs to be examined whether the
+   requirements for SCM_CRITICAL_SECTION_START/END are fulfilled.  See
+   the manual.
+*/
+
+/* Defined in threads.c. */
+SCM_INTERNAL scm_i_pthread_mutex_t scm_i_critical_section_mutex;
+
+SCM_API void scm_critical_section_start (void);
+SCM_API void scm_critical_section_end (void);
+
+#ifdef BUILDING_LIBGUILE
+
+# define SCM_CRITICAL_SECTION_START                            \
+  do {                                                         \
+    scm_i_pthread_mutex_lock (&scm_i_critical_section_mutex);  \
+    SCM_I_CURRENT_THREAD->block_asyncs++;                      \
+    SCM_I_CURRENT_THREAD->critical_section_level++;            \
+  } while (0)
+# define SCM_CRITICAL_SECTION_END                              \
+  do {                                                         \
+    SCM_I_CURRENT_THREAD->critical_section_level--;            \
+    SCM_I_CURRENT_THREAD->block_asyncs--;                      \
+    scm_i_pthread_mutex_unlock (&scm_i_critical_section_mutex); \
+    scm_async_click ();                                                \
+  } while (0)
+
+#else /* !BUILDING_LIBGUILE */
+
+# define SCM_CRITICAL_SECTION_START  scm_critical_section_start ()
+# define SCM_CRITICAL_SECTION_END    scm_critical_section_end ()
+
+#endif /* !BUILDING_LIBGUILE */
+
+SCM_INTERNAL void scm_init_async (void);
+
+#if (SCM_ENABLE_DEPRECATED == 1)
+
+SCM_DEPRECATED SCM scm_system_async (SCM thunk);
+SCM_DEPRECATED SCM scm_unmask_signals (void);
+SCM_DEPRECATED SCM scm_mask_signals (void);
+
+#endif
+
+#endif  /* SCM_ASYNC_H */
+
+/*
+  Local Variables:
+  c-file-style: "gnu"
+  End:
+*/