guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] GNU Guile branch, master, updated. release_1-9-11-304-gf


From: Ludovic Courtès
Subject: [Guile-commits] GNU Guile branch, master, updated. release_1-9-11-304-gf57fdf0
Date: Thu, 02 Sep 2010 12:45:08 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Guile".

http://git.savannah.gnu.org/cgit/guile.git/commit/?id=f57fdf07d6374028f35bcb1ee748a94022deda6d

The branch, master has been updated
       via  f57fdf07d6374028f35bcb1ee748a94022deda6d (commit)
       via  d31ae2c363cf92b62260e9513534c7c046a4315f (commit)
      from  ac37b82d5bc0bc7fc5777b069a7f198622b6cbb7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit f57fdf07d6374028f35bcb1ee748a94022deda6d
Author: Ludovic Courtès <address@hidden>
Date:   Thu Sep 2 14:42:14 2010 +0200

    Fix memory leak in `lock-mutex' (aka. `scm_lock_mutex'.)
    
    The memory leak is trivially reproducible with:
    
      (define m (make-mutex))
      (let loop () (lock-mutex m) (unlock-mutex m) (loop))
    
    or similarly with:
    
      (define p (delay (+ 1 2)))
      (let loop () (force p) (loop))
    
    since `force' acquires P's mutex.
    
    It could also lead to premature release of a thread waiting in
    `fat_mutex_lock' when a former owner's `do_thread_exit' is run.
    
    * libguile/threads.c (fat_mutex_unlock): When `m->level' becomes 0,
      remove MUTEX from `t->mutexes'.
      (fat_mutex_lock): Update comment above the `t->mutexes' assignment.
      (do_thread_exit): Add an assertion making sure that each mutex in
      `t->mutexes' is owned by T.

commit d31ae2c363cf92b62260e9513534c7c046a4315f
Author: Ludovic Courtès <address@hidden>
Date:   Thu Sep 2 11:22:01 2010 +0200

    Avoid calls to `scm_current_thread' in `fat_mutex_unlock'.
    
    * libguile/threads.c (fat_mutex_unlock): Use `t->handle' instead of
      calling `scm_current_thread'.

-----------------------------------------------------------------------

Summary of changes:
 libguile/threads.c |   33 ++++++++++++++++++++++++---------
 1 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/libguile/threads.c b/libguile/threads.c
index 7c377d7..8249ebf 100644
--- a/libguile/threads.c
+++ b/libguile/threads.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995,1996,1997,1998,2000,2001, 2002, 2003, 2004, 2005, 2006, 
2007, 2008, 2009 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1997,1998,2000,2001, 2002, 2003, 2004, 2005, 2006, 
2007, 2008, 2009, 2010 Free Software Foundation, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
@@ -38,6 +38,8 @@
 #include <sys/time.h>
 #endif
 
+#include <assert.h>
+
 #include "libguile/validate.h"
 #include "libguile/root.h"
 #include "libguile/eval.h"
@@ -466,7 +468,12 @@ do_thread_exit (void *v)
          fat_mutex *m  = SCM_MUTEX_DATA (mutex);
 
          scm_i_pthread_mutex_lock (&m->lock);
+
+         /* Since MUTEX is in `t->mutexes', T must be its owner.  */
+         assert (scm_is_eq (m->owner, t->handle));
+
          unblock_from_queue (m->waiting);
+
          scm_i_pthread_mutex_unlock (&m->lock);
        }
 
@@ -1234,10 +1241,10 @@ fat_mutex_lock (SCM mutex, scm_t_timespec *timeout, SCM 
owner, int *ret)
              scm_i_pthread_mutex_lock (&t->admin_mutex);
 
              /* Only keep a weak reference to MUTEX so that it's not
-                retained when not referenced elsewhere (bug #27450).  Note
-                that the weak pair itself it still retained, but it's better
-                than retaining MUTEX and the threads referred to by its
-                associated queue.  */
+                retained when not referenced elsewhere (bug #27450).
+                The weak pair itself is eventually removed when MUTEX
+                is unlocked.  Note that `t->mutexes' lists mutexes
+                currently held by T, so it should be small.  */
              t->mutexes = scm_weak_car_pair (mutex, t->mutexes);
 
              scm_i_pthread_mutex_unlock (&t->admin_mutex);
@@ -1381,7 +1388,7 @@ fat_mutex_unlock (SCM mutex, SCM cond,
 
   owner = m->owner;
 
-  if (!scm_is_eq (owner, scm_current_thread ()))
+  if (!scm_is_eq (owner, t->handle))
     {
       if (m->level == 0)
        {
@@ -1390,7 +1397,7 @@ fat_mutex_unlock (SCM mutex, SCM cond,
              scm_i_pthread_mutex_unlock (&m->lock);
              scm_misc_error (NULL, "mutex not locked", SCM_EOL);
            }
-         owner = scm_current_thread ();
+         owner = t->handle;
        }
       else if (!m->allow_external_unlock)
        {
@@ -1409,7 +1416,11 @@ fat_mutex_unlock (SCM mutex, SCM cond,
          if (m->level > 0)
            m->level--;
          if (m->level == 0)
-           m->owner = unblock_from_queue (m->waiting);
+           {
+             /* Change the owner of MUTEX.  */
+             t->mutexes = scm_delq_x (mutex, t->mutexes);
+             m->owner = unblock_from_queue (m->waiting);
+           }
 
          t->block_asyncs++;
 
@@ -1453,7 +1464,11 @@ fat_mutex_unlock (SCM mutex, SCM cond,
       if (m->level > 0)
        m->level--;
       if (m->level == 0)
-       m->owner = unblock_from_queue (m->waiting);
+       {
+         /* Change the owner of MUTEX.  */
+         t->mutexes = scm_delq_x (mutex, t->mutexes);
+         m->owner = unblock_from_queue (m->waiting);
+       }
 
       scm_i_pthread_mutex_unlock (&m->lock);
       ret = 1;


hooks/post-receive
-- 
GNU Guile



reply via email to

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