guile-commits
[Top][All Lists]
Advanced

[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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]