remove libguile/lang.h, deprecate %nil (in favor of #nil)
[bpt/guile.git] / libguile / async.c
index 2833b54..e448dc1 100644 (file)
@@ -1,33 +1,35 @@
-/* Copyright (C) 1995,1996,1997,1998,2000,2001, 2002, 2004, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1997,1998,2000,2001, 2002, 2004, 2006, 2008, 2009, 2010 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 2.1 of the License, or (at your option) any later version.
+ * 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
+ * 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
  */
 
 
 \f
-#if HAVE_CONFIG_H
+#ifdef HAVE_CONFIG_H
 #  include <config.h>
 #endif
 
+#define SCM_BUILDING_DEPRECATED_CODE
+
 #include <signal.h>
 #include "libguile/_scm.h"
 #include "libguile/eval.h"
 #include "libguile/throw.h"
 #include "libguile/root.h"
 #include "libguile/smob.h"
-#include "libguile/lang.h"
 #include "libguile/dynwind.h"
 #include "libguile/deprecation.h"
 
@@ -41,6 +43,8 @@
 #include <unistd.h>
 #endif
 
+#include <full-write.h>
+
 \f
 /* {Asynchronous Events}
  *
@@ -82,9 +86,9 @@ static scm_t_bits tc16_async;
 #define SCM_ASYNCP(X)          SCM_TYP16_PREDICATE (tc16_async, X)
 #define VALIDATE_ASYNC(pos, a) SCM_MAKE_VALIDATE_MSG(pos, a, ASYNCP, "user async")
 
-#define ASYNC_GOT_IT(X)        (SCM_CELL_WORD_0 (X) >> 16)
-#define SET_ASYNC_GOT_IT(X, V) (SCM_SET_CELL_WORD_0 ((X), SCM_TYP16 (X) | ((V) << 16)))
-#define ASYNC_THUNK(X)         SCM_CELL_OBJECT_1 (X)
+#define ASYNC_GOT_IT(X)        (SCM_SMOB_FLAGS (X))
+#define SET_ASYNC_GOT_IT(X, V) (SCM_SET_SMOB_FLAGS ((X), ((V))))
+#define ASYNC_THUNK(X)         SCM_SMOB_OBJECT_1 (X)
 
 
 SCM_DEFINE (scm_async, "async", 1, 0, 0,
@@ -172,7 +176,7 @@ scm_async_click ()
 SCM_DEFINE (scm_system_async, "system-async", 1, 0, 0,
             (SCM thunk),
            "This function is deprecated.  You can use @var{thunk} directly\n"
-            "instead of explicitely creating an async object.\n")
+            "instead of explicitly creating an async object.\n")
 #define FUNC_NAME s_scm_system_async
 {
   scm_c_issue_deprecation_warning 
@@ -236,13 +240,13 @@ scm_i_queue_async_cell (SCM c, scm_i_thread *t)
   if (sleep_fd >= 0)
     {
       char dummy = 0;
+
       /* Likewise, T might already been done with sleeping here, but
         interrupting it once too often does no harm.  T might also
         not yet have started sleeping, but this is no problem either
         since the data written to a pipe will not be lost, unlike a
-        condition variable signal.
-      */
-      write (sleep_fd, &dummy, 1);
+        condition variable signal.  */
+      full_write (sleep_fd, &dummy, 1);
     }
 
   /* This is needed to protect sleep_mutex.
@@ -467,13 +471,35 @@ scm_dynwind_unblock_asyncs ()
   scm_dynwind_unwind_handler (increase_block, t, SCM_F_WIND_EXPLICITLY);
 }
 
+\f
+/* These are function variants of the same-named macros (uppercase) for use
+   outside of libguile.  This is so that `SCM_I_CURRENT_THREAD', which may
+   reside in TLS, is not accessed from outside of libguile.  It thus allows
+   libguile to be built with the "local-dynamic" TLS model.  */
+
+void
+scm_critical_section_start (void)
+{
+  SCM_CRITICAL_SECTION_START;
+}
+
+void
+scm_critical_section_end (void)
+{
+  SCM_CRITICAL_SECTION_END;
+}
+
+void
+scm_async_tick (void)
+{
+  SCM_ASYNC_TICK;
+}
 
 \f
 
 void
 scm_init_async ()
 {
-  scm_asyncs = SCM_EOL;
   tc16_async = scm_make_smob_type ("async", 0);
 
 #include "libguile/async.x"