mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 11:40:18 +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:
parent
1f6f591d66
commit
79657fd3ec
2 changed files with 18 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue