1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 19:50:24 +02:00

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.
This commit is contained in:
Mark H Weaver 2013-12-01 18:29:33 -05:00
parent 1f6f591d66
commit 79657fd3ec
2 changed files with 18 additions and 1 deletions

View file

@ -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}.") "Return the property of @var{port} associated with @var{key}.")
#define FUNC_NAME s_scm_i_port_property #define FUNC_NAME s_scm_i_port_property
{ {
scm_i_pthread_mutex_t *lock;
SCM result;
SCM_VALIDATE_OPPORT (1, port); 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 #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}.") "Set the property of @var{port} associated with @var{key} to @var{value}.")
#define FUNC_NAME s_scm_i_set_port_property_x #define FUNC_NAME s_scm_i_set_port_property_x
{ {
scm_i_pthread_mutex_t *lock;
scm_t_port_internal *pti; scm_t_port_internal *pti;
SCM_VALIDATE_OPPORT (1, port); SCM_VALIDATE_OPPORT (1, port);
scm_c_lock_port (port, &lock);
pti = SCM_PORT_GET_INTERNAL (port); pti = SCM_PORT_GET_INTERNAL (port);
pti->alist = scm_assq_set_x (pti->alist, key, value); pti->alist = scm_assq_set_x (pti->alist, key, value);
if (lock)
scm_i_pthread_mutex_unlock (lock);
return SCM_UNSPECIFIED; return SCM_UNSPECIFIED;
} }
#undef FUNC_NAME #undef FUNC_NAME

View file

@ -2157,6 +2157,10 @@ set_port_read_option (SCM port, int option, int new_value)
unsigned int read_options; unsigned int read_options;
new_value &= READ_OPTION_MASK; 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); 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)) if (scm_is_unsigned_integer (scm_read_options, 0, READ_OPTIONS_MAX_VALUE))
read_options = scm_to_uint (scm_read_options); 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; read_options |= new_value << option;
scm_read_options = scm_from_uint (read_options); scm_read_options = scm_from_uint (read_options);
scm_i_set_port_property_x (port, sym_port_read_options, scm_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. */ /* Set OPTS and PORT's case-insensitivity according to VALUE. */