pkgsrc/multimedia/handbrake/patches/patch-contrib_libbluray_P04-netbsd-pthread__equal-check.patch
ryoon 463f275a0d handbrake: Use pthread properly and fix segfault in correct way
* Bump PKGREVISION.
* From multimedia/libbluray by kamil@.
2020-02-13 23:12:37 +00:00

96 lines
2.7 KiB
Diff

$NetBSD: patch-contrib_libbluray_P04-netbsd-pthread__equal-check.patch,v 1.2 2020/02/13 23:12:37 ryoon Exp $
* mutex: Switch the POSIX backend to PTHREAD_MUTEX_RECURSIVE
https://code.videolan.org/videolan/libbluray/merge_requests/17
via multimedia/libbluray
--- contrib/libbluray/P04-netbsd-pthread_equal-check.patch.orig 2020-02-13 18:46:05.315624115 +0000
+++ contrib/libbluray/P04-netbsd-pthread_equal-check.patch
@@ -0,0 +1,87 @@
+--- libbluray-1.1.2/src/util/mutex.c.orig 2019-06-07 18:00:28.000000000 +0000
++++ libbluray-1.2.2/src/util/mutex.c
+@@ -68,18 +68,16 @@ static int _mutex_destroy(MUTEX_IMPL *p)
+
+ #elif defined(HAVE_PTHREAD_H)
+
+-typedef struct {
+- int lock_count;
+- pthread_t owner;
+- pthread_mutex_t mutex;
+-} MUTEX_IMPL;
++typedef pthread_mutex_t MUTEX_IMPL;
+
+ static int _mutex_init(MUTEX_IMPL *p)
+ {
+- p->owner = (pthread_t)-1;
+- p->lock_count = 0;
++ pthread_mutexattr_t attr;
+
+- if (pthread_mutex_init(&p->mutex, NULL)) {
++ pthread_mutexattr_init(&attr);
++ pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
++
++ if (pthread_mutex_init(p, &attr)) {
+ BD_DEBUG(DBG_BLURAY|DBG_CRIT, "pthread_mutex_init() failed !\n");
+ return -1;
+ }
+@@ -89,40 +87,17 @@ static int _mutex_init(MUTEX_IMPL *p)
+
+ static int _mutex_lock(MUTEX_IMPL *p)
+ {
+- if (pthread_equal(p->owner, pthread_self())) {
+- /* recursive lock */
+- p->lock_count++;
+- return 0;
+- }
+-
+- if (pthread_mutex_lock(&p->mutex)) {
++ if (pthread_mutex_lock(p)) {
+ BD_DEBUG(DBG_BLURAY|DBG_CRIT, "pthread_mutex_lock() failed !\n");
+ return -1;
+ }
+
+- p->owner = pthread_self();
+- p->lock_count = 1;
+-
+ return 0;
+ }
+
+ static int _mutex_unlock(MUTEX_IMPL *p)
+ {
+- if (!pthread_equal(p->owner, pthread_self())) {
+- BD_DEBUG(DBG_BLURAY|DBG_CRIT, "bd_mutex_unlock(): not owner !\n");
+- return -1;
+- }
+-
+- p->lock_count--;
+- if (p->lock_count > 0) {
+- return 0;
+- }
+-
+- /* unlock */
+-
+- p->owner = (pthread_t)-1;
+-
+- if (pthread_mutex_unlock(&p->mutex)) {
++ if (pthread_mutex_unlock(p)) {
+ BD_DEBUG(DBG_BLURAY|DBG_CRIT, "pthread_mutex_unlock() failed !\n");
+ return -1;
+ }
+@@ -132,10 +107,7 @@ static int _mutex_unlock(MUTEX_IMPL *p)
+
+ static int _mutex_destroy(MUTEX_IMPL *p)
+ {
+- _mutex_lock(p);
+- _mutex_unlock(p);
+-
+- if (pthread_mutex_destroy(&p->mutex)) {
++ if (pthread_mutex_destroy(p)) {
+ BD_DEBUG(DBG_BLURAY|DBG_CRIT, "pthread_mutex_destroy() failed !\n");
+ return -1;
+ }
+@@ -193,4 +165,3 @@ int bd_mutex_destroy(BD_MUTEX *p)
+ X_FREE(p->impl);
+ return 0;
+ }
+-