Author: dick
Date: 2005-04-19 12:02:40 -0400 (Tue, 19 Apr 2005)
New Revision: 43267

Modified:
   trunk/mono/mono/io-layer/ChangeLog
   trunk/mono/mono/io-layer/handles-private.h
   trunk/mono/mono/io-layer/handles.c
   trunk/mono/mono/io-layer/mutexes.c
   trunk/mono/mono/io-layer/wait.c
Log:

2005-04-19  Dick Porter  <[EMAIL PROTECTED]>

        * mutexes.c: 
        * wait.c: 
        * handles.c (_wapi_handle_count_signalled_handles)
        * handles-private.h (_wapi_handle_shared_lock_handle): Use new
        shared handle locks in critical sections.

        * handles.c (_wapi_handle_new_for_existing_ns): Reuse old
        handles if there is already one there.
        
        * handles.c (_wapi_handle_ref): It was possible for a process to
        exit before getting around to updating shared handle timestamps,
        so do it here too.




Modified: trunk/mono/mono/io-layer/ChangeLog
===================================================================
--- trunk/mono/mono/io-layer/ChangeLog  2005-04-19 15:53:09 UTC (rev 43266)
+++ trunk/mono/mono/io-layer/ChangeLog  2005-04-19 16:02:40 UTC (rev 43267)
@@ -1,4 +1,18 @@
+2005-04-19  Dick Porter  <[EMAIL PROTECTED]>
 
+       * mutexes.c: 
+       * wait.c: 
+       * handles.c (_wapi_handle_count_signalled_handles)
+       * handles-private.h (_wapi_handle_shared_lock_handle): Use new
+       shared handle locks in critical sections.
+
+       * handles.c (_wapi_handle_new_for_existing_ns): Reuse old handles
+       if there is already one there.
+       
+       * handles.c (_wapi_handle_ref): It was possible for a process to
+       exit before getting around to updating shared handle timestamps,
+       so do it here too.
+
 Tue Apr 19 16:25:47 CEST 2005 Paolo Molaro <[EMAIL PROTECTED]>
 
        * threads.c: fix lookup of the thread id in the has table:

Modified: trunk/mono/mono/io-layer/handles-private.h
===================================================================
--- trunk/mono/mono/io-layer/handles-private.h  2005-04-19 15:53:09 UTC (rev 
43266)
+++ trunk/mono/mono/io-layer/handles-private.h  2005-04-19 16:02:40 UTC (rev 
43267)
@@ -74,9 +74,10 @@
                                                      gpointer *handles,
                                                      gboolean waitall,
                                                      guint32 *retcount,
-                                                     guint32 *lowest);
+                                                     guint32 *lowest,
+                                                     guint32 *now);
 extern void _wapi_handle_unlock_handles (guint32 numhandles,
-                                        gpointer *handles);
+                                        gpointer *handles, guint32 now);
 extern int _wapi_handle_wait_signal (void);
 extern int _wapi_handle_timedwait_signal (struct timespec *timeout);
 extern int _wapi_handle_wait_signal_poll_share (void);
@@ -323,6 +324,66 @@
        nanosleep (&sleepytime, NULL);
 }
 
+static inline int _wapi_handle_shared_lock_handle (gpointer handle, guint32 
*now)
+{
+       int ret;
+       
+       g_assert (_WAPI_SHARED_HANDLE(_wapi_handle_type(handle)));
+       
+       _wapi_handle_ref (handle);
+       
+       /* We don't lock shared handles, but we need to be able to
+        * tell other threads to hold off.
+        *
+        * We do this by atomically putting the least-significant 32
+        * bits of time(2) into the 'checking' field if it is zero.
+        * If it isn't zero, then it means that either another thread
+        * is looking at this handle right now, or someone crashed
+        * here.  Assume that if the time value is more than 10
+        * seconds old, its a crash and override it.  10 seconds
+        * should be enough for anyone...
+        *
+        * If the time value is within 10 seconds, back off and try
+        * again as per the non-shared case.
+        */
+       do {
+               *now = (guint32)(time (NULL) & 0xFFFFFFFF);
+               
+               ret = _wapi_timestamp_exclusion 
(&WAPI_SHARED_HANDLE_METADATA(handle).checking, *now);
+               if (ret == EBUSY) {
+                       _wapi_handle_spin (100);
+               }
+       } while (ret == EBUSY);
+
+       return (ret);
+}
+
+static inline int _wapi_handle_shared_trylock_handle (gpointer handle, guint32 
now)
+{
+       int ret;
+       
+       g_assert (_WAPI_SHARED_HANDLE (_wapi_handle_type (handle)));
+       
+       _wapi_handle_ref (handle);
+       
+       ret = _wapi_timestamp_exclusion 
(&WAPI_SHARED_HANDLE_METADATA(handle).checking, now);
+       if (ret == EBUSY) {
+               _wapi_handle_unref (handle);
+       }
+       
+       return (ret);
+}
+
+static inline int _wapi_handle_shared_unlock_handle (gpointer handle, guint32 
now)
+{
+       g_assert (_WAPI_SHARED_HANDLE (_wapi_handle_type (handle)));
+       
+       _wapi_timestamp_release (&WAPI_SHARED_HANDLE_METADATA(handle).checking, 
now);
+       _wapi_handle_unref (handle);
+
+       return (0);
+}
+
 static inline void _wapi_handle_share_release (struct _WapiFileShare *info)
 {
        guint32 now;

Modified: trunk/mono/mono/io-layer/handles.c
===================================================================
--- trunk/mono/mono/io-layer/handles.c  2005-04-19 15:53:09 UTC (rev 43266)
+++ trunk/mono/mono/io-layer/handles.c  2005-04-19 16:02:40 UTC (rev 43267)
@@ -136,6 +136,7 @@
 {
        meta->timestamp = (guint32)(time (NULL) & 0xFFFFFFFF);
        meta->signalled = FALSE;
+       meta->checking = 0;
 }
 
 static void _wapi_handle_init_shared (struct _WapiHandleShared *handle,
@@ -395,7 +396,7 @@
 {
        guint32 handle_idx = 0;
        gpointer handle;
-       int thr_ret;
+       int thr_ret, i, k;
        
        mono_once (&shared_init_once, shared_init);
        
@@ -407,12 +408,29 @@
        g_assert(!_WAPI_FD_HANDLE(type));
        g_assert(_WAPI_SHARED_HANDLE(type));
        g_assert(offset != 0);
-       
+               
+       for (i = SLOT_INDEX (0); _wapi_private_handles [i] != NULL; i++) {
+               for (k = SLOT_OFFSET (0); k < _WAPI_HANDLE_INITIAL_COUNT; k++) {
+                       struct _WapiHandleUnshared *handle_data = 
&_wapi_private_handles [i][k];
+               
+                       if (handle_data->type == type &&
+                           handle_data->u.shared.offset == offset) {
+                               handle = GUINT_TO_POINTER (i * 
_WAPI_HANDLE_INITIAL_COUNT + k);
+                               _wapi_handle_ref (handle);
+
+#ifdef DEBUG
+                               g_message ("%s: Returning old handle %p 
referencing 0x%x", __func__, handle, offset);
+#endif
+                               return (handle);
+                       }
+               }
+       }
+
        pthread_cleanup_push ((void(*)(void *))mono_mutex_unlock_in_cleanup,
                              (void *)&scan_mutex);
        thr_ret = mono_mutex_lock (&scan_mutex);
        g_assert (thr_ret == 0);
-               
+       
        while ((handle_idx = _wapi_handle_new_internal (type, handle_specific)) 
== 0) {
                /* Try and expand the array, and have another go */
                int idx = SLOT_INDEX (_wapi_private_handle_count);
@@ -556,6 +574,11 @@
                struct _WapiHandleShared *shared_handle_data;
                struct _WapiHandleSharedMetadata *shared_meta;
                guint32 offset;
+                       
+               /* Unsafe, because we don't want the handle to vanish
+                * while we're checking it
+                */
+               _WAPI_HANDLE_COLLECTION_UNSAFE;
                
                do {
                        ref = &handle_data->u.shared;
@@ -567,6 +590,8 @@
 
                        *handle_specific = &shared_handle_data->u;
                } while (offset != shared_meta->offset);
+
+               _WAPI_HANDLE_COLLECTION_SAFE;
        } else {
                *handle_specific = &handle_data->u;
        }
@@ -757,10 +782,6 @@
        guint32 i, k;
        gboolean found = FALSE;
 
-       /* Unsafe, because we don't want the handle to vanish while
-        * we're checking it
-        */
-       _WAPI_HANDLE_COLLECTION_UNSAFE;
 
        for(i = SLOT_INDEX (0); !found && _wapi_private_handles [i] != NULL; 
i++) {
                for (k = SLOT_OFFSET (0); k < _WAPI_HANDLE_INITIAL_COUNT; k++) {
@@ -787,6 +808,11 @@
                        struct _WapiHandleSharedMetadata *shared_meta;
                        guint32 offset, now;
                        
+                       /* Unsafe, because we don't want the handle to
+                        * vanish while we're checking it
+                        */
+                       _WAPI_HANDLE_COLLECTION_UNSAFE;
+
                        do {
                                ref = &handle_data->u.shared;
                                shared_meta = 
&_wapi_shared_layout->metadata[ref->offset];
@@ -803,14 +829,14 @@
                         */
                        now = (guint32)(time (NULL) & 0xFFFFFFFF);
                        InterlockedExchange (&shared_meta->timestamp, now);
+
+                       _WAPI_HANDLE_COLLECTION_SAFE;
                } else {
                        *handle_specific = &handle_data->u;
                }
        }
 
 done:
-       _WAPI_HANDLE_COLLECTION_SAFE;
-       
        return(ret);
 }
 
@@ -909,8 +935,21 @@
 void _wapi_handle_ref (gpointer handle)
 {
        guint32 idx = GPOINTER_TO_UINT(handle);
+       guint32 now = (guint32)(time (NULL) & 0xFFFFFFFF);
+       struct _WapiHandleUnshared *handle_data = &_WAPI_PRIVATE_HANDLES(idx);
        
-       InterlockedIncrement (&_WAPI_PRIVATE_HANDLES(idx).ref);
+       InterlockedIncrement (&handle_data->ref);
+
+       /* It's possible for processes to exit before getting around
+        * to updating timestamps in the collection thread, so if a
+        * shared handle is reffed do the timestamp here as well just
+        * to make sure.
+        */
+       if (_WAPI_SHARED_HANDLE(handle_data->type)) {
+               struct _WapiHandleSharedMetadata *shared_meta = 
&_wapi_shared_layout->metadata[handle_data->u.shared.offset];
+               
+               InterlockedExchange (&shared_meta->timestamp, now);
+       }
        
 #ifdef DEBUG_REFS
        g_message ("%s: handle %p ref now %d", __func__, handle,
@@ -1083,7 +1122,8 @@
                                               gpointer *handles,
                                               gboolean waitall,
                                               guint32 *retcount,
-                                              guint32 *lowest)
+                                              guint32 *lowest,
+                                              guint32 *now)
 {
        guint32 count, i, iter=0;
        gboolean ret;
@@ -1095,34 +1135,17 @@
        for(i=0; i<numhandles; i++) {
                gpointer handle = handles[i];
                guint32 idx = GPOINTER_TO_UINT(handle);
-               guint32 now = (guint32)(time(NULL) & 0xFFFFFFFF);
 
 #ifdef DEBUG
                g_message ("%s: attempting to lock %p", __func__, handle);
 #endif
 
+               *now = (guint32)(time(NULL) & 0xFFFFFFFF);
                type = _WAPI_PRIVATE_HANDLES(idx).type;
 
                if (_WAPI_SHARED_HANDLE(type)) {
-                       /* We don't lock shared handles, but we need
-                        * to be able to simultaneously check the
-                        * signal state of all handles in the array
-                        *
-                        * We do this by atomically putting the
-                        * least-significant 32 bits of time(2) into
-                        * the 'checking' field if it is zero.  If it
-                        * isn't zero, then it means that either
-                        * another thread is looking at this handle
-                        * right now, or someone crashed here.  Assume
-                        * that if the time value is more than 10
-                        * seconds old, its a crash and override it.
-                        * 10 seconds should be enough for anyone...
-                        *
-                        * If the time value is within 10 seconds,
-                        * back off and try again as per the
-                        * non-shared case.
-                        */
-                       thr_ret = _wapi_timestamp_exclusion 
(&WAPI_SHARED_HANDLE_METADATA(handle).checking, now);
+                       thr_ret = _wapi_handle_shared_trylock_handle (handle,
+                                                                     *now);
                } else {
                        thr_ret = _wapi_handle_trylock_handle (handle);
                }
@@ -1140,11 +1163,11 @@
                                idx = GPOINTER_TO_UINT(handle);
 
                                if (_WAPI_SHARED_HANDLE(type)) {
-                                       /* Reset the checking field */
-                                       thr_ret = _wapi_timestamp_release 
(&WAPI_SHARED_HANDLE_METADATA(handle).checking, now);
-                               } else{
+                                       thr_ret = 
_wapi_handle_shared_unlock_handle (handle, *now);
+                               } else {
                                        thr_ret = _wapi_handle_unlock_handle 
(handle);
                                }
+                               
                                g_assert (thr_ret == 0);
                        }
 
@@ -1226,7 +1249,8 @@
        return(ret);
 }
 
-void _wapi_handle_unlock_handles (guint32 numhandles, gpointer *handles)
+void _wapi_handle_unlock_handles (guint32 numhandles, gpointer *handles,
+                                 guint32 now)
 {
        guint32 i;
        int thr_ret;
@@ -1241,13 +1265,12 @@
 #endif
 
                if (_WAPI_SHARED_HANDLE(type)) {
-                       WAPI_SHARED_HANDLE_METADATA(handle).checking = 0;
+                       thr_ret = _wapi_handle_shared_unlock_handle (handle,
+                                                                    now);
                } else {
-                       thr_ret = mono_mutex_unlock 
(&_WAPI_PRIVATE_HANDLES(idx).signal_mutex);
-                       g_assert (thr_ret == 0);
+                       thr_ret = _wapi_handle_unlock_handle (handle);
                }
-
-               _wapi_handle_unref (handle);
+               g_assert (thr_ret == 0);
        }
 }
 

Modified: trunk/mono/mono/io-layer/mutexes.c
===================================================================
--- trunk/mono/mono/io-layer/mutexes.c  2005-04-19 15:53:09 UTC (rev 43266)
+++ trunk/mono/mono/io-layer/mutexes.c  2005-04-19 16:02:40 UTC (rev 43267)
@@ -138,8 +138,8 @@
 
        _wapi_handle_set_signal_state (handle, FALSE, FALSE);
        
-       mutex_handle->pid=getpid ();
-       mutex_handle->tid=pthread_self ();
+       mutex_handle->pid = getpid ();
+       mutex_handle->tid = pthread_self ();
        mutex_handle->recursion++;
 
 #ifdef DEBUG
@@ -168,9 +168,9 @@
        g_message("%s: testing ownership mutex handle %p", __func__, handle);
 #endif
 
-       if(mutex_handle->recursion>0 &&
-          mutex_handle->pid==getpid () &&
-          mutex_handle->tid==pthread_self ()) {
+       if (mutex_handle->recursion > 0 &&
+           mutex_handle->pid == getpid () &&
+           mutex_handle->tid == pthread_self ()) {
 #ifdef DEBUG
                g_message ("%s: mutex handle %p owned by %d:%ld", __func__,
                           handle, getpid (), pthread_self ());
@@ -203,7 +203,7 @@
        gboolean ok;
        
 #ifdef DEBUG
-       g_message("%s: owning named mutex handle %p", __func__, handle);
+       g_message ("%s: owning named mutex handle %p", __func__, handle);
 #endif
        
        ok = _wapi_copy_handle (handle, WAPI_HANDLE_NAMEDMUTEX,
@@ -219,27 +219,16 @@
        namedmutex_handle->tid = pthread_self ();
        namedmutex_handle->recursion++;
 
-       /* If try_replace returns FALSE, it means someone else updated
-        * this handle, so we failed to own it
-        */
-       ok = _wapi_try_replace_handle (handle, WAPI_HANDLE_NAMEDMUTEX,
-                                      &shared_handle);
-       if (ok) {
-               _wapi_shared_handle_set_signal_state (handle, FALSE);
+       _wapi_replace_handle (handle, WAPI_HANDLE_NAMEDMUTEX, &shared_handle);
+       _wapi_shared_handle_set_signal_state (handle, FALSE);
 
 #ifdef DEBUG
-               g_message ("%s: mutex handle %p locked %d times by %d:%ld",
-                          __func__, handle, namedmutex_handle->recursion,
-                          namedmutex_handle->pid, namedmutex_handle->tid);
+       g_message ("%s: mutex handle %p locked %d times by %d:%ld", __func__,
+                  handle, namedmutex_handle->recursion,
+                  namedmutex_handle->pid, namedmutex_handle->tid);
 #endif
-       } else {
-#ifdef DEBUG
-               g_message ("%s: failed to own mutex handle %p", __func__,
-                          handle);
-#endif
-       }
        
-       return(ok);
+       return(TRUE);
 }
 
 static gboolean namedmutex_is_owned (gpointer handle)
@@ -330,6 +319,7 @@
        gboolean ok;
        struct mutex_check_data *data = (struct mutex_check_data *)user_data;
        int thr_ret;
+       guint32 now;
        
        ok = _wapi_lookup_handle (handle, WAPI_HANDLE_NAMEDMUTEX,
                                  (gpointer *)&mutex_handle);
@@ -339,9 +329,7 @@
                return(FALSE);
        }
 
-       pthread_cleanup_push ((void(*)(void *))_wapi_handle_unlock_handle,
-                             handle);
-       thr_ret = _wapi_handle_lock_handle (handle);
+       thr_ret = _wapi_handle_shared_lock_handle (handle, &now);
        g_assert (thr_ret == 0);
        
        if (mutex_handle->pid == data->pid &&
@@ -357,9 +345,7 @@
                _wapi_shared_handle_set_signal_state (handle, TRUE);
        }
 
-       thr_ret = _wapi_handle_unlock_handle (handle);
-       g_assert (thr_ret == 0);
-       pthread_cleanup_pop (0);
+       _wapi_handle_shared_unlock_handle (handle, now);
        
        /* Return false to keep searching */
        return(FALSE);
@@ -432,10 +418,10 @@
        gchar *utf8_name;
        int thr_ret;
        gpointer ret = NULL;
-       guint32 now = (guint32)(time(NULL) & 0xFFFFFFFF);
+       guint32 now = (guint32)(time(NULL) & 0xFFFFFFFF), locknow;
        guint32 namelen;
        gint32 offset;
-       
+
        /* w32 seems to guarantee that opening named mutexes can't
         * race each other
         */
@@ -503,8 +489,7 @@
                /* Set the initial state, as this is a completely new
                 * handle
                 */
-               pthread_cleanup_push ((void(*)(void 
*))_wapi_handle_unlock_handle, handle);
-               thr_ret = _wapi_handle_lock_handle (handle);
+               thr_ret = _wapi_handle_shared_lock_handle (handle, &locknow);
                g_assert (thr_ret == 0);
        
                if (owned == TRUE) {
@@ -513,9 +498,7 @@
                        _wapi_shared_handle_set_signal_state (handle, TRUE);
                }
 
-               thr_ret = _wapi_handle_unlock_handle (handle);
-               g_assert (thr_ret == 0);
-               pthread_cleanup_pop (0);
+               _wapi_handle_shared_unlock_handle (handle, locknow);
        }
        
 #ifdef DEBUG
@@ -625,6 +608,7 @@
        pid_t pid=getpid ();
        int thr_ret;
        gboolean ret = FALSE;
+       guint32 now;
        
        ok=_wapi_lookup_handle (handle, WAPI_HANDLE_NAMEDMUTEX,
                                (gpointer *)&mutex_handle);
@@ -634,9 +618,7 @@
                return(FALSE);
        }
 
-       pthread_cleanup_push ((void(*)(void *))_wapi_handle_unlock_handle,
-                             handle);
-       thr_ret = _wapi_handle_lock_handle (handle);
+       thr_ret = _wapi_handle_shared_lock_handle (handle, &now);
        g_assert (thr_ret == 0);
        
 #ifdef DEBUG
@@ -666,9 +648,7 @@
        }
 
 cleanup:
-       thr_ret = _wapi_handle_unlock_handle (handle);
-       g_assert (thr_ret == 0);
-       pthread_cleanup_pop (0);
+       _wapi_handle_shared_unlock_handle (handle, now);
        
        return(ret);
 }

Modified: trunk/mono/mono/io-layer/wait.c
===================================================================
--- trunk/mono/mono/io-layer/wait.c     2005-04-19 15:53:09 UTC (rev 43266)
+++ trunk/mono/mono/io-layer/wait.c     2005-04-19 16:02:40 UTC (rev 43267)
@@ -22,6 +22,52 @@
 
 #undef DEBUG
 
+static gboolean own_if_signalled(gpointer handle)
+{
+       gboolean ret = FALSE;
+       guint32 now = (guint32)(time (NULL) & 0xFFFFFFFF);
+       
+       if (_WAPI_SHARED_HANDLE (_wapi_handle_type (handle))) {
+               if (_wapi_handle_shared_trylock_handle (handle, now) == EBUSY) {
+                       return (FALSE);
+               }
+       }
+       
+       if (_wapi_handle_issignalled (handle)) {
+               _wapi_handle_ops_own (handle);
+               ret = TRUE;
+       }
+
+       if (_WAPI_SHARED_HANDLE (_wapi_handle_type (handle))) {
+               _wapi_handle_shared_unlock_handle (handle, now);
+       }
+
+       return(ret);
+}
+
+static gboolean own_if_owned(gpointer handle)
+{
+       gboolean ret = FALSE;
+       guint32 now = (guint32)(time (NULL) & 0xFFFFFFFF);
+       
+       if (_WAPI_SHARED_HANDLE (_wapi_handle_type (handle))) {
+               if (_wapi_handle_shared_trylock_handle (handle, now) == EBUSY) {
+                       return (FALSE);
+               }
+       }
+       
+       if (_wapi_handle_ops_isowned (handle)) {
+               _wapi_handle_ops_own (handle);
+               ret = TRUE;
+       }
+
+       if (_WAPI_SHARED_HANDLE (_wapi_handle_type (handle))) {
+               _wapi_handle_shared_unlock_handle (handle, now);
+       }
+
+       return(ret);
+}
+
 /**
  * WaitForSingleObjectEx:
  * @handle: an object to wait for
@@ -80,12 +126,11 @@
 
        if (_wapi_handle_test_capabilities (handle,
                                            WAPI_HANDLE_CAP_OWN) == TRUE) {
-               if (_wapi_handle_ops_isowned (handle)==TRUE) {
+               if (own_if_owned (handle) == TRUE) {
 #ifdef DEBUG
                        g_message ("%s: handle %p already owned", __func__,
                                   handle);
 #endif
-                       _wapi_handle_ops_own (handle);
                        ret = WAIT_OBJECT_0;
                        goto done;
                }
@@ -97,13 +142,12 @@
                goto done;
        }
        
-       if (_wapi_handle_issignalled (handle)) {
+       if (own_if_signalled (handle) == TRUE) {
 #ifdef DEBUG
                g_message ("%s: handle %p already signalled", __func__,
                           handle);
 #endif
 
-               _wapi_handle_ops_own (handle);
                ret=WAIT_OBJECT_0;
                goto done;
        }
@@ -116,13 +160,12 @@
        do {
                /* Check before waiting on the condition, just in case
                 */
-               if (_wapi_handle_issignalled (handle)) {
+               if (own_if_signalled (handle)) {
 #ifdef DEBUG
                        g_message ("%s: handle %p signalled", __func__,
                                   handle);
 #endif
 
-                       _wapi_handle_ops_own (handle);
                        ret = WAIT_OBJECT_0;
                        goto done;
                }
@@ -141,20 +184,14 @@
                         * handle is signalled now.  (It might not be
                         * if someone else got in before us.)
                         */
-                       if(_wapi_handle_issignalled (handle)) {
+                       if (own_if_signalled (handle)) {
 #ifdef DEBUG
                                g_message ("%s: handle %p signalled", __func__,
                                           handle);
 #endif
 
-                               /* This might fail if a shared handle
-                                * was grabbed before we got it (we
-                                * can't lock those.)
-                                */
-                               if (_wapi_handle_ops_own (handle) == TRUE) {
-                                       ret=WAIT_OBJECT_0;
-                                       goto done;
-                               }
+                               ret=WAIT_OBJECT_0;
+                               goto done;
                        }
                
                        /* Better luck next time */
@@ -266,12 +303,11 @@
        _wapi_handle_ops_signal (signal_handle);
 
        if (_wapi_handle_test_capabilities (wait, WAPI_HANDLE_CAP_OWN)==TRUE) {
-               if (_wapi_handle_ops_isowned (wait)==TRUE) {
+               if (own_if_owned (wait)) {
 #ifdef DEBUG
                        g_message ("%s: handle %p already owned", __func__,
                                   wait);
 #endif
-                       _wapi_handle_ops_own (wait);
                        ret = WAIT_OBJECT_0;
                        goto done;
                }
@@ -283,12 +319,11 @@
                goto done;
        }
        
-       if (_wapi_handle_issignalled (wait)) {
+       if (own_if_signalled (wait)) {
 #ifdef DEBUG
                g_message ("%s: handle %p already signalled", __func__, wait);
 #endif
 
-               _wapi_handle_ops_own (wait);
                ret = WAIT_OBJECT_0;
                goto done;
        }
@@ -301,12 +336,11 @@
        do {
                /* Check before waiting on the condition, just in case
                 */
-               if (_wapi_handle_issignalled (wait)) {
+               if (own_if_signalled (wait)) {
 #ifdef DEBUG
                        g_message ("%s: handle %p signalled", __func__, wait);
 #endif
 
-                       _wapi_handle_ops_own (wait);
                        ret = WAIT_OBJECT_0;
                        goto done;
                }
@@ -326,20 +360,14 @@
                         * handle is signalled now.  (It might not be
                         * if someone else got in before us.)
                         */
-                       if(_wapi_handle_issignalled (wait)) {
+                       if (own_if_signalled (wait)) {
 #ifdef DEBUG
                                g_message ("%s: handle %p signalled", __func__,
                                           wait);
 #endif
 
-                               /* This might fail if a shared handle
-                                * was grabbed before we got it (we
-                                * can't lock those.)
-                                */
-                               if (_wapi_handle_ops_own (wait) == TRUE) {
-                                       ret = WAIT_OBJECT_0;
-                                       goto done;
-                               }
+                               ret = WAIT_OBJECT_0;
+                               goto done;
                        }
                
                        /* Better luck next time */
@@ -376,13 +404,15 @@
 {
        guint32 numobjects;
        gpointer *handles;
+       guint32 now;
 };
 
 static void handle_cleanup (void *data)
 {
        struct handle_cleanup_data *handles = (struct handle_cleanup_data 
*)data;
 
-       _wapi_handle_unlock_handles (handles->numobjects, handles->handles);
+       _wapi_handle_unlock_handles (handles->numobjects, handles->handles,
+                                    handles->now);
 }
 
 static gboolean test_and_own (guint32 numobjects, gpointer *handles,
@@ -401,18 +431,15 @@
        
        pthread_cleanup_push (handle_cleanup, (void *)&cleanup_data);
        done = _wapi_handle_count_signalled_handles (numobjects, handles,
-                                                    waitall, count, lowest);
+                                                    waitall, count, lowest,
+                                                    &cleanup_data.now);
        if (done == TRUE) {
                if (waitall == TRUE) {
                        for (i = 0; i < numobjects; i++) {
-                               if (_wapi_handle_issignalled (handles[i])) {
-                                       _wapi_handle_ops_own (handles[i]);
-                               }
+                               own_if_signalled (handles[i]);
                        }
                } else {
-                       if (_wapi_handle_issignalled (handles[*lowest])) {
-                               _wapi_handle_ops_own (handles[*lowest]);
-                       }
+                       own_if_signalled (handles[*lowest]);
                }
        }
        

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to