ab295a
From 2ec58402d05eb12d0b9387963941f1e445d9aa5b Mon Sep 17 00:00:00 2001
ab295a
From: Jitka Plesnikova <jplesnik@redhat.com>
ab295a
Date: Fri, 26 Apr 2019 15:00:30 +0200
ab295a
Subject: [PATCH] Upgrade to 1.60
ab295a
ab295a
---
ab295a
 lib/threads/shared.pm |  4 ++--
ab295a
 shared.xs             | 39 +++++++++++++++++++++++++++++++++++++++
ab295a
 2 files changed, 41 insertions(+), 2 deletions(-)
ab295a
ab295a
diff --git a/lib/threads/shared.pm b/lib/threads/shared.pm
ab295a
index f7e5ff8..45ad154 100644
ab295a
--- a/lib/threads/shared.pm
ab295a
+++ b/lib/threads/shared.pm
ab295a
@@ -8,7 +8,7 @@ use Config;
ab295a
 
ab295a
 use Scalar::Util qw(reftype refaddr blessed);
ab295a
 
ab295a
-our $VERSION = '1.59'; # Please update the pod, too.
ab295a
+our $VERSION = '1.60'; # Please update the pod, too.
ab295a
 my $XS_VERSION = $VERSION;
ab295a
 $VERSION = eval $VERSION;
ab295a
 
ab295a
@@ -196,7 +196,7 @@ threads::shared - Perl extension for sharing data structures between threads
ab295a
 
ab295a
 =head1 VERSION
ab295a
 
ab295a
-This document describes threads::shared version 1.59
ab295a
+This document describes threads::shared version 1.60
ab295a
 
ab295a
 =head1 SYNOPSIS
ab295a
 
ab295a
diff --git a/shared.xs b/shared.xs
ab295a
index d0f7d1e..6cdf094 100644
ab295a
--- a/shared.xs
ab295a
+++ b/shared.xs
ab295a
@@ -115,6 +115,17 @@
ab295a
  * without the prefix (e.g., sv, tmp or obj).
ab295a
  */
ab295a
 
ab295a
+/* this is lower overhead than warn() and less likely to interfere
ab295a
+   with other parts of perl (like with the debugger.)
ab295a
+*/
ab295a
+#ifdef SHARED_TRACE_LOCKS
ab295a
+#  define TRACE_LOCK(x) DEBUG_U(x)
ab295a
+#  define TRACE_LOCKv(x) DEBUG_Uv(x)
ab295a
+#else
ab295a
+#  define TRACE_LOCK(x)
ab295a
+#  define TRACE_LOCKv(x)
ab295a
+#endif
ab295a
+
ab295a
 #define PERL_NO_GET_CONTEXT
ab295a
 #include "EXTERN.h"
ab295a
 #include "perl.h"
ab295a
@@ -211,8 +222,24 @@ recursive_lock_release(pTHX_ recursive_lock_t *lock)
ab295a
         if (--lock->locks == 0) {
ab295a
             lock->owner = NULL;
ab295a
             COND_SIGNAL(&lock->cond);
ab295a
+            TRACE_LOCK(
ab295a
+                    PerlIO_printf(Perl_debug_log, "shared lock released %p for %p at %s:%d\n",
ab295a
+                                  lock, aTHX, CopFILE(PL_curcop), CopLINE(PL_curcop))
ab295a
+                    );
ab295a
+        }
ab295a
+        else {
ab295a
+            TRACE_LOCKv(
ab295a
+                    PerlIO_printf(Perl_debug_log, "shared lock unbump %p for %p at %s:%d\n",
ab295a
+                                  lock, aTHX, CopFILE(PL_curcop), CopLINE(PL_curcop))
ab295a
+                    );
ab295a
         }
ab295a
     }
ab295a
+    else {
ab295a
+        TRACE_LOCK(
ab295a
+                PerlIO_printf(Perl_debug_log, "bad shared lock release %p for %p (owned by %p) at %s:%d\n",
ab295a
+                               lock, aTHX, lock->owner, CopFILE(PL_curcop), CopLINE(PL_curcop))
ab295a
+                 );
ab295a
+    }
ab295a
     MUTEX_UNLOCK(&lock->mutex);
ab295a
 }
ab295a
 
ab295a
@@ -224,8 +251,16 @@ recursive_lock_acquire(pTHX_ recursive_lock_t *lock, const char *file, int line)
ab295a
     assert(aTHX);
ab295a
     MUTEX_LOCK(&lock->mutex);
ab295a
     if (lock->owner == aTHX) {
ab295a
+        TRACE_LOCKv(
ab295a
+                 PerlIO_printf(Perl_debug_log, "shared lock bump %p (%p) at %s:%d\n",
ab295a
+                               lock, lock->owner, CopFILE(PL_curcop), CopLINE(PL_curcop))
ab295a
+                 );
ab295a
         lock->locks++;
ab295a
     } else {
ab295a
+        TRACE_LOCK(
ab295a
+                 PerlIO_printf(Perl_debug_log, "shared lock try %p for %p (owned by %p) at %s:%d\n",
ab295a
+                               lock, aTHX, lock->owner, CopFILE(PL_curcop), CopLINE(PL_curcop))
ab295a
+                 );
ab295a
         while (lock->owner) {
ab295a
 #ifdef DEBUG_LOCKS
ab295a
             Perl_warn(aTHX_ " %p waiting - owned by %p %s:%d\n",
ab295a
@@ -233,6 +268,10 @@ recursive_lock_acquire(pTHX_ recursive_lock_t *lock, const char *file, int line)
ab295a
 #endif
ab295a
             COND_WAIT(&lock->cond,&lock->mutex);
ab295a
         }
ab295a
+        TRACE_LOCK(
ab295a
+                 PerlIO_printf(Perl_debug_log, "shared lock got %p at %s:%d\n",
ab295a
+                               lock, CopFILE(PL_curcop), CopLINE(PL_curcop))
ab295a
+                 );
ab295a
         lock->locks = 1;
ab295a
         lock->owner = aTHX;
ab295a
 #ifdef DEBUG_LOCKS
ab295a
-- 
ab295a
2.20.1
ab295a