summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark H Weaver <mhw@netris.org>2013-12-01 18:29:33 -0500
committerMark H Weaver <mhw@netris.org>2013-12-01 18:34:30 -0500
commit79657fd3ec264ecd533a62d349c2cf1a2be2df14 (patch)
tree42359c57e8f6993da14bc75907119ae28545d08c
parent1f6f591d666a0332317374f32339cd4ec3e248e9 (diff)
downloadguile-79657fd3ec264ecd533a62d349c2cf1a2be2df14.tar.gz
Thread safe port properties.
* libguile/ports.c (scm_i_port_property, scm_i_set_port_property_x): Lock the port mutex while accessing the port alist. * libguile/read.c (set_port_read_option): Lock the port mutex while modifying port read options.
-rw-r--r--libguile/ports.c13
-rw-r--r--libguile/read.c6
2 files changed, 18 insertions, 1 deletions
diff --git a/libguile/ports.c b/libguile/ports.c
index 61bd57739..f4efce777 100644
--- a/libguile/ports.c
+++ b/libguile/ports.c
@@ -348,8 +348,15 @@ SCM_DEFINE (scm_i_port_property, "%port-property", 2, 0, 0,
"Return the property of @var{port} associated with @var{key}.")
#define FUNC_NAME s_scm_i_port_property
{
+ scm_i_pthread_mutex_t *lock;
+ SCM result;
+
SCM_VALIDATE_OPPORT (1, port);
- return scm_assq_ref (SCM_PORT_GET_INTERNAL (port)->alist, key);
+ scm_c_lock_port (port, &lock);
+ result = scm_assq_ref (SCM_PORT_GET_INTERNAL (port)->alist, key);
+ if (lock)
+ scm_i_pthread_mutex_unlock (lock);
+ return result;
}
#undef FUNC_NAME
@@ -358,11 +365,15 @@ SCM_DEFINE (scm_i_set_port_property_x, "%set-port-property!", 3, 0, 0,
"Set the property of @var{port} associated with @var{key} to @var{value}.")
#define FUNC_NAME s_scm_i_set_port_property_x
{
+ scm_i_pthread_mutex_t *lock;
scm_t_port_internal *pti;
SCM_VALIDATE_OPPORT (1, port);
+ scm_c_lock_port (port, &lock);
pti = SCM_PORT_GET_INTERNAL (port);
pti->alist = scm_assq_set_x (pti->alist, key, value);
+ if (lock)
+ scm_i_pthread_mutex_unlock (lock);
return SCM_UNSPECIFIED;
}
#undef FUNC_NAME
diff --git a/libguile/read.c b/libguile/read.c
index d1e1be372..382a1d379 100644
--- a/libguile/read.c
+++ b/libguile/read.c
@@ -2157,6 +2157,10 @@ set_port_read_option (SCM port, int option, int new_value)
unsigned int read_options;
new_value &= READ_OPTION_MASK;
+
+ scm_dynwind_begin (0);
+ scm_dynwind_lock_port (port);
+
scm_read_options = scm_i_port_property (port, sym_port_read_options);
if (scm_is_unsigned_integer (scm_read_options, 0, READ_OPTIONS_MAX_VALUE))
read_options = scm_to_uint (scm_read_options);
@@ -2166,6 +2170,8 @@ set_port_read_option (SCM port, int option, int new_value)
read_options |= new_value << option;
scm_read_options = scm_from_uint (read_options);
scm_i_set_port_property_x (port, sym_port_read_options, scm_read_options);
+
+ scm_dynwind_end ();
}
/* Set OPTS and PORT's case-insensitivity according to VALUE. */