Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-8]: src/lib/libc/gen Pull up following revision(s) (requested by ...
details: https://anonhg.NetBSD.org/src/rev/b94f3fc9b92e
branches: netbsd-8
changeset: 447903:b94f3fc9b92e
user: martin <martin%NetBSD.org@localhost>
date: Sun Jan 27 18:25:52 2019 +0000
description:
Pull up following revision(s) (requested by christos in ticket #1170):
lib/libc/gen/popen.c: revision 1.36
PR/53904: Jintao Zhu: Use a mutex instead of an rwlock to assure thread safety
diffstat:
lib/libc/gen/popen.c | 55 +++++++++++++++++++++++----------------------------
1 files changed, 25 insertions(+), 30 deletions(-)
diffs (132 lines):
diff -r cb2fc3a1d775 -r b94f3fc9b92e lib/libc/gen/popen.c
--- a/lib/libc/gen/popen.c Thu Jan 24 15:36:05 2019 +0000
+++ b/lib/libc/gen/popen.c Sun Jan 27 18:25:52 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: popen.c,v 1.35 2015/02/02 22:07:05 christos Exp $ */
+/* $NetBSD: popen.c,v 1.35.8.1 2019/01/27 18:25:52 martin Exp $ */
/*
* Copyright (c) 1988, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)popen.c 8.3 (Berkeley) 5/3/95";
#else
-__RCSID("$NetBSD: popen.c,v 1.35 2015/02/02 22:07:05 christos Exp $");
+__RCSID("$NetBSD: popen.c,v 1.35.8.1 2019/01/27 18:25:52 martin Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -73,7 +73,20 @@
} *pidlist;
#ifdef _REENTRANT
-static rwlock_t pidlist_lock = RWLOCK_INITIALIZER;
+static mutex_t pidlist_mutex = MUTEX_INITIALIZER;
+# define MUTEX_LOCK() \
+ do { \
+ if (__isthreaded) \
+ mutex_lock(&pidlist_mutex); \
+ } while (/*CONSTCOND*/0)
+# define MUTEX_UNLOCK() \
+ do { \
+ if (__isthreaded) \
+ mutex_unlock(&pidlist_mutex); \
+ } while (/*CONSTCOND*/0)
+#else
+# define MUTEX_LOCK() __nothing
+# define MUTEX_UNLOCK() __nothing
#endif
static struct pid *
@@ -183,17 +196,13 @@
if ((cur = pdes_get(pdes, &type)) == NULL)
return NULL;
-#ifdef _REENTRANT
- (void)rwlock_rdlock(&pidlist_lock);
-#endif
+ MUTEX_LOCK();
(void)__readlockenv();
switch (pid = vfork()) {
case -1: /* Error. */
serrno = errno;
(void)__unlockenv();
-#ifdef _REENTRANT
- (void)rwlock_unlock(&pidlist_lock);
-#endif
+ MUTEX_UNLOCK();
pdes_error(pdes, cur);
errno = serrno;
return NULL;
@@ -208,9 +217,7 @@
pdes_parent(pdes, cur, pid, type);
-#ifdef _REENTRANT
- (void)rwlock_unlock(&pidlist_lock);
-#endif
+ MUTEX_UNLOCK();
return cur->fp;
}
@@ -228,15 +235,11 @@
if ((cur = pdes_get(pdes, &type)) == NULL)
return NULL;
-#ifdef _REENTRANT
- (void)rwlock_rdlock(&pidlist_lock);
-#endif
+ MUTEX_LOCK();
switch (pid = vfork()) {
case -1: /* Error. */
serrno = errno;
-#ifdef _REENTRANT
- (void)rwlock_unlock(&pidlist_lock);
-#endif
+ MUTEX_UNLOCK();
pdes_error(pdes, cur);
errno = serrno;
return NULL;
@@ -250,9 +253,7 @@
pdes_parent(pdes, cur, pid, type);
-#ifdef _REENTRANT
- (void)rwlock_unlock(&pidlist_lock);
-#endif
+ MUTEX_UNLOCK();
return cur->fp;
}
@@ -271,18 +272,14 @@
_DIAGASSERT(iop != NULL);
-#ifdef _REENTRANT
- rwlock_wrlock(&pidlist_lock);
-#endif
+ MUTEX_LOCK();
/* Find the appropriate file pointer. */
for (last = NULL, cur = pidlist; cur; last = cur, cur = cur->next)
if (cur->fp == iop)
break;
if (cur == NULL) {
-#ifdef _REENTRANT
- (void)rwlock_unlock(&pidlist_lock);
-#endif
+ MUTEX_UNLOCK();
errno = ESRCH;
return -1;
}
@@ -295,9 +292,7 @@
else
last->next = cur->next;
-#ifdef _REENTRANT
- (void)rwlock_unlock(&pidlist_lock);
-#endif
+ MUTEX_UNLOCK();
do {
pid = waitpid(cur->pid, &pstat, 0);
Home |
Main Index |
Thread Index |
Old Index