summaryrefslogtreecommitdiff
path: root/libguile
diff options
context:
space:
mode:
Diffstat (limited to 'libguile')
-rw-r--r--libguile/ChangeLog19
-rw-r--r--libguile/fports.c10
-rw-r--r--libguile/ioext.c4
-rw-r--r--libguile/ports.c23
-rw-r--r--libguile/ports.h4
-rw-r--r--libguile/strports.c6
-rw-r--r--libguile/vports.c6
7 files changed, 53 insertions, 19 deletions
diff --git a/libguile/ChangeLog b/libguile/ChangeLog
index 4d519a1f7..98470a4e6 100644
--- a/libguile/ChangeLog
+++ b/libguile/ChangeLog
@@ -1,3 +1,22 @@
+2003-04-24 Mikael Djurfeldt <mdj@kvast.blakulla.net>
+
+ * ports.c, ports.h (scm_i_port_table_mutex): New mutex.
+
+ * fports.c (scm_evict_ports): Lock/unlock scm_i_port_table_mutex.
+
+ * ports.c (scm_close_port, scm_flush_all_ports): Ditto.
+
+ * ioext.c (scm_fdes_to_ports): Ditto.
+
+ * vports.c (scm_make_soft_port): Changed SCM_DEFER/ALLOW_INTS into
+ lock/unlock scm_i_port_table_mutex.
+
+ * strports.c (scm_mkstrport): Ditto.
+
+ * ports.c (scm_void_port, scm_port_for_each): Ditto.
+
+ * fports.c (scm_fdes_to_port): Ditto.
+
2003-04-23 Dirk Herrmann <D.Herrmann@tu-bs.de>
This set of patches contains no functional changes, only debatable
diff --git a/libguile/fports.c b/libguile/fports.c
index 392a92df3..078135a8c 100644
--- a/libguile/fports.c
+++ b/libguile/fports.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003 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
@@ -199,6 +199,8 @@ scm_evict_ports (int fd)
{
long i;
+ scm_mutex_lock (&scm_i_port_table_mutex);
+
for (i = 0; i < scm_i_port_table_size; i++)
{
SCM port = scm_i_port_table[i]->port;
@@ -216,6 +218,8 @@ scm_evict_ports (int fd)
}
}
}
+
+ scm_mutex_unlock (&scm_i_port_table_mutex);
}
@@ -415,7 +419,7 @@ scm_fdes_to_port (int fdes, char *mode, SCM name)
SCM_MISC_ERROR ("requested file mode not available on fdes", SCM_EOL);
}
- SCM_DEFER_INTS;
+ scm_mutex_lock (&scm_i_port_table_mutex);
port = scm_new_port_table_entry (scm_tc16_fport);
SCM_SET_CELL_TYPE(port, scm_tc16_fport | mode_bits);
@@ -433,7 +437,7 @@ scm_fdes_to_port (int fdes, char *mode, SCM name)
scm_fport_buffer_add (port, -1, -1);
}
SCM_SET_FILENAME (port, name);
- SCM_ALLOW_INTS;
+ scm_mutex_unlock (&scm_i_port_table_mutex);
return port;
}
#undef FUNC_NAME
diff --git a/libguile/ioext.c b/libguile/ioext.c
index a91ac6fb2..66e32cb91 100644
--- a/libguile/ioext.c
+++ b/libguile/ioext.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2003 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
@@ -282,12 +282,14 @@ SCM_DEFINE (scm_fdes_to_ports, "fdes->ports", 1, 0, 0,
SCM_VALIDATE_INUM_COPY (1, fd, int_fd);
+ scm_mutex_lock (&scm_i_port_table_mutex);
for (i = 0; i < scm_i_port_table_size; i++)
{
if (SCM_OPFPORTP (scm_i_port_table[i]->port)
&& ((scm_t_fport *) scm_i_port_table[i]->stream)->fdes == int_fd)
result = scm_cons (scm_i_port_table[i]->port, result);
}
+ scm_mutex_unlock (&scm_i_port_table_mutex);
return result;
}
#undef FUNC_NAME
diff --git a/libguile/ports.c b/libguile/ports.c
index 707d1871e..3d9c1eb11 100644
--- a/libguile/ports.c
+++ b/libguile/ports.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2003 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
@@ -431,6 +431,9 @@ 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);
+
+/* This function is not and should not be thread safe. */
SCM
scm_new_port_table_entry (scm_t_bits tag)
@@ -487,6 +490,9 @@ scm_add_to_port_table (SCM port)
/* Remove a port from the table and destroy it. */
+
+/* This function is not and should not be thread safe. */
+
void
scm_remove_from_port_table (SCM port)
#define FUNC_NAME "scm_remove_from_port_table"
@@ -679,7 +685,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_remove_from_port_table (port);
+ scm_mutex_unlock (&scm_i_port_table_mutex);
SCM_CLR_PORT_OPEN_FLAG (port);
return SCM_BOOL (rv >= 0);
}
@@ -731,21 +739,18 @@ SCM_DEFINE (scm_port_for_each, "port-for-each", 1, 0, 0,
SCM_VALIDATE_PROC (1, proc);
- /* when pre-emptive multithreading is supported, access to the port
- table will need to be controlled by a mutex. */
-
/* Even without pre-emptive multithreading, running arbitrary code
while scanning the port table is unsafe because the port table
can change arbitrarily (from a GC, for example). So we build a
list in advance while blocking the GC. -mvo */
- SCM_DEFER_INTS;
+ scm_mutex_lock (&scm_i_port_table_mutex);
scm_block_gc++;
ports = SCM_EOL;
for (i = 0; i < scm_i_port_table_size; i++)
ports = scm_cons (scm_i_port_table[i]->port, ports);
scm_block_gc--;
- SCM_ALLOW_INTS;
+ scm_mutex_unlock (&scm_i_port_table_mutex);
while (ports != SCM_EOL)
{
@@ -845,11 +850,13 @@ SCM_DEFINE (scm_flush_all_ports, "flush-all-ports", 0, 0, 0,
{
size_t i;
+ scm_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);
return SCM_UNSPECIFIED;
}
#undef FUNC_NAME
@@ -1520,7 +1527,7 @@ write_void_port (SCM port SCM_UNUSED,
SCM
scm_void_port (char *mode_str)
{
- SCM_DEFER_INTS;
+ scm_mutex_lock (&scm_i_port_table_mutex);
{
int mode_bits = scm_mode_bits (mode_str);
SCM answer = scm_new_port_table_entry (scm_tc16_void_port);
@@ -1530,7 +1537,7 @@ scm_void_port (char *mode_str)
SCM_SETSTREAM (answer, 0);
SCM_SET_CELL_TYPE (answer, scm_tc16_void_port | mode_bits);
- SCM_ALLOW_INTS;
+ scm_mutex_unlock (&scm_i_port_table_mutex);
return answer;
}
}
diff --git a/libguile/ports.h b/libguile/ports.h
index 218c60ba2..01717a5a7 100644
--- a/libguile/ports.h
+++ b/libguile/ports.h
@@ -3,7 +3,7 @@
#ifndef SCM_PORTS_H
#define SCM_PORTS_H
-/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2003 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
@@ -26,6 +26,7 @@
#include "libguile/print.h"
#include "libguile/struct.h"
+#include "libguile/threads.h"
/* Not sure if this is a good idea. We need it for off_t. */
#include <sys/types.h>
@@ -110,6 +111,7 @@ typedef struct
SCM_API scm_t_port **scm_i_port_table;
SCM_API long scm_i_port_table_size; /* Number of ports in scm_i_port_table. */
+SCM_API scm_t_mutex scm_i_port_table_mutex;
#define SCM_READ_BUFFER_EMPTY_P(c_port) (c_port->read_pos >= c_port->read_end)
diff --git a/libguile/strports.c b/libguile/strports.c
index 56daf7dfb..db43c3cf8 100644
--- a/libguile/strports.c
+++ b/libguile/strports.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995,1996,1998,1999,2000,2001,2002 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1998,1999,2000,2001,2002, 2003 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
@@ -260,7 +260,7 @@ scm_mkstrport (SCM pos, SCM str, long modes, const char *caller)
if (!((modes & SCM_WRTNG) || (modes & SCM_RDNG)))
scm_misc_error ("scm_mkstrport", "port must read or write", SCM_EOL);
- SCM_DEFER_INTS;
+ scm_mutex_lock (&scm_i_port_table_mutex);
z = scm_new_port_table_entry (scm_tc16_strport);
pt = SCM_PTAB_ENTRY(z);
SCM_SETSTREAM (z, SCM_UNPACK (str));
@@ -272,7 +272,7 @@ scm_mkstrport (SCM pos, SCM str, long modes, const char *caller)
pt->rw_random = 1;
- SCM_ALLOW_INTS;
+ scm_mutex_unlock (&scm_i_port_table_mutex);
/* ensure write_pos is writable. */
if ((modes & SCM_WRTNG) && pt->write_pos == pt->write_end)
diff --git a/libguile/vports.c b/libguile/vports.c
index ee0693fe4..a693d5323 100644
--- a/libguile/vports.c
+++ b/libguile/vports.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995,1996,1998,1999,2000,2001, 2002 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1998,1999,2000,2001, 2002, 2003 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
@@ -192,14 +192,14 @@ SCM_DEFINE (scm_make_soft_port, "make-soft-port", 2, 0, 0,
SCM_ASSERT ((vlen == 5) || (vlen == 6), pv, 1, FUNC_NAME);
SCM_VALIDATE_STRING (2, modes);
- SCM_DEFER_INTS;
+ scm_mutex_lock (&scm_i_port_table_mutex);
z = scm_new_port_table_entry (scm_tc16_sfport);
pt = SCM_PTAB_ENTRY (z);
scm_port_non_buffer (pt);
SCM_SET_CELL_TYPE (z, scm_tc16_sfport | scm_mode_bits (SCM_STRING_CHARS (modes)));
SCM_SETSTREAM (z, SCM_UNPACK (pv));
- SCM_ALLOW_INTS;
+ scm_mutex_unlock (&scm_i_port_table_mutex);
return z;
}
#undef FUNC_NAME