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