[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 01/15: Refactor thread safety for %port-property
From: |
Andy Wingo |
Subject: |
[Guile-commits] 01/15: Refactor thread safety for %port-property |
Date: |
Tue, 26 Apr 2016 21:38:51 +0000 |
wingo pushed a commit to branch wip-port-refactor
in repository guile.
commit 3e951f7dfc6260da597e7677120a5f012c943bff
Author: Andy Wingo <address@hidden>
Date: Fri Apr 22 16:23:42 2016 +0200
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.
---
libguile/ports.c | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/libguile/ports.c b/libguile/ports.c
index ed387c6..0a424e0 100644
--- a/libguile/ports.c
+++ b/libguile/ports.c
@@ -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}.")
#define FUNC_NAME s_scm_i_port_property
{
- scm_i_pthread_mutex_t *lock;
SCM result;
+ scm_t_port *pt;
SCM_VALIDATE_OPPORT (1, port);
- 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);
+
+ pt = SCM_PTAB_ENTRY (port);
+ scm_i_pthread_mutex_lock (pt->lock);
+ result = scm_assq_ref (pt->internal->alist, key);
+ scm_i_pthread_mutex_unlock (pt->lock);
+
return result;
}
#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}.")
#define FUNC_NAME s_scm_i_set_port_property_x
{
- scm_i_pthread_mutex_t *lock;
- scm_t_port_internal *pti;
+ scm_t_port *pt;
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);
+
+ pt = SCM_PTAB_ENTRY (port);
+ scm_i_pthread_mutex_lock (pt->lock);
+ pt->internal->alist = scm_assq_set_x (pt->internal->alist, key, value);
+ scm_i_pthread_mutex_unlock (pt->lock);
+
return SCM_UNSPECIFIED;
}
#undef FUNC_NAME
- [Guile-commits] branch wip-port-refactor updated (5a342f6 -> 15d5304), Andy Wingo, 2016/04/26
- [Guile-commits] 01/15: Refactor thread safety for %port-property,
Andy Wingo <=
- [Guile-commits] 03/15: scm_c_read instead of scm_c_read_unlock, Andy Wingo, 2016/04/26
- [Guile-commits] 02/15: Refactor to internal get/peek-byte functions, Andy Wingo, 2016/04/26
- [Guile-commits] 04/15: Remove port rw_active field, Andy Wingo, 2016/04/26
- [Guile-commits] 08/15: Remove scm_unget_{byte,bytes}_unlocked, Andy Wingo, 2016/04/26
- [Guile-commits] 06/15: Remove scm_c_read_bytes_unlocked, Andy Wingo, 2016/04/26
- [Guile-commits] 10/15: Remove locking in scm_end_input, Andy Wingo, 2016/04/26
- [Guile-commits] 05/15: Remove scm_flush_unlocked / scm_end_input_unlocked, Andy Wingo, 2016/04/26
- [Guile-commits] 11/15: Remove scm_fill_input_unlocked, Andy Wingo, 2016/04/26
- [Guile-commits] 09/15: scm_ungetc, scm_ungets instead of _unlocked variants, Andy Wingo, 2016/04/26
- [Guile-commits] 07/15: Replace scm_getc with scm_getc_unlocked, Andy Wingo, 2016/04/26