pkgsrc-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: pkg/51966
The following reply was made to PR pkg/51966; it has been noted by GNATS.
From: Izumi Tsutsui <tsutsui%ceres.dti.ne.jp@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: ryoon%NetBSD.org@localhost, aran%100acres.us@localhost, tsutsui%ceres.dti.ne.jp@localhost
Subject: Re: pkg/51966
Date: Sun, 25 Jun 2017 15:20:39 +0900
Hi,
I've revised Aran's patch to:
- move changes (avoid use of sem_t) inside #if defined(__NetBSD__)
- avoid use of pthread_mutex_timedlock(3) (not available on NetBSD 7.1)
-> I'm not sure if pthread_mutex_lock(3) is acceptable in this case though
It seems working on NetBSD/i386 7.1 with browser.tabs.remote.autostart.2=true
(i.e. e10s enabled).
Note for NetBSD 7.1 PR pkg/52309 (avoid PTHREAD_PRIO_INHERIT, which
is not available on 7.1 either) is also necessary.
--- shar from here ---
# This is a shell archive. Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file". Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
# patches/patch-ipc_glue_CrossProcessSemaphore.h
# patches/patch-ipc_glue_CrossProcessSemaphore__posix.cpp
#
echo x - patches/patch-ipc_glue_CrossProcessSemaphore.h
sed 's/^X//' >patches/patch-ipc_glue_CrossProcessSemaphore.h << 'END-of-patches/patch-ipc_glue_CrossProcessSemaphore.h'
X$NetBSD$
X
X- avoid use of sem_t on NetBSD
X http://mail-index.netbsd.org/pkgsrc-bugs/2017/06/23/msg062225.html
X
X--- ipc/glue/CrossProcessSemaphore.h.orig 2017-06-05 20:45:20.000000000 +0000
X+++ ipc/glue/CrossProcessSemaphore.h
X@@ -91,7 +91,13 @@ private:
X HANDLE mSemaphore;
X #elif !defined(OS_MACOSX)
X RefPtr<mozilla::ipc::SharedMemoryBasic> mSharedBuffer;
X+#if defined(__NetBSD__)
X+ pthread_mutex_t* mMutex;
X+ pthread_cond_t* mNotZero;
X+ uint32_t* mValue;
X+#else
X sem_t* mSemaphore;
X+#endif
X mozilla::Atomic<int32_t>* mRefCount;
X #endif
X };
END-of-patches/patch-ipc_glue_CrossProcessSemaphore.h
echo x - patches/patch-ipc_glue_CrossProcessSemaphore__posix.cpp
sed 's/^X//' >patches/patch-ipc_glue_CrossProcessSemaphore__posix.cpp << 'END-of-patches/patch-ipc_glue_CrossProcessSemaphore__posix.cpp'
X$NetBSD$
X
X- avoid use of sem_t on NetBSD
X http://mail-index.netbsd.org/pkgsrc-bugs/2017/06/23/msg062225.html
X
X--- ipc/glue/CrossProcessSemaphore_posix.cpp.orig 2017-06-25 05:29:49.000000000 +0000
X+++ ipc/glue/CrossProcessSemaphore_posix.cpp
X@@ -9,6 +9,11 @@
X #include "nsDebug.h"
X #include "nsISupportsImpl.h"
X #include <errno.h>
X+#if defined(__NetBSD__)
X+#include <iostream>
X+#include <unistd.h>
X+#include <limits>
X+#endif
X
X static const uint64_t kNsPerMs = 1000000;
X static const uint64_t kNsPerSec = 1000000000;
X@@ -17,7 +22,13 @@ namespace {
X
X
X struct SemaphoreData {
X+#if defined(__NetBSD__)
X+ pthread_mutex_t mMutex;
X+ pthread_cond_t mNotZero;
X+ uint32_t mValue;
X+#else
X sem_t mSemaphore;
X+#endif
X mozilla::Atomic<int32_t> mRefCount;
X uint32_t mInitialValue;
X };
X@@ -44,13 +55,27 @@ CrossProcessSemaphore::Create(const char
X return nullptr;
X }
X
X+#if defined(__NetBSD__)
X+ data->mValue = aInitialValue;
X+ if (pthread_mutex_init(&data->mMutex, NULL) ||
X+ pthread_cond_init(&data->mNotZero, NULL) ) {
X+ return nullptr;
X+ }
X+#else
X if (sem_init(&data->mSemaphore, 1, aInitialValue)) {
X return nullptr;
X }
X+#endif
X
X CrossProcessSemaphore* sem = new CrossProcessSemaphore;
X sem->mSharedBuffer = sharedBuffer;
X+#if defined(__NetBSD__)
X+ sem->mMutex = &data->mMutex;
X+ sem->mNotZero = &data->mNotZero;
X+ sem->mValue = &data->mValue;
X+#else
X sem->mSemaphore = &data->mSemaphore;
X+#endif
X sem->mRefCount = &data->mRefCount;
X *sem->mRefCount = 1;
X
X@@ -84,24 +109,44 @@ CrossProcessSemaphore::Create(CrossProce
X
X int32_t oldCount = data->mRefCount++;
X if (oldCount == 0) {
X+#if defined(__NetBSD__)
X+ if (pthread_mutex_init(&data->mMutex, NULL) ||
X+ pthread_cond_init(&data->mNotZero, NULL) ) {
X+ data->mRefCount--;
X+ return nullptr;
X+ }
X+#else
X // The other side has already let go of their CrossProcessSemaphore, so now
X // mSemaphore is garbage. We need to re-initialize it.
X if (sem_init(&data->mSemaphore, 1, data->mInitialValue)) {
X data->mRefCount--;
X return nullptr;
X }
X+#endif
X }
X
X CrossProcessSemaphore* sem = new CrossProcessSemaphore;
X sem->mSharedBuffer = sharedBuffer;
X+#if defined(__NetBSD__)
X+ sem->mMutex = &data->mMutex;
X+ sem->mNotZero = &data->mNotZero;
X+ sem->mValue = &data->mValue;
X+#else
X sem->mSemaphore = &data->mSemaphore;
X+#endif
X sem->mRefCount = &data->mRefCount;
X return sem;
X }
X
X
X CrossProcessSemaphore::CrossProcessSemaphore()
X+#if defined(__NetBSD__)
X+ : mMutex (nullptr)
X+ , mNotZero (nullptr)
X+ , mValue (nullptr)
X+#else
X : mSemaphore(nullptr)
X+#endif
X , mRefCount(nullptr)
X {
X MOZ_COUNT_CTOR(CrossProcessSemaphore);
X@@ -113,17 +158,58 @@ CrossProcessSemaphore::~CrossProcessSema
X
X if (oldCount == 0) {
X // Nothing can be done if the destroy fails so ignore return code.
X+#if defined(__NetBSD__)
X+ (void)pthread_cond_destroy(mNotZero);
X+ (void)pthread_mutex_destroy(mMutex);
X+#else
X Unused << sem_destroy(mSemaphore);
X+#endif
X }
X
X MOZ_COUNT_DTOR(CrossProcessSemaphore);
X }
X
X+#if defined(__NetBSD__)
X+static struct timespec
X+makeAbsTime(const Maybe<TimeDuration>& aWaitTime) {
X+ struct timespec ts;
X+ if (aWaitTime.isSome()) {
X+ clock_gettime(CLOCK_REALTIME, &ts);
X+ ts.tv_nsec += (kNsPerMs * aWaitTime->ToMilliseconds());
X+ ts.tv_sec += ts.tv_nsec / kNsPerSec;
X+ ts.tv_nsec %= kNsPerSec;
X+ }
X+ else {
X+ ts.tv_sec = std::numeric_limits<time_t>::max();
X+ ts.tv_nsec = 0;
X+ }
X+ return ts;
X+}
X+#endif
X+
X bool
X CrossProcessSemaphore::Wait(const Maybe<TimeDuration>& aWaitTime)
X {
X MOZ_ASSERT(*mRefCount > 0, "Attempting to wait on a semaphore with zero ref count");
X int ret;
X+#if defined(__NetBSD__)
X+ struct timespec ts = makeAbsTime(aWaitTime);
X+
X+ ret = pthread_mutex_lock(mMutex);
X+
X+ if (ret == 0) {
X+ while (ret == 0 && mValue == 0) {
X+ ret = pthread_cond_timedwait(mNotZero, mMutex, &ts);
X+ while (ret == -1 && errno == EINTR) {
X+ ret = pthread_cond_timedwait(mNotZero, mMutex, &ts);
X+ }
X+ }
X+ if (ret == 0) {
X+ --(*mValue);
X+ }
X+ pthread_mutex_unlock(mMutex);
X+ }
X+#else
X if (aWaitTime.isSome()) {
X struct timespec ts;
X if (clock_gettime(CLOCK_REALTIME, &ts) == -1) {
X@@ -142,6 +228,7 @@ CrossProcessSemaphore::Wait(const Maybe<
X continue;
X }
X }
X+#endif
X return ret == 0;
X }
X
X@@ -149,7 +236,17 @@ void
X CrossProcessSemaphore::Signal()
X {
X MOZ_ASSERT(*mRefCount > 0, "Attempting to signal a semaphore with zero ref count");
X+#if defined(__NetBSD__)
X+ int ret;
X+ ret = pthread_mutex_lock(mMutex);
X+ if (ret == 0) {
X+ ++(*mValue);
X+ pthread_cond_signal(mNotZero);
X+ pthread_mutex_unlock(mMutex);
X+ }
X+#else
X sem_post(mSemaphore);
X+#endif
X }
X
X CrossProcessSemaphoreHandle
END-of-patches/patch-ipc_glue_CrossProcessSemaphore__posix.cpp
exit
---
Izumi Tsutsui
Home |
Main Index |
Thread Index |
Old Index