mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-12 06:41:13 +02:00
Refactor thread safety for %port-property
* libguile/ports.c (scm_i_port_property, scm_i_set_port_property_x): Knowing that the critical section can't throw, use serial lock discipline.
This commit is contained in:
parent
5a342f61c4
commit
3e951f7dfc
1 changed files with 14 additions and 12 deletions
|
@ -321,14 +321,16 @@ 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 result;
|
||||||
|
scm_t_port *pt;
|
||||||
|
|
||||||
SCM_VALIDATE_OPPORT (1, port);
|
SCM_VALIDATE_OPPORT (1, port);
|
||||||
scm_c_lock_port (port, &lock);
|
|
||||||
result = scm_assq_ref (SCM_PORT_GET_INTERNAL (port)->alist, key);
|
pt = SCM_PTAB_ENTRY (port);
|
||||||
if (lock)
|
scm_i_pthread_mutex_lock (pt->lock);
|
||||||
scm_i_pthread_mutex_unlock (lock);
|
result = scm_assq_ref (pt->internal->alist, key);
|
||||||
|
scm_i_pthread_mutex_unlock (pt->lock);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#undef FUNC_NAME
|
#undef FUNC_NAME
|
||||||
|
@ -338,15 +340,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 *pt;
|
||||||
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);
|
pt = SCM_PTAB_ENTRY (port);
|
||||||
pti->alist = scm_assq_set_x (pti->alist, key, value);
|
scm_i_pthread_mutex_lock (pt->lock);
|
||||||
if (lock)
|
pt->internal->alist = scm_assq_set_x (pt->internal->alist, key, value);
|
||||||
scm_i_pthread_mutex_unlock (lock);
|
scm_i_pthread_mutex_unlock (pt->lock);
|
||||||
|
|
||||||
return SCM_UNSPECIFIED;
|
return SCM_UNSPECIFIED;
|
||||||
}
|
}
|
||||||
#undef FUNC_NAME
|
#undef FUNC_NAME
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue