In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/65c7421c80585e0d12a20773935dc01f4ffa3e42?hp=83918a83a5dfae8071d366c33fa37b83aabecfc4>

- Log -----------------------------------------------------------------
commit 65c7421c80585e0d12a20773935dc01f4ffa3e42
Author: David Mitchell <[email protected]>
Date:   Fri Jun 4 17:05:21 2010 +0100

    threads::shared: veto signal despatch if locked
    
    This fixes RT #74868: Safe signals changes causing hangs with threads.
    
    The basic issue is that due to changes in where safe signals can be
    despatched, (including now on leaving scope), it's possible for a
    perl-level signal handler to be called while PL_sharedsv_lock is held.
    If the handler does locking or manipulation of shared vars, then deadlock
    can occur.
    
    A robust fix for this is to ensure that the signal handler isn't called
    while we have the lock. This is done using the signal handler hook added
    in the previous commit.

M       dist/threads-shared/shared.xs

commit 92f022bbf8c129c6f2379a382f1eaaa5c7bd9f3f
Author: David Mitchell <[email protected]>
Date:   Fri Jun 4 16:18:05 2010 +0100

    add PL_signalhook to hook into signal dispatch
    
    This is initially intended for threads::shared and shouldn't (yet)
    be considered part of the public API.

M       embedvar.h
M       intrpvar.h
M       perl.h
M       perlapi.h
M       sv.c
-----------------------------------------------------------------------

Summary of changes:
 dist/threads-shared/shared.xs |   23 +++++++++++++++++++++++
 embedvar.h                    |    2 ++
 intrpvar.h                    |    2 ++
 perl.h                        |    3 ++-
 perlapi.h                     |    2 ++
 sv.c                          |    1 +
 6 files changed, 32 insertions(+), 1 deletions(-)

diff --git a/dist/threads-shared/shared.xs b/dist/threads-shared/shared.xs
index a1c6925..720e3b6 100644
--- a/dist/threads-shared/shared.xs
+++ b/dist/threads-shared/shared.xs
@@ -1167,6 +1167,23 @@ Perl_shared_object_destroy(pTHX_ SV *sv)
 }
 #endif
 
+/* veto signal despatch if we have the lock */
+
+#ifdef PL_signalhook
+
+STATIC despatch_signals_proc_t prev_signal_hook = NULL;
+
+STATIC void
+S_shared_signal_hook(pTHX) {
+    int us;
+    MUTEX_LOCK(&PL_sharedsv_lock.mutex);
+    us = (PL_sharedsv_lock.owner == aTHX);
+    MUTEX_UNLOCK(&PL_sharedsv_lock.mutex);
+    if (us)
+       return; /* try again later */
+    CALL_FPTR(prev_signal_hook)(aTHX);
+}
+#endif
 
 /* Saves a space for keeping SVs wider than an interpreter. */
 
@@ -1184,6 +1201,12 @@ Perl_sharedsv_init(pTHX)
 #ifdef PL_destroyhook
     PL_destroyhook = &Perl_shared_object_destroy;
 #endif
+#ifdef PL_signalhook
+    if (!prev_signal_hook) {
+       prev_signal_hook = PL_signalhook;
+       PL_signalhook = &S_shared_signal_hook;
+    }
+#endif
 }
 
 #endif /* USE_ITHREADS */
diff --git a/embedvar.h b/embedvar.h
index 609e107..428147f 100644
--- a/embedvar.h
+++ b/embedvar.h
@@ -273,6 +273,7 @@
 #define PL_sharehook           (vTHX->Isharehook)
 #define PL_sig_pending         (vTHX->Isig_pending)
 #define PL_sighandlerp         (vTHX->Isighandlerp)
+#define PL_signalhook          (vTHX->Isignalhook)
 #define PL_signals             (vTHX->Isignals)
 #define PL_slab_count          (vTHX->Islab_count)
 #define PL_slabs               (vTHX->Islabs)
@@ -601,6 +602,7 @@
 #define PL_Isharehook          PL_sharehook
 #define PL_Isig_pending                PL_sig_pending
 #define PL_Isighandlerp                PL_sighandlerp
+#define PL_Isignalhook         PL_signalhook
 #define PL_Isignals            PL_signals
 #define PL_Islab_count         PL_slab_count
 #define PL_Islabs              PL_slabs
diff --git a/intrpvar.h b/intrpvar.h
index bfa613c..eb398fc 100644
--- a/intrpvar.h
+++ b/intrpvar.h
@@ -655,6 +655,8 @@ PERLVARI(Iunlockhook,       share_proc_t,   
MEMBER_TO_FPTR(PERL_UNLOCK_HOOK))
 
 PERLVARI(Ithreadhook,  thrhook_proc_t, MEMBER_TO_FPTR(Perl_nothreadhook))
 
+PERLVARI(Isignalhook,  despatch_signals_proc_t, 
MEMBER_TO_FPTR(Perl_despatch_signals))
+
 PERLVARI(Ihash_seed, UV, 0)            /* Hash initializer */
 
 PERLVARI(Irehash_seed, UV, 0)          /* 582 hash initializer */
diff --git a/perl.h b/perl.h
index c21aaa9..ea18d32 100644
--- a/perl.h
+++ b/perl.h
@@ -4189,6 +4189,7 @@ typedef void (CPERLscope(*share_proc_t)) (pTHX_ SV *sv);
 typedef int  (CPERLscope(*thrhook_proc_t)) (pTHX);
 typedef OP* (CPERLscope(*PPADDR_t)[]) (pTHX);
 typedef bool (CPERLscope(*destroyable_proc_t)) (pTHX_ SV *sv);
+typedef void (CPERLscope(*despatch_signals_proc_t)) (pTHX);
 
 /* _ (for $_) must be first in the following list (DEFSV requires it) */
 #define THREADSV_NAMES "_123456789&`'+/.,\\\";^-%=|~:\001\005!@"
@@ -5677,7 +5678,7 @@ typedef struct am_table_short AMTS;
 
 #ifndef PERL_MICRO
 #      ifndef PERL_ASYNC_CHECK
-#              define PERL_ASYNC_CHECK() if (PL_sig_pending) despatch_signals()
+#              define PERL_ASYNC_CHECK() if (PL_sig_pending) 
CALL_FPTR(PL_signalhook)(aTHX)
 #      endif
 #endif
 
diff --git a/perlapi.h b/perlapi.h
index 5b7c50b..506d72c 100644
--- a/perlapi.h
+++ b/perlapi.h
@@ -582,6 +582,8 @@ END_EXTERN_C
 #define PL_sig_pending         (*Perl_Isig_pending_ptr(aTHX))
 #undef  PL_sighandlerp
 #define PL_sighandlerp         (*Perl_Isighandlerp_ptr(aTHX))
+#undef  PL_signalhook
+#define PL_signalhook          (*Perl_Isignalhook_ptr(aTHX))
 #undef  PL_signals
 #define PL_signals             (*Perl_Isignals_ptr(aTHX))
 #undef  PL_slab_count
diff --git a/sv.c b/sv.c
index cb85ca6..c9e6f9e 100644
--- a/sv.c
+++ b/sv.c
@@ -12451,6 +12451,7 @@ perl_clone_using(PerlInterpreter *proto_perl, UV flags,
     PL_unlockhook      = proto_perl->Iunlockhook;
     PL_threadhook      = proto_perl->Ithreadhook;
     PL_destroyhook     = proto_perl->Idestroyhook;
+    PL_signalhook      = proto_perl->Isignalhook;
 
 #ifdef THREADS_HAVE_PIDS
     PL_ppid            = proto_perl->Ippid;

--
Perl5 Master Repository

Reply via email to