Threading changes.
[bpt/guile.git] / libguile / ports.c
index 5fe928a..b0ede66 100644 (file)
@@ -29,6 +29,7 @@
 #include "libguile/_scm.h"
 #include "libguile/eval.h"
 #include "libguile/objects.h"
+#include "libguile/goops.h"
 #include "libguile/smob.h"
 #include "libguile/chars.h"
 #include "libguile/dynwind.h"
@@ -492,7 +493,7 @@ scm_t_port **scm_i_port_table;
 long scm_i_port_table_size = 0;        /* Number of ports in scm_i_port_table.  */
 long scm_i_port_table_room = 20;       /* Size of the array.  */
 
-SCM_GLOBAL_MUTEX (scm_i_port_table_mutex);
+pthread_mutex_t scm_i_port_table_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 /* This function is not and should not be thread safe. */
 
@@ -763,9 +764,9 @@ SCM_DEFINE (scm_close_port, "close-port", 1, 0, 0,
     rv = (scm_ptobs[i].close) (port);
   else
     rv = 0;
-  scm_mutex_lock (&scm_i_port_table_mutex);
+  scm_pthread_mutex_lock (&scm_i_port_table_mutex);
   scm_remove_from_port_table (port);
-  scm_mutex_unlock (&scm_i_port_table_mutex);
+  pthread_mutex_unlock (&scm_i_port_table_mutex);
   SCM_CLR_PORT_OPEN_FLAG (port);
   return scm_from_bool (rv >= 0);
 }
@@ -814,21 +815,21 @@ scm_c_port_for_each (void (*proc)(void *data, SCM p), void *data)
      can change arbitrarily (from a GC, for example).  So we first
      collect the ports into a vector. -mvo */
 
-  scm_mutex_lock (&scm_i_port_table_mutex);
+  scm_pthread_mutex_lock (&scm_i_port_table_mutex);
   n = scm_i_port_table_size;
-  scm_mutex_unlock (&scm_i_port_table_mutex);
+  pthread_mutex_unlock (&scm_i_port_table_mutex);
 
-  ports = scm_make_vector (scm_from_size_t (n), SCM_BOOL_F);
+  ports = scm_c_make_vector (n, SCM_BOOL_F);
 
-  scm_mutex_lock (&scm_i_port_table_mutex);
+  scm_pthread_mutex_lock (&scm_i_port_table_mutex);
   if (n > scm_i_port_table_size)
     n = scm_i_port_table_size;
   for (i = 0; i < n; i++)
-    SCM_VECTOR_SET (ports, i, scm_i_port_table[i]->port);
-  scm_mutex_unlock (&scm_i_port_table_mutex);
+    SCM_SIMPLE_VECTOR_SET (ports, i, scm_i_port_table[i]->port);
+  pthread_mutex_unlock (&scm_i_port_table_mutex);
 
   for (i = 0; i < n; i++)
-    proc (data, SCM_VECTOR_REF (ports, i));
+    proc (data, SCM_SIMPLE_VECTOR_REF (ports, i));
 }
 
 SCM_DEFINE (scm_port_for_each, "port-for-each", 1, 0, 0,
@@ -937,13 +938,13 @@ SCM_DEFINE (scm_flush_all_ports, "flush-all-ports", 0, 0, 0,
 {
   size_t i;
 
-  scm_mutex_lock (&scm_i_port_table_mutex);
+  scm_pthread_mutex_lock (&scm_i_port_table_mutex);
   for (i = 0; i < scm_i_port_table_size; i++)
     {
       if (SCM_OPOUTPORTP (scm_i_port_table[i]->port))
        scm_flush (scm_i_port_table[i]->port);
     }
-  scm_mutex_unlock (&scm_i_port_table_mutex);
+  pthread_mutex_unlock (&scm_i_port_table_mutex);
   return SCM_UNSPECIFIED;
 }
 #undef FUNC_NAME
@@ -1010,9 +1011,17 @@ scm_getc (SCM port)
 
   switch (c)
     {
+      case '\a':
+        break;
+      case '\b':
+        SCM_DECCOL (port);
+        break;
       case '\n':
         SCM_INCLINE (port);
         break;
+      case '\r':
+        SCM_ZEROCOL (port);
+        break;
       case '\t':
         SCM_TABCOL (port);
         break;
@@ -1053,9 +1062,17 @@ scm_lfwrite (const char *ptr, size_t size, SCM port)
   ptob->write (port, ptr, size);
 
   for (; size; ptr++, size--) {
-    if (*ptr == '\n') {
+    if (*ptr == '\a') {
+    }
+    else if (*ptr == '\b') {
+      SCM_DECCOL(port);
+    }
+    else if (*ptr == '\n') {
       SCM_INCLINE(port);
     }
+    else if (*ptr == '\r') {
+      SCM_ZEROCOL(port);
+    }
     else if (*ptr == '\t') {
       SCM_TABCOL(port);
     }
@@ -1588,7 +1605,7 @@ scm_port_print (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED)
   scm_print_port_mode (exp, port);
   scm_puts (type, port);
   scm_putc (' ', port);
-  scm_intprint (SCM_CELL_WORD_1 (exp), 16, port);
+  scm_uintprint (SCM_CELL_WORD_1 (exp), 16, port);
   scm_putc ('>', port);
   return 1;
 }
@@ -1621,7 +1638,7 @@ write_void_port (SCM port SCM_UNUSED,
 static SCM
 scm_i_void_port (long mode_bits)
 {
-  scm_mutex_lock (&scm_i_port_table_mutex);
+  scm_pthread_mutex_lock (&scm_i_port_table_mutex);
   {
     SCM answer = scm_new_port_table_entry (scm_tc16_void_port);
     scm_t_port * pt = SCM_PTAB_ENTRY(answer);
@@ -1630,7 +1647,7 @@ scm_i_void_port (long mode_bits)
   
     SCM_SETSTREAM (answer, 0);
     SCM_SET_CELL_TYPE (answer, scm_tc16_void_port | mode_bits);
-    scm_mutex_unlock (&scm_i_port_table_mutex);
+    pthread_mutex_unlock (&scm_i_port_table_mutex);
     return answer;
   }
 }