Author: gonzalo
Date: 2005-04-16 16:27:03 -0400 (Sat, 16 Apr 2005)
New Revision: 43128

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/processes.c
Log:
2005-04-16 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>

        * handles.c:
        * processes.c:
        * handles-private.h: we were calling g_renew to expand the handle array,
        but that might move the memory and we might have pthread conditions or
        mutexes in the original memory area that are being used. Now instead of
        expanding an existing array, we just create new ones and keep a list of
        them. Access to _wapi_private_handles had to be modified accordingly.



Modified: trunk/mono/mono/io-layer/ChangeLog
===================================================================
--- trunk/mono/mono/io-layer/ChangeLog  2005-04-16 19:47:14 UTC (rev 43127)
+++ trunk/mono/mono/io-layer/ChangeLog  2005-04-16 20:27:03 UTC (rev 43128)
@@ -1,3 +1,13 @@
+2005-04-16 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
+       * handles.c:
+       * processes.c:
+       * handles-private.h: we were calling g_renew to expand the handle array,
+       but that might move the memory and we might have pthread conditions or
+       mutexes in the original memory area that are being used. Now instead of
+       expanding an existing array, we just create new ones and keep a list of
+       them. Access to _wapi_private_handles had to be modified accordingly.
+
 2005-04-15  Dick Porter  <[EMAIL PROTECTED]>
 
        * collection.c: FreeBSD needs more than PTHREAD_STACK_MIN

Modified: trunk/mono/mono/io-layer/handles-private.h
===================================================================
--- trunk/mono/mono/io-layer/handles-private.h  2005-04-16 19:47:14 UTC (rev 
43127)
+++ trunk/mono/mono/io-layer/handles-private.h  2005-04-16 20:27:03 UTC (rev 
43128)
@@ -20,9 +20,10 @@
 #include <mono/io-layer/misc-private.h>
 #include <mono/io-layer/collection.h>
 
+#define _WAPI_PRIVATE_HANDLES(x) (_wapi_private_handles [x / 
_WAPI_HANDLE_INITIAL_COUNT][x % _WAPI_HANDLE_INITIAL_COUNT])
 #undef DEBUG
 
-extern struct _WapiHandleUnshared *_wapi_private_handles;
+extern struct _WapiHandleUnshared *_wapi_private_handles [];
 extern struct _WapiHandleSharedLayout *_wapi_shared_layout;
 extern struct _WapiFileShareLayout *_wapi_fileshare_layout;
 
@@ -94,20 +95,20 @@
 /* This is OK to use for atomic writes of individual struct members, as they
  * are independent
  */
-#define WAPI_SHARED_HANDLE_METADATA(handle) 
_wapi_shared_layout->metadata[_wapi_private_handles[GPOINTER_TO_UINT((handle))].u.shared.offset]
+#define WAPI_SHARED_HANDLE_METADATA(handle) 
_wapi_shared_layout->metadata[_WAPI_PRIVATE_HANDLES(GPOINTER_TO_UINT((handle))).u.shared.offset]
 
 /* Use this for read-only accesses to shared handle structs, so that
  * if a handle is updated we always look at the latest copy.  For
  * write access, use handle_copy/handle_replace so that all the
  * handle-type-specific data is updated atomically.
  */
-#define WAPI_SHARED_HANDLE_TYPED_DATA(handle, type) 
_wapi_shared_layout->handles[_wapi_shared_layout->metadata[_wapi_private_handles[GPOINTER_TO_UINT((handle))].u.shared.offset].offset].u.type
+#define WAPI_SHARED_HANDLE_TYPED_DATA(handle, type) 
_wapi_shared_layout->handles[_wapi_shared_layout->metadata[_WAPI_PRIVATE_HANDLES(GPOINTER_TO_UINT((handle))).u.shared.offset].offset].u.type
 
 static inline WapiHandleType _wapi_handle_type (gpointer handle)
 {
        guint32 idx = GPOINTER_TO_UINT(handle);
        
-       return(_wapi_private_handles[idx].type);
+       return(_WAPI_PRIVATE_HANDLES(idx).type);
 }
 
 static inline void _wapi_handle_set_signal_state (gpointer handle,
@@ -120,7 +121,7 @@
 
        g_assert (!_WAPI_SHARED_HANDLE(_wapi_handle_type (handle)));
        
-       handle_data = &_wapi_private_handles[idx];
+       handle_data = &_WAPI_PRIVATE_HANDLES(idx);
        
 #ifdef DEBUG
        g_message ("%s: setting state of %p to %s (broadcast %s)", __func__,
@@ -171,7 +172,7 @@
        
        g_assert (_WAPI_SHARED_HANDLE(_wapi_handle_type (handle)));
        
-       handle_data = &_wapi_private_handles[idx];
+       handle_data = &_WAPI_PRIVATE_HANDLES(idx);
        
        ref = &handle_data->u.shared;
        shared_meta = &_wapi_shared_layout->metadata[ref->offset];
@@ -192,7 +193,7 @@
        if (_WAPI_SHARED_HANDLE(_wapi_handle_type (handle))) {
                return(WAPI_SHARED_HANDLE_METADATA(handle).signalled);
        } else {
-               return(_wapi_private_handles[idx].signalled);
+               return(_WAPI_PRIVATE_HANDLES(idx).signalled);
        }
 }
 
@@ -229,7 +230,7 @@
                return(0);
        }
        
-       return(mono_mutex_lock (&_wapi_private_handles[idx].signal_mutex));
+       return(mono_mutex_lock (&_WAPI_PRIVATE_HANDLES(idx).signal_mutex));
 }
 
 static inline int _wapi_handle_trylock_handle (gpointer handle)
@@ -246,7 +247,7 @@
                return(0);
        }
 
-       return(mono_mutex_trylock (&_wapi_private_handles[idx].signal_mutex));
+       return(mono_mutex_trylock (&_WAPI_PRIVATE_HANDLES(idx).signal_mutex));
 }
 
 static inline int _wapi_handle_unlock_handle (gpointer handle)
@@ -263,7 +264,7 @@
                return(0);
        }
        
-       ret = mono_mutex_unlock (&_wapi_private_handles[idx].signal_mutex);
+       ret = mono_mutex_unlock (&_WAPI_PRIVATE_HANDLES(idx).signal_mutex);
 
        _wapi_handle_unref (handle);
        

Modified: trunk/mono/mono/io-layer/handles.c
===================================================================
--- trunk/mono/mono/io-layer/handles.c  2005-04-16 19:47:14 UTC (rev 43127)
+++ trunk/mono/mono/io-layer/handles.c  2005-04-16 20:27:03 UTC (rev 43128)
@@ -82,7 +82,15 @@
        "Error!!"
 };
 
-struct _WapiHandleUnshared *_wapi_private_handles = NULL;
+/*
+ * We can hold _WAPI_PRIVATE_MAX_SLOTS * _WAPI_HANDLE_INITIAL_COUNT handles.
+ * If 4M handles are not enough... Oh, well... we will crash.
+ */
+#define _WAPI_PRIVATE_MAX_SLOTS                1024
+#define SLOT_INDEX(x)  (x / _WAPI_HANDLE_INITIAL_COUNT)
+#define SLOT_OFFSET(x) (x % _WAPI_HANDLE_INITIAL_COUNT)
+
+struct _WapiHandleUnshared *_wapi_private_handles [_WAPI_PRIVATE_MAX_SLOTS];
 static guint32 _wapi_private_handle_count = 0;
 
 struct _WapiHandleSharedLayout *_wapi_shared_layout = NULL;
@@ -99,19 +107,17 @@
 static void shared_init (void)
 {
        int thr_ret;
+       int idx = 0;
        
        _wapi_fd_reserve = getdtablesize();
 
-       _wapi_private_handle_count = _WAPI_HANDLE_INITIAL_COUNT;
-       
-       while(_wapi_fd_reserve > _wapi_private_handle_count) {
+       do {
+               _wapi_private_handles [idx++] = g_new0 (struct 
_WapiHandleUnshared,
+                                                       
_WAPI_HANDLE_INITIAL_COUNT);
+
                _wapi_private_handle_count += _WAPI_HANDLE_INITIAL_COUNT;
-       }
+       } while(_wapi_fd_reserve > _wapi_private_handle_count);
        
-       _wapi_private_handles = g_new0 (struct _WapiHandleUnshared,
-                                       _wapi_private_handle_count);
-
-
        _wapi_shared_layout = _wapi_shm_attach ();
        g_assert (_wapi_shared_layout != NULL);
        
@@ -268,8 +274,9 @@
 static guint32 _wapi_handle_new_internal (WapiHandleType type,
                                          gpointer handle_specific)
 {
-       guint32 i;
+       guint32 i, k, count;
        static guint32 last = 0;
+       gboolean retry = FALSE;
        
        /* A linear scan should be fast enough.  Start from the last
         * allocation, assuming that handles are allocated more often
@@ -279,21 +286,27 @@
        
        if (last < _wapi_fd_reserve) {
                last = _wapi_fd_reserve;
+       } else {
+               retry = TRUE;
        }
-       
+
 again:
-       for(i = last; i <_wapi_private_handle_count; i++) {
-               struct _WapiHandleUnshared *handle = &_wapi_private_handles[i];
-               
-               if(handle->type == WAPI_HANDLE_UNUSED) {
-                       last = i + 1;
+       count = last;
+       for(i = SLOT_INDEX (count); _wapi_private_handles [i] != NULL; i++) {
+               for (k = SLOT_OFFSET (count); k < _WAPI_HANDLE_INITIAL_COUNT; 
k++) {
+                       struct _WapiHandleUnshared *handle = 
&_wapi_private_handles [i][k];
+
+                       if(handle->type == WAPI_HANDLE_UNUSED) {
+                               last = count + 1;
                        
-                       _wapi_handle_init (handle, type, handle_specific);
-                       return(i);
+                               _wapi_handle_init (handle, type, 
handle_specific);
+                               return (count);
+                       }
+                       count++;
                }
        }
 
-       if(last > _wapi_fd_reserve) {
+       if(retry && last > _wapi_fd_reserve) {
                /* Try again from the beginning */
                last = _wapi_fd_reserve;
                goto again;
@@ -326,16 +339,10 @@
                
        while ((handle_idx = _wapi_handle_new_internal (type, handle_specific)) 
== 0) {
                /* Try and expand the array, and have another go */
-               _wapi_private_handles = g_renew (struct _WapiHandleUnshared,
-                                                _wapi_private_handles,
-                                                _wapi_private_handle_count +
-                                                _WAPI_HANDLE_INITIAL_COUNT);
-               memset (_wapi_private_handles +
-                       (_wapi_private_handle_count *
-                        sizeof(struct _WapiHandleUnshared)), '\0',
-                       (_WAPI_HANDLE_INITIAL_COUNT *
-                        sizeof(struct _WapiHandleUnshared)));
-               
+               int idx = SLOT_INDEX (_wapi_private_handle_count);
+               _wapi_private_handles [idx] = g_new0 (struct 
_WapiHandleUnshared,
+                                               _WAPI_HANDLE_INITIAL_COUNT);
+
                _wapi_private_handle_count += _WAPI_HANDLE_INITIAL_COUNT;
        }
                
@@ -373,7 +380,7 @@
                        g_assert (ref != 0);
                }
                
-               _wapi_private_handles[handle_idx].u.shared.offset = ref;
+               _WAPI_PRIVATE_HANDLES(handle_idx).u.shared.offset = ref;
 #ifdef DEBUG
                g_message ("%s: New shared handle at offset 0x%x", __func__,
                           ref);
@@ -409,16 +416,10 @@
                
        while ((handle_idx = _wapi_handle_new_internal (type, handle_specific)) 
== 0) {
                /* Try and expand the array, and have another go */
-               _wapi_private_handles = g_renew (struct _WapiHandleUnshared,
-                                                _wapi_private_handles,
-                                                _wapi_private_handle_count +
-                                                _WAPI_HANDLE_INITIAL_COUNT);
-               memset (_wapi_private_handles +
-                       (_wapi_private_handle_count *
-                        sizeof(struct _WapiHandleUnshared)), '\0',
-                       (_WAPI_HANDLE_INITIAL_COUNT *
-                        sizeof(struct _WapiHandleUnshared)));
-               
+               int idx = SLOT_INDEX (_wapi_private_handle_count);
+               _wapi_private_handles [idx] = g_new0 (struct 
_WapiHandleUnshared,
+                                               _WAPI_HANDLE_INITIAL_COUNT);
+
                _wapi_private_handle_count += _WAPI_HANDLE_INITIAL_COUNT;
        }
                
@@ -431,7 +432,7 @@
        
        handle = GUINT_TO_POINTER (handle_idx);
                
-       _wapi_private_handles[handle_idx].u.shared.offset = offset;
+       _WAPI_PRIVATE_HANDLES(handle_idx).u.shared.offset = offset;
 
 #ifdef DEBUG
        g_message ("%s: Allocated new handle %p referencing 0x%x", __func__,
@@ -464,7 +465,7 @@
                return(GUINT_TO_POINTER (_WAPI_HANDLE_INVALID));
        }
 
-       handle = &_wapi_private_handles[fd];
+       handle = &_WAPI_PRIVATE_HANDLES(fd);
        
        if (handle->type != WAPI_HANDLE_UNUSED) {
 #ifdef DEBUG
@@ -508,17 +509,10 @@
        
        while ((handle_idx = _wapi_handle_new_internal (type, NULL)) == 0) {
                /* Try and expand the array, and have another go */
-               _wapi_private_handles = g_renew (struct _WapiHandleUnshared,
-                                                _wapi_private_handles,
-                                                _wapi_private_handle_count +
-                                                _WAPI_HANDLE_INITIAL_COUNT);
-                       
-               memset (_wapi_private_handles +
-                       (_wapi_private_handle_count *
-                        sizeof(struct _WapiHandleUnshared)), '\0',
-                       (_WAPI_HANDLE_INITIAL_COUNT *
-                        sizeof(struct _WapiHandleUnshared)));
-                       
+               int idx = SLOT_INDEX (_wapi_private_handle_count);
+               _wapi_private_handles [idx] = g_new0 (struct 
_WapiHandleUnshared,
+                                               _WAPI_HANDLE_INITIAL_COUNT);
+
                _wapi_private_handle_count += _WAPI_HANDLE_INITIAL_COUNT;
        }
 
@@ -529,7 +523,7 @@
        /* Make sure we left the space for fd mappings */
        g_assert (handle_idx >= _wapi_fd_reserve);
 
-       handle_data = &_wapi_private_handles[handle_idx];
+       handle_data = &_WAPI_PRIVATE_HANDLES(handle_idx);
        ref = &handle_data->u.shared;
        ref->offset = offset;
 
@@ -548,7 +542,7 @@
        struct _WapiHandleUnshared *handle_data;
        guint32 handle_idx = GPOINTER_TO_UINT(handle);
 
-       handle_data = &_wapi_private_handles[handle_idx];
+       handle_data = &_WAPI_PRIVATE_HANDLES(handle_idx);
        
        if (handle_data->type != type) {
                return(FALSE);
@@ -598,7 +592,7 @@
                   _wapi_handle_typename[type]);
 #endif
 
-       handle_data = &_wapi_private_handles[handle_idx];
+       handle_data = &_WAPI_PRIVATE_HANDLES(handle_idx);
        
        if(handle_data->type != type) {
 #ifdef DEBUG
@@ -650,9 +644,9 @@
 #endif
 
        g_assert(_WAPI_SHARED_HANDLE(type));
-       g_assert(_wapi_private_handles[handle_idx].type == type);
+       g_assert(_WAPI_PRIVATE_HANDLES(handle_idx).type == type);
        
-       ref = _wapi_private_handles[handle_idx].u.shared.offset;
+       ref = _WAPI_PRIVATE_HANDLES(handle_idx).u.shared.offset;
        shared_meta = &_wapi_shared_layout->metadata[ref];
        
        do {
@@ -700,9 +694,9 @@
 #endif
 
        g_assert(_WAPI_SHARED_HANDLE(type));
-       g_assert(_wapi_private_handles[handle_idx].type == type);
+       g_assert(_WAPI_PRIVATE_HANDLES(handle_idx).type == type);
        
-       ref = _wapi_private_handles[handle_idx].u.shared.offset;
+       ref = _WAPI_PRIVATE_HANDLES(handle_idx).u.shared.offset;
        shared_meta = &_wapi_shared_layout->metadata[ref];
        
        old_off = shared_meta->offset;
@@ -761,25 +755,29 @@
 {
        struct _WapiHandleUnshared *handle_data = NULL;
        gpointer ret = NULL;
-       guint32 i;
+       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 = 0; i < _wapi_private_handle_count; i++) {
-               handle_data = &_wapi_private_handles[i];
+       for(i = SLOT_INDEX (0); !found && _wapi_private_handles [i] != NULL; 
i++) {
+               for (k = SLOT_OFFSET (0); k < _WAPI_HANDLE_INITIAL_COUNT; k++) {
+                       handle_data = &_wapi_private_handles [i][k];
                
-               if(handle_data->type == type) {
-                       ret = GUINT_TO_POINTER (i);
-                       if(check (ret, user_data) == TRUE) {
-                               break;
+                       if(handle_data->type == type) {
+                               ret = GUINT_TO_POINTER (i);
+                               if(check (ret, user_data) == TRUE) {
+                                       found = TRUE;
+                                       break;
+                               }
                        }
                }
        }
 
-       if(i == _wapi_private_handle_count) {
+       if (!found) {
                goto done;
        }
        
@@ -913,11 +911,11 @@
 {
        guint32 idx = GPOINTER_TO_UINT(handle);
        
-       InterlockedIncrement (&_wapi_private_handles[idx].ref);
+       InterlockedIncrement (&_WAPI_PRIVATE_HANDLES(idx).ref);
        
 #ifdef DEBUG_REFS
        g_message ("%s: handle %p ref now %d", __func__, handle,
-                  _wapi_private_handles[idx].ref);
+                  _WAPI_PRIVATE_HANDLES(idx).ref);
 #endif
 }
 
@@ -933,15 +931,15 @@
         * could lock a mutex, but I'm not sure that allowing a handle
         * reference to reach 0 isn't an application bug anyway.
         */
-       destroy = (InterlockedDecrement (&_wapi_private_handles[idx].ref) ==0);
+       destroy = (InterlockedDecrement (&_WAPI_PRIVATE_HANDLES(idx).ref) ==0);
        
 #ifdef DEBUG_REFS
        g_message ("%s: handle %p ref now %d (destroy %s)", __func__, handle,
-                  _wapi_private_handles[idx].ref, destroy?"TRUE":"FALSE");
+                  _WAPI_PRIVATE_HANDLES(idx).ref, destroy?"TRUE":"FALSE");
 #endif
        
        if(destroy==TRUE) {
-               WapiHandleType type = _wapi_private_handles[idx].type;
+               WapiHandleType type = _WAPI_PRIVATE_HANDLES(idx).type;
 
 #ifdef DEBUG
                g_message ("%s: Destroying handle %p", __func__, handle);
@@ -949,10 +947,10 @@
                
                _wapi_handle_ops_close (handle);
 
-               memset (&_wapi_private_handles[idx].u, '\0',
-                       sizeof(_wapi_private_handles[idx].u));
+               memset (&_WAPI_PRIVATE_HANDLES(idx).u, '\0',
+                       sizeof(_WAPI_PRIVATE_HANDLES(idx).u));
 
-               _wapi_private_handles[idx].type = WAPI_HANDLE_UNUSED;
+               _WAPI_PRIVATE_HANDLES(idx).type = WAPI_HANDLE_UNUSED;
                
                if (!_WAPI_SHARED_HANDLE(type)) {
                        /* Destroy the mutex and cond var.  We hope nobody
@@ -960,10 +958,10 @@
                         * now, but pthreads doesn't have a
                         * "unlock_and_destroy" atomic function.
                         */
-                       thr_ret = mono_mutex_destroy 
(&_wapi_private_handles[idx].signal_mutex);
+                       thr_ret = mono_mutex_destroy 
(&_WAPI_PRIVATE_HANDLES(idx).signal_mutex);
                        g_assert (thr_ret == 0);
                                
-                       thr_ret = pthread_cond_destroy 
(&_wapi_private_handles[idx].signal_cond);
+                       thr_ret = pthread_cond_destroy 
(&_WAPI_PRIVATE_HANDLES(idx).signal_cond);
                        g_assert (thr_ret == 0);
                }
 
@@ -985,7 +983,7 @@
        guint32 idx = GPOINTER_TO_UINT(handle);
        WapiHandleType type;
 
-       type = _wapi_private_handles[idx].type;
+       type = _WAPI_PRIVATE_HANDLES(idx).type;
 
 #ifdef DEBUG
        g_message ("%s: testing 0x%x against 0x%x (%d)", __func__,
@@ -1000,7 +998,7 @@
        guint32 idx = GPOINTER_TO_UINT(handle);
        WapiHandleType type;
 
-       type = _wapi_private_handles[idx].type;
+       type = _WAPI_PRIVATE_HANDLES(idx).type;
 
        if (handle_ops[type] != NULL &&
            handle_ops[type]->close != NULL) {
@@ -1013,7 +1011,7 @@
        guint32 idx = GPOINTER_TO_UINT(handle);
        WapiHandleType type;
 
-       type = _wapi_private_handles[idx].type;
+       type = _WAPI_PRIVATE_HANDLES(idx).type;
 
        if (handle_ops[type] != NULL && handle_ops[type]->signal != NULL) {
                handle_ops[type]->signal (handle);
@@ -1025,7 +1023,7 @@
        guint32 idx = GPOINTER_TO_UINT(handle);
        WapiHandleType type;
        
-       type = _wapi_private_handles[idx].type;
+       type = _WAPI_PRIVATE_HANDLES(idx).type;
 
        if (handle_ops[type] != NULL && handle_ops[type]->own_handle != NULL) {
                return(handle_ops[type]->own_handle (handle));
@@ -1039,7 +1037,7 @@
        guint32 idx = GPOINTER_TO_UINT(handle);
        WapiHandleType type;
 
-       type = _wapi_private_handles[idx].type;
+       type = _WAPI_PRIVATE_HANDLES(idx).type;
 
        if (handle_ops[type] != NULL && handle_ops[type]->is_owned != NULL) {
                return(handle_ops[type]->is_owned (handle));
@@ -1053,7 +1051,7 @@
        guint32 idx = GPOINTER_TO_UINT(handle);
        WapiHandleType type;
        
-       type = _wapi_private_handles[idx].type;
+       type = _WAPI_PRIVATE_HANDLES(idx).type;
        
        if (handle_ops[type] != NULL &&
            handle_ops[type]->special_wait != NULL) {
@@ -1104,7 +1102,7 @@
                g_message ("%s: attempting to lock %p", __func__, handle);
 #endif
 
-               type = _wapi_private_handles[idx].type;
+               type = _WAPI_PRIVATE_HANDLES(idx).type;
 
                if (_WAPI_SHARED_HANDLE(type)) {
                        /* We don't lock shared handles, but we need
@@ -1183,7 +1181,7 @@
                gpointer handle = handles[i];
                guint32 idx = GPOINTER_TO_UINT(handle);
                
-               type = _wapi_private_handles[idx].type;
+               type = _WAPI_PRIVATE_HANDLES(idx).type;
 
                _wapi_handle_ref (handle);
                
@@ -1196,7 +1194,7 @@
                   (_WAPI_SHARED_HANDLE(type) &&
                    WAPI_SHARED_HANDLE_METADATA(handle).signalled == TRUE) ||
                   (!_WAPI_SHARED_HANDLE(type) &&
-                   _wapi_private_handles[idx].signalled == TRUE)) {
+                   _WAPI_PRIVATE_HANDLES(idx).signalled == TRUE)) {
                        count++;
                        
 #ifdef DEBUG
@@ -1237,7 +1235,7 @@
        for(i=0; i<numhandles; i++) {
                gpointer handle = handles[i];
                guint32 idx = GPOINTER_TO_UINT(handle);
-               WapiHandleType type = _wapi_private_handles[idx].type;
+               WapiHandleType type = _WAPI_PRIVATE_HANDLES(idx).type;
                
 #ifdef DEBUG
                g_message ("%s: unlocking handle %p", __func__, handle);
@@ -1246,7 +1244,7 @@
                if (_WAPI_SHARED_HANDLE(type)) {
                        WAPI_SHARED_HANDLE_METADATA(handle).checking = 0;
                } else {
-                       thr_ret = mono_mutex_unlock 
(&_wapi_private_handles[idx].signal_mutex);
+                       thr_ret = mono_mutex_unlock 
(&_WAPI_PRIVATE_HANDLES(idx).signal_mutex);
                        g_assert (thr_ret == 0);
                }
 
@@ -1408,8 +1406,8 @@
                        _wapi_handle_spin (100);
                }
        } else {
-               return(mono_cond_wait (&_wapi_private_handles[idx].signal_cond,
-                                      
&_wapi_private_handles[idx].signal_mutex));
+               return(mono_cond_wait (&_WAPI_PRIVATE_HANDLES(idx).signal_cond,
+                                      
&_WAPI_PRIVATE_HANDLES(idx).signal_mutex));
        }
 }
 
@@ -1452,7 +1450,7 @@
                        }
                }
        } else {
-               return(mono_cond_timedwait 
(&_wapi_private_handles[idx].signal_cond, 
&_wapi_private_handles[idx].signal_mutex, timeout));
+               return(mono_cond_timedwait 
(&_WAPI_PRIVATE_HANDLES(idx).signal_cond, 
&_WAPI_PRIVATE_HANDLES(idx).signal_mutex, timeout));
        }
 }
 
@@ -1660,20 +1658,22 @@
 void _wapi_handle_dump (void)
 {
        struct _WapiHandleUnshared *handle_data;
-       guint32 i;
+       guint32 i, k;
 
-       for (i = 0; i < _wapi_private_handle_count; i++) {
-               handle_data = &_wapi_private_handles[i];
+       for(i = SLOT_INDEX (0); _wapi_private_handles [i] != NULL; i++) {
+               for (k = SLOT_OFFSET (0); k < _WAPI_HANDLE_INITIAL_COUNT; k++) {
+                       handle_data = &_wapi_private_handles [i][k];
 
-               if (handle_data->type == WAPI_HANDLE_UNUSED) {
-                       continue;
+                       if (handle_data->type == WAPI_HANDLE_UNUSED) {
+                               continue;
+                       }
+               
+                       g_print ("%3x [%7s] %s %d ", i,
+                                _wapi_handle_typename[handle_data->type],
+                                handle_data->signalled?"Sg":"Un", 
handle_data->ref);
+                       handle_details[handle_data->type](&handle_data->u);
+                       g_print ("\n");
                }
-               
-               g_print ("%3x [%7s] %s %d ", i,
-                        _wapi_handle_typename[handle_data->type],
-                        handle_data->signalled?"Sg":"Un", handle_data->ref);
-               handle_details[handle_data->type](&handle_data->u);
-               g_print ("\n");
        }
 }
 
@@ -1686,7 +1686,7 @@
 
 void _wapi_handle_update_refs (void)
 {
-       guint32 i, lock_now;
+       guint32 i, k, lock_now;
        int thr_ret;
        
        _WAPI_HANDLE_COLLECTION_UNSAFE;
@@ -1703,44 +1703,46 @@
        } while (thr_ret == EBUSY);
        g_assert(thr_ret == 0);
 
-       for (i = 0; i < _wapi_private_handle_count; i++) {
-               struct _WapiHandleUnshared *handle = &_wapi_private_handles[i];
-               guint32 now = (guint32)(time (NULL) & 0xFFFFFFFF);
+       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 = 
&_wapi_private_handles [i][k];
+                       guint32 now = (guint32)(time (NULL) & 0xFFFFFFFF);
 
-               if (_WAPI_SHARED_HANDLE(handle->type)) {
-                       struct _WapiHandleSharedMetadata *shared_meta;
-                       
+                       if (_WAPI_SHARED_HANDLE(handle->type)) {
+                               struct _WapiHandleSharedMetadata *shared_meta;
+                               
 #ifdef DEBUG
-                       g_message ("%s: (%d) handle 0x%x is SHARED", __func__,
-                                  getpid (), i);
+                               g_message ("%s: (%d) handle 0x%x is SHARED", 
__func__,
+                                          getpid (), i);
 #endif
 
-                       shared_meta = 
&_wapi_shared_layout->metadata[handle->u.shared.offset];
+                               shared_meta = 
&_wapi_shared_layout->metadata[handle->u.shared.offset];
 
 #ifdef DEBUG
-                       g_message ("%s: (%d) Updating timstamp of handle 0x%x",
-                                  __func__, getpid(),
-                                  handle->u.shared.offset);
+                               g_message ("%s: (%d) Updating timstamp of 
handle 0x%x",
+                                          __func__, getpid(),
+                                          handle->u.shared.offset);
 #endif
 
-                       InterlockedExchange (&shared_meta->timestamp, now);
-               } else if (handle->type == WAPI_HANDLE_FILE) {
-                       struct _WapiHandle_file *file_handle = &handle->u.file;
-                       
+                               InterlockedExchange (&shared_meta->timestamp, 
now);
+                       } else if (handle->type == WAPI_HANDLE_FILE) {
+                               struct _WapiHandle_file *file_handle = 
&handle->u.file;
+                               
 #ifdef DEBUG
-                       g_message ("%s: (%d) handle 0x%x is FILE", __func__,
-                                  getpid (), i);
+                               g_message ("%s: (%d) handle 0x%x is FILE", 
__func__,
+                                          getpid (), i);
 #endif
-                       
-                       g_assert (file_handle->share_info != NULL);
+                               
+                               g_assert (file_handle->share_info != NULL);
 
 #ifdef DEBUG
-                       g_message ("%s: (%d) Inc refs on fileshare 0x%x",
-                                  __func__, getpid(),
-                                  (file_handle->share_info - 
&_wapi_fileshare_layout->share_info[0]) / sizeof(struct _WapiFileShare));
+                               g_message ("%s: (%d) Inc refs on fileshare 
0x%x",
+                                          __func__, getpid(),
+                                          (file_handle->share_info - 
&_wapi_fileshare_layout->share_info[0]) / sizeof(struct _WapiFileShare));
 #endif
 
-                       InterlockedExchange 
(&file_handle->share_info->timestamp, now);
+                               InterlockedExchange 
(&file_handle->share_info->timestamp, now);
+                       }
                }
        }
        

Modified: trunk/mono/mono/io-layer/processes.c
===================================================================
--- trunk/mono/mono/io-layer/processes.c        2005-04-16 19:47:14 UTC (rev 
43127)
+++ trunk/mono/mono/io-layer/processes.c        2005-04-16 20:27:03 UTC (rev 
43128)
@@ -532,7 +532,7 @@
                struct _WapiHandleUnshared *handle_data;
                struct _WapiHandle_shared_ref *ref;
                
-               handle_data = &_wapi_private_handles[GPOINTER_TO_UINT(handle)];
+               handle_data = &_WAPI_PRIVATE_HANDLES(GPOINTER_TO_UINT(handle));
                ref = &handle_data->u.shared;
                
                env_strings[env_count] = g_strdup_printf 
("_WAPI_PROCESS_HANDLE_OFFSET=%d", ref->offset);

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

Reply via email to