[shibboleth-sp2] 28/100: Added mutex around transport array.

Ferenc Wágner wferi-guest at moszumanska.debian.org
Tue Jan 26 21:29:14 UTC 2016


This is an automated email from the git hooks/post-receive script.

wferi-guest pushed a commit to annotated tag 1.2.1
in repository shibboleth-sp2.

commit d191b886ddb5a12caf6121dcd714ef923cfb08b4
Author: Scott Cantor <cantor.2 at osu.edu>
Date:   Wed Oct 13 04:08:04 2004 +0000

    Added mutex around transport array.
---
 oncrpc/nt.c      |  4 ++++
 oncrpc/rpc/rpc.h |  5 ++++-
 oncrpc/svc.c     | 37 ++++++++++++++++++++++++++++++++++---
 3 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/oncrpc/nt.c b/oncrpc/nt.c
index 99ef500..18eda7f 100644
--- a/oncrpc/nt.c
+++ b/oncrpc/nt.c
@@ -15,6 +15,8 @@ WSADATA WSAData;
 
 static int init = 0;
 
+CRITICAL_SECTION __thr_mutex;
+
 int rpc_nt_init(void)
 {
     if (init++)
@@ -47,10 +49,12 @@ BOOL WINAPI DllMain(
     switch (fdwReason) {
         case DLL_PROCESS_ATTACH:
             __thr_key = TlsAlloc();
+            InitializeCriticalSection(&__thr_mutex);
             break;
 
         case DLL_PROCESS_DETACH:
             TlsFree(__thr_key);
+            DeleteCriticalSection(&__thr_mutex);
             break;
 
         case DLL_THREAD_DETACH: {
diff --git a/oncrpc/rpc/rpc.h b/oncrpc/rpc/rpc.h
index 6b6cbfc..53d801f 100644
--- a/oncrpc/rpc/rpc.h
+++ b/oncrpc/rpc/rpc.h
@@ -134,7 +134,10 @@ extern "C" {
 
 /* Oct 2004: Additions by Scott Cantor to support POSIX and Win32 threads. */
 #ifdef WIN32
-extern DWORD __thr_key; /* Win32 TLS key */
+extern DWORD __thr_key;
+extern CRITICAL_SECTION __thr_mutex;
+#else
+extern pthread_mutex_t __thr_mutex;
 #endif
 
 extern struct opaque_auth* _thr_null_auth(void);
diff --git a/oncrpc/svc.c b/oncrpc/svc.c
index 7bbdf7c..914ec8b 100644
--- a/oncrpc/svc.c
+++ b/oncrpc/svc.c
@@ -60,6 +60,9 @@ static char sccsid[] = "@(#)svc.c 1.41 87/10/13 Copyr 1984 Sun Micro";
 #include <sys/errno.h>
 #include <rpc/rpc.h>
 #include <rpc/pmap_clnt.h>
+#include <pthread.h>
+
+static pthread_mutex_t __thr_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 extern int errno;
 #endif
@@ -103,6 +106,11 @@ xprt_register(xprt)
 	SVCXPRT *xprt;
 {
 	register int sock = xprt->xp_sock;
+#ifdef WIN32
+    EnterCriticalSection(&__thr_mutex);
+#else
+    pthread_mutex_lock(&__thr_mutex);
+#endif
 
 #ifdef FD_SETSIZE
 	if (xports == NULL) {
@@ -142,6 +150,12 @@ xprt_register(xprt)
 		svc_fds |= (1 << sock);
 	}
 #endif /* def FD_SETSIZE */
+
+#ifdef WIN32
+    LeaveCriticalSection(&__thr_mutex);
+#else
+    pthread_mutex_unlock(&__thr_mutex);
+#endif
 }
 
 /*
@@ -152,6 +166,11 @@ xprt_unregister(xprt)
 	SVCXPRT *xprt;
 { 
 	register int sock = xprt->xp_sock;
+#ifdef WIN32
+    EnterCriticalSection(&__thr_mutex);
+#else
+    pthread_mutex_lock(&__thr_mutex);
+#endif
 
 #ifdef FD_SETSIZE
 #ifdef WIN32
@@ -170,6 +189,12 @@ xprt_unregister(xprt)
 		svc_fds &= ~(1 << sock);
 	}
 #endif /* def FD_SETSIZE */
+
+#ifdef WIN32
+    LeaveCriticalSection(&__thr_mutex);
+#else
+    pthread_mutex_unlock(&__thr_mutex);
+#endif
 }
 
 
@@ -478,20 +503,26 @@ svc_getreqset(readfds)
 	for ( i=0; i<readfds->fd_count; i++ ) {
 		sock = readfds->fd_array[i];
 		/* sock has input waiting */
-		xprt = xports[sock];
+        EnterCriticalSection(&__thr_mutex);
+        xprt = xports[sock];
+        LeaveCriticalSection(&__thr_mutex);
 #else
 	setsize = FD_SETSIZE;	
 	maskp = (u_long *)readfds->fds_bits;
 	for (sock = 0; sock < setsize; sock += NFDBITS) {
 	    for (mask = *maskp++; bit = ffs(mask); mask ^= (1 << (bit - 1))) {
 		/* sock has input waiting */
-		xprt = xports[sock + bit - 1];
+        pthread_mutex_lock(&__thr_mutex);
+        xprt = xports[sock + bit - 1];
+        pthread_mutex_unlock(&__thr_mutex);
 #endif
 #else
 	for (sock = 0; readfds_local != 0; sock++, readfds_local >>= 1) {
 	    if ((readfds_local & 1) != 0) {
 		/* sock has input waiting */
-		xprt = xports[sock];
+        pthread_mutex_lock(&__thr_mutex);
+        xprt = xports[sock];
+        pthread_mutex_unlock(&__thr_mutex);
 #endif /* def FD_SETSIZE */
 		/* now receive msgs from xprtprt (support batch calls) */
 		do {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-shibboleth/shibboleth-sp2.git



More information about the Pkg-shibboleth-devel mailing list