[Mono-list] Checking for implementation of _POSIX_THREAD_PROCESS_SHARED

Juli Mallett jmallett@FreeBSD.ORG
Wed, 11 Dec 2002 17:38:26 -0800


There's a bug in how _POSIX_THREAD_PROCESS_SHARED is checked for, which
is fixed by FreeBSD's ports tree's patches, which is irrelevant since we
seem to unconditionally undef _POSIX_THREAD_PROCESS_SHARED, but is important
for correct semantics later.  With _POSIX_THREAD_PROCESS_SHARED (and all
similar POSIX support symbols), an ifdef check is not the correct way to
check if it is supported.  Such a symbol may be defined, but have the value
-1 to denote that it is unimplemented (or not supported).

Here's diff incl. changelog:
%%%
Index: ChangeLog
===================================================================
RCS file: /cvs/public/mono/mono/io-layer/ChangeLog,v
retrieving revision 1.99
diff -b -d -w -u -r1.99 ChangeLog
--- ChangeLog	8 Dec 2002 13:50:17 -0000	1.99
+++ ChangeLog	12 Dec 2002 01:34:54 -0000
@@ -1,3 +1,11 @@
+2002-12-11  Juli Mallett  <jmallett@FreeBSD.org>
+
+	* daemon.c, handles-private.h, handles.c, wapi-private.h:
+	Check for an implementation which says it supports
+	_POSIX_THREAD_PROCESS_SHARED, rather than just one that
+	defines the symbol.  Defined but with a value of -1 still
+	means that it is unsupported.
+
 2002-12-08  Martin Baulig  <martin@ximian.com>
 
 	* handles.c (_wapi_handle_new): Create new non-shared handles with
Index: daemon.c
===================================================================
RCS file: /cvs/public/mono/mono/io-layer/daemon.c,v
retrieving revision 1.23
diff -b -d -w -u -r1.23 daemon.c
--- daemon.c	7 Oct 2002 10:21:10 -0000	1.23
+++ daemon.c	12 Dec 2002 01:34:54 -0000
@@ -250,7 +250,7 @@
 		
 		_wapi_handle_ops_close_shared (GUINT_TO_POINTER (handle));
 		
-#ifdef _POSIX_THREAD_PROCESS_SHARED
+#if defined(_POSIX_THREAD_PROCESS_SHARED) && _POSIX_THREAD_PROCESS_SHARED != -1 		mono_mutex_destroy (&_wapi_shared_data->handles[handle].signal_mutex);
 		pthread_cond_destroy (&_wapi_shared_data->handles[handle].signal_cond);
 #endif
@@ -400,7 +400,7 @@
 
 		thread_handle->exitstatus=0;
 
-#ifdef _POSIX_THREAD_PROCESS_SHARED
+#if defined(_POSIX_THREAD_PROCESS_SHARED) && _POSIX_THREAD_PROCESS_SHARED != -1 		_wapi_handle_lock_handle (handle);
 		_wapi_handle_set_signal_state (handle, TRUE, TRUE);
 		_wapi_handle_unlock_handle (handle);
@@ -463,7 +463,7 @@
 		_wapi_timeval_to_filetime (&tv,
 					   &process_handle_data->exit_time);
 
-#ifdef _POSIX_THREAD_PROCESS_SHARED
+#if defined(_POSIX_THREAD_PROCESS_SHARED) && _POSIX_THREAD_PROCESS_SHARED != -1 		_wapi_handle_lock_handle (process_handle);
 		_wapi_handle_set_signal_state (process_handle, TRUE, TRUE);
 		_wapi_handle_unlock_handle (process_handle);
Index: handles-private.h
===================================================================
RCS file: /cvs/public/mono/mono/io-layer/handles-private.h,v
retrieving revision 1.9
diff -b -d -w -u -r1.9 handles-private.h
--- handles-private.h	27 Sep 2002 12:02:56 -0000	1.9
+++ handles-private.h	12 Dec 2002 01:34:54 -0000
@@ -109,7 +109,7 @@
 		/* Tell everyone blocking on multiple handles that something
 		 * was signalled
 		 */
-#ifdef _POSIX_THREAD_PROCESS_SHARED
+#if defined(_POSIX_THREAD_PROCESS_SHARED) && _POSIX_THREAD_PROCESS_SHARED != -1 		mono_mutex_lock (&_wapi_shared_data->signal_mutex);
 		pthread_cond_broadcast (&_wapi_shared_data->signal_cond);
 		mono_mutex_unlock (&_wapi_shared_data->signal_mutex);
@@ -144,7 +144,7 @@
 #ifdef DEBUG
 	g_message (G_GNUC_PRETTY_FUNCTION ": lock global signal mutex");
 #endif
-#ifdef _POSIX_THREAD_PROCESS_SHARED
+#if defined(_POSIX_THREAD_PROCESS_SHARED) && _POSIX_THREAD_PROCESS_SHARED != -1 	return(mono_mutex_lock (&_wapi_shared_data->signal_mutex));
 #else
 	return(mono_mutex_lock (&_wapi_private_data->signal_mutex));
@@ -156,7 +156,7 @@
 #ifdef DEBUG
 	g_message (G_GNUC_PRETTY_FUNCTION ": unlock global signal mutex");
 #endif
-#ifdef _POSIX_THREAD_PROCESS_SHARED
+#if defined(_POSIX_THREAD_PROCESS_SHARED) && _POSIX_THREAD_PROCESS_SHARED != -1 	return(mono_mutex_unlock (&_wapi_shared_data->signal_mutex));
 #else
 	return(mono_mutex_unlock (&_wapi_private_data->signal_mutex));
Index: handles.c
===================================================================
RCS file: /cvs/public/mono/mono/io-layer/handles.c,v
retrieving revision 1.28
diff -b -d -w -u -r1.28 handles.c
--- handles.c	8 Dec 2002 13:50:17 -0000	1.28
+++ handles.c	12 Dec 2002 01:34:55 -0000
@@ -147,7 +147,7 @@
 	pthread_mutexattr_init (&mutex_shared_attr);
 	pthread_condattr_init (&cond_shared_attr);
 
-#ifdef _POSIX_THREAD_PROCESS_SHARED
+#if defined(_POSIX_THREAD_PROCESS_SHARED) && _POSIX_THREAD_PROCESS_SHARED != -1 	pthread_mutexattr_setpshared (&mutex_shared_attr,
 				      PTHREAD_PROCESS_SHARED);
 	pthread_condattr_setpshared (&cond_shared_attr,
@@ -179,7 +179,7 @@
 			last=i+1;
 			shared->type=type;
 			shared->signalled=FALSE;
-#ifdef _POSIX_THREAD_PROCESS_SHARED
+#if defined(_POSIX_THREAD_PROCESS_SHARED) && _POSIX_THREAD_PROCESS_SHARED != -1 			mono_mutex_init (&_wapi_shared_data->handles[i].signal_mutex, &mutex_shared_attr);
 			pthread_cond_init (&_wapi_shared_data->handles[i].signal_cond, &cond_shared_attr);
 #endif
@@ -255,7 +255,7 @@
 		return(GUINT_TO_POINTER (_WAPI_HANDLE_INVALID));
 	}
 
-#ifndef _POSIX_THREAD_PROCESS_SHARED
+#if !defined(_POSIX_THREAD_PROCESS_SHARED) || _POSIX_THREAD_PROCESS_SHARED == -1
 	mono_mutex_init (&_wapi_shared_data->handles[idx].signal_mutex, &mutex_shared_attr);
 	pthread_cond_init (&_wapi_shared_data->handles[idx].signal_cond, &cond_shared_attr);
 #endif
@@ -412,7 +412,7 @@
 			memset (&_wapi_shared_data->handles[idx].u, '\0', sizeof(_wapi_shared_data->handles[idx].u));
 		
 		}
-#ifndef _POSIX_THREAD_PROCESS_SHARED
+#if !defined(_POSIX_THREAD_PROCESS_SHARED) || _POSIX_THREAD_PROCESS_SHARED == -1
 		else {
 			mono_mutex_destroy (&_wapi_shared_data->handles[idx].signal_mutex);
 			pthread_cond_destroy (&_wapi_shared_data->handles[idx].signal_cond);
@@ -1013,7 +1013,7 @@
  */
 int _wapi_handle_wait_signal (void)
 {
-#ifdef _POSIX_THREAD_PROCESS_SHARED
+#if defined(_POSIX_THREAD_PROCESS_SHARED) && _POSIX_THREAD_PROCESS_SHARED != -1 	return(mono_cond_wait (&_wapi_shared_data->signal_cond,
 			       &_wapi_shared_data->signal_mutex));
 #else
@@ -1035,7 +1035,7 @@
 
 int _wapi_handle_timedwait_signal (struct timespec *timeout)
 {
-#ifdef _POSIX_THREAD_PROCESS_SHARED
+#if defined(_POSIX_THREAD_PROCESS_SHARED) && _POSIX_THREAD_PROCESS_SHARED != -1 	return(mono_cond_timedwait (&_wapi_shared_data->signal_cond,
 				    &_wapi_shared_data->signal_mutex,
 				    timeout));
@@ -1067,7 +1067,7 @@
 
 int _wapi_handle_wait_signal_handle (gpointer handle)
 {
-#ifdef _POSIX_THREAD_PROCESS_SHARED
+#if defined(_POSIX_THREAD_PROCESS_SHARED) && _POSIX_THREAD_PROCESS_SHARED != -1 	guint32 idx=GPOINTER_TO_UINT (handle);
 	
 	return(mono_cond_wait (&_wapi_shared_data->handles[idx].signal_cond,
@@ -1093,7 +1093,7 @@
 int _wapi_handle_timedwait_signal_handle (gpointer handle,
 					  struct timespec *timeout)
 {
-#ifdef _POSIX_THREAD_PROCESS_SHARED
+#if defined(_POSIX_THREAD_PROCESS_SHARED) && _POSIX_THREAD_PROCESS_SHARED != -1 	guint32 idx=GPOINTER_TO_UINT (handle);
 	
 	return(mono_cond_timedwait (&_wapi_shared_data->handles[idx].signal_cond,
Index: wapi-private.h
===================================================================
RCS file: /cvs/public/mono/mono/io-layer/wapi-private.h,v
retrieving revision 1.19
diff -b -d -w -u -r1.19 wapi-private.h
--- wapi-private.h	2 Oct 2002 17:00:17 -0000	1.19
+++ wapi-private.h	12 Dec 2002 01:34:55 -0000
@@ -106,7 +106,7 @@
 	guchar daemon[MONO_SIZEOF_SUNPATH];
 	_wapi_daemon_status daemon_running;
 	
-#ifdef _POSIX_THREAD_PROCESS_SHARED
+#if defined(_POSIX_THREAD_PROCESS_SHARED) && _POSIX_THREAD_PROCESS_SHARED != -1 	mono_mutex_t signal_mutex;
 	pthread_cond_t signal_cond;
 #endif
@@ -134,7 +134,7 @@
  */
 struct _WapiHandlePrivate_list
 {
-#ifndef _POSIX_THREAD_PROCESS_SHARED
+#if !defined(_POSIX_THREAD_PROCESS_SHARED) || _POSIX_THREAD_PROCESS_SHARED == -1
 	mono_mutex_t signal_mutex;
 	pthread_cond_t signal_cond;
 #endif
%%%

I'd like to commit this some time tonight or tomorrow, if nobody objects.

Thanx,
juli.
-- 
Juli Mallett <jmallett@FreeBSD.org>
OpenDarwin, Mono, FreeBSD Developer.
ircd-hybrid Developer, EFnet addict.
FreeBSD on MIPS-Anything on FreeBSD.