Author: dick
Date: 2005-04-21 07:46:55 -0400 (Thu, 21 Apr 2005)
New Revision: 43396

Modified:
   trunk/mono/mono/io-layer/ChangeLog
   trunk/mono/mono/io-layer/collection.c
   trunk/mono/mono/io-layer/collection.h
   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/processes.c
   trunk/mono/mono/io-layer/threads.c
   trunk/mono/mono/io-layer/wait.c
   trunk/mono/mono/metadata/ChangeLog
   trunk/mono/mono/metadata/threads.c
Log:

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

        * mutexes.c: 
        * processes.c: 
        * threads.c: 
        * handles.c (_wapi_handle_new): Turn assertions into errors.

        * collection.c (_wapi_handle_collect): Use symbols not magic
        numbers for timeout values

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

        * threads.c (mono_thread_create): Turn an assertion into an
        * error.




Modified: trunk/mono/mono/io-layer/ChangeLog
===================================================================
--- trunk/mono/mono/io-layer/ChangeLog  2005-04-21 11:08:47 UTC (rev 43395)
+++ trunk/mono/mono/io-layer/ChangeLog  2005-04-21 11:46:55 UTC (rev 43396)
@@ -1,3 +1,13 @@
+2005-04-21  Dick Porter  <[EMAIL PROTECTED]>
+
+       * mutexes.c: 
+       * processes.c: 
+       * threads.c: 
+       * handles.c (_wapi_handle_new): Turn assertions into errors.
+
+       * collection.c (_wapi_handle_collect): Use symbols not magic
+       numbers for timeout values
+
 2005-04-19  Dick Porter  <[EMAIL PROTECTED]>
 
        * mutexes.c: 

Modified: trunk/mono/mono/io-layer/collection.c
===================================================================
--- trunk/mono/mono/io-layer/collection.c       2005-04-21 11:08:47 UTC (rev 
43395)
+++ trunk/mono/mono/io-layer/collection.c       2005-04-21 11:46:55 UTC (rev 
43396)
@@ -27,7 +27,7 @@
 {
        struct timespec sleepytime;
 
-       sleepytime.tv_sec = 10;
+       sleepytime.tv_sec = _WAPI_HANDLE_COLLECTION_UPDATE_INTERVAL;
        sleepytime.tv_nsec = 0;
 
        while (1) {
@@ -90,7 +90,7 @@
                for (i = 0; i < _WAPI_HANDLE_INITIAL_COUNT; i++) {
                        struct _WapiHandleShared *shared;
                        struct _WapiHandleSharedMetadata *meta;
-                       guint32 too_old = (guint32)(time(NULL) & 0xFFFFFFFF) - 
300; /* 5 minutes without update */
+                       guint32 too_old = (guint32)(time(NULL) & 0xFFFFFFFF) - 
_WAPI_HANDLE_COLLECTION_EXPIRED_INTERVAL;
                        
                        meta = &_wapi_shared_layout->metadata[i];
                        if (meta->timestamp < too_old && meta->offset != 0) {
@@ -116,7 +116,7 @@
 
                for (i = 0; i < _wapi_fileshare_layout->hwm; i++) {
                        struct _WapiFileShare *file_share = 
&_wapi_fileshare_layout->share_info[i];
-                       guint32 too_old = (guint32)(time(NULL) & 0xFFFFFFFF) - 
300; /* 5 minutes without update */
+                       guint32 too_old = (guint32)(time(NULL) & 0xFFFFFFFF) - 
_WAPI_HANDLE_COLLECTION_EXPIRED_INTERVAL;
                        
                        if (file_share->timestamp < too_old) {
                                memset (file_share, '\0',

Modified: trunk/mono/mono/io-layer/collection.h
===================================================================
--- trunk/mono/mono/io-layer/collection.h       2005-04-21 11:08:47 UTC (rev 
43395)
+++ trunk/mono/mono/io-layer/collection.h       2005-04-21 11:46:55 UTC (rev 
43396)
@@ -12,6 +12,9 @@
 
 #include <glib.h>
 
+#define _WAPI_HANDLE_COLLECTION_UPDATE_INTERVAL                10
+#define _WAPI_HANDLE_COLLECTION_EXPIRED_INTERVAL       300
+
 #define _WAPI_HANDLE_COLLECTION_UNSAFE                         \
        {                                                       \
                guint32 _wapi_save_start;                       \

Modified: trunk/mono/mono/io-layer/handles-private.h
===================================================================
--- trunk/mono/mono/io-layer/handles-private.h  2005-04-21 11:08:47 UTC (rev 
43395)
+++ trunk/mono/mono/io-layer/handles-private.h  2005-04-21 11:46:55 UTC (rev 
43396)
@@ -46,9 +46,8 @@
                                     gpointer *handle_specific);
 extern gboolean _wapi_copy_handle (gpointer handle, WapiHandleType type,
                                   struct _WapiHandleShared *handle_specific);
-extern void _wapi_replace_handle (gpointer handle, WapiHandleType type,
+extern gboolean _wapi_replace_handle (gpointer handle, WapiHandleType type,
                                  struct _WapiHandleShared *handle_specific);
-extern gboolean _wapi_try_replace_handle (gpointer handle, WapiHandleType 
type, struct _WapiHandleShared *handle_specific);
 extern gpointer _wapi_search_handle (WapiHandleType type,
                                     gboolean (*check)(gpointer, gpointer),
                                     gpointer user_data,

Modified: trunk/mono/mono/io-layer/handles.c
===================================================================
--- trunk/mono/mono/io-layer/handles.c  2005-04-21 11:08:47 UTC (rev 43395)
+++ trunk/mono/mono/io-layer/handles.c  2005-04-21 11:46:55 UTC (rev 43396)
@@ -369,7 +369,7 @@
                        offset = _wapi_handle_new_shared (type,
                                                          handle_specific);
                        /* FIXME: grow the arrays */
-                       g_assert (offset != 0);
+                       return (_WAPI_HANDLE_INVALID);
                }
                
                ref = _wapi_handle_new_shared_offset (offset);
@@ -377,7 +377,7 @@
                        _wapi_handle_collect ();
                        ref = _wapi_handle_new_shared_offset (offset);
                        /* FIXME: grow the arrays */
-                       g_assert (ref != 0);
+                       return (_WAPI_HANDLE_INVALID);
                }
                
                _WAPI_PRIVATE_HANDLES(handle_idx).u.shared.offset = ref;
@@ -654,8 +654,8 @@
        return(TRUE);
 }
 
-void _wapi_replace_handle (gpointer handle, WapiHandleType type,
-                          struct _WapiHandleShared *handle_specific)
+gboolean _wapi_replace_handle (gpointer handle, WapiHandleType type,
+                              struct _WapiHandleShared *handle_specific)
 {
        struct _WapiHandleShared *shared_handle_data;
        struct _WapiHandleSharedMetadata *shared_meta;
@@ -681,7 +681,7 @@
                        new_off = _wapi_handle_new_shared (type, 
                                                           handle_specific);
                        /* FIXME: grow the arrays */
-                       g_assert (new_off != 0);
+                       return (FALSE);
                }
                
                shared_handle_data = &_wapi_shared_layout->handles[new_off];
@@ -701,71 +701,8 @@
        g_message ("%s: handle at 0x%x is now found at 0x%x", __func__, ref,
                   new_off);
 #endif
-}
 
-gboolean _wapi_try_replace_handle (gpointer handle, WapiHandleType type,
-                                  struct _WapiHandleShared *handle_specific)
-{
-       struct _WapiHandleShared *shared_handle_data;
-       struct _WapiHandleSharedMetadata *shared_meta;
-       guint32 handle_idx = GPOINTER_TO_UINT(handle);
-       guint32 old_off, new_off, ref;
-       gboolean ret;
-       
-#ifdef DEBUG
-       g_message ("%s: Trying to replace handle %p of type %s", __func__,
-                  handle, _wapi_handle_typename[type]);
-#endif
-
-       g_assert(_WAPI_SHARED_HANDLE(type));
-       g_assert(_WAPI_PRIVATE_HANDLES(handle_idx).type == type);
-       
-       ref = _WAPI_PRIVATE_HANDLES(handle_idx).u.shared.offset;
-       shared_meta = &_wapi_shared_layout->metadata[ref];
-       
-       old_off = shared_meta->offset;
-       new_off = _wapi_handle_new_shared (type, handle_specific);
-
-       if (new_off == 0) {
-               _wapi_handle_collect ();
-               new_off = _wapi_handle_new_shared (type, handle_specific);
-       
-               /* FIXME: grow the arrays */
-               g_assert (new_off != 0);
-       }
-       
-       shared_handle_data = &_wapi_shared_layout->handles[new_off];
-
-#ifdef DEBUG
-       g_message ("%s: Old offset: 0x%x, trying to move to 0x%x", __func__,
-                  old_off, new_off);
-#endif
-
-       memcpy (shared_handle_data, handle_specific,
-               sizeof(struct _WapiHandleShared));
-       
-       ret = (InterlockedCompareExchange (&shared_meta->offset, new_off,
-                                          old_off) == old_off);
-
-       if (ret) {
-               /* An entry can't become fresh again (its going to be
-                * collected eventually), so no need for atomic ops
-                * here.
-                */
-               _wapi_shared_layout->handles[old_off].stale = TRUE;
-       }
-
-#ifdef DEBUG
-       if (ret) {
-               g_message ("%s: handle at 0x%x is now found at 0x%x", __func__,
-                          ref, new_off);
-       } else {
-               g_message ("%s: handle at 0x%x already updated", __func__,
-                          ref);
-       }
-#endif
-
-       return(ret);
+       return (TRUE);
 }
 
 /* This will only find shared handles that have already been opened by

Modified: trunk/mono/mono/io-layer/mutexes.c
===================================================================
--- trunk/mono/mono/io-layer/mutexes.c  2005-04-21 11:08:47 UTC (rev 43395)
+++ trunk/mono/mono/io-layer/mutexes.c  2005-04-21 11:46:55 UTC (rev 43396)
@@ -219,7 +219,13 @@
        namedmutex_handle->tid = pthread_self ();
        namedmutex_handle->recursion++;
 
-       _wapi_replace_handle (handle, WAPI_HANDLE_NAMEDMUTEX, &shared_handle);
+       ok = _wapi_replace_handle (handle, WAPI_HANDLE_NAMEDMUTEX,
+                                  &shared_handle);
+       if (ok == FALSE) {
+               SetLastError (ERROR_OUTOFMEMORY);
+               return (FALSE);
+       }
+       
        _wapi_shared_handle_set_signal_state (handle, FALSE);
 
 #ifdef DEBUG

Modified: trunk/mono/mono/io-layer/processes.c
===================================================================
--- trunk/mono/mono/io-layer/processes.c        2005-04-21 11:08:47 UTC (rev 
43395)
+++ trunk/mono/mono/io-layer/processes.c        2005-04-21 11:46:55 UTC (rev 
43396)
@@ -138,7 +138,12 @@
        }
        _wapi_time_t_to_filetime (time(NULL), &process_handle->exit_time);
        
-       _wapi_replace_handle (handle, WAPI_HANDLE_PROCESS, &shared_handle);
+       ok = _wapi_replace_handle (handle, WAPI_HANDLE_PROCESS,
+                                  &shared_handle);
+       if (ok == FALSE) {
+               SetLastError (ERROR_OUTOFMEMORY);
+               return (WAIT_FAILED);
+       }
        
        _wapi_shared_handle_set_signal_state (handle, TRUE);
 
@@ -596,7 +601,13 @@
        
        shared_handle.u.process.id = pid;
 
-       _wapi_replace_handle (handle, WAPI_HANDLE_PROCESS, &shared_handle);
+       ret = _wapi_replace_handle (handle, WAPI_HANDLE_PROCESS,
+                                   &shared_handle);
+       if (ret == FALSE) {
+               SetLastError (ERROR_OUTOFMEMORY);
+               _wapi_handle_unref (handle);
+               goto cleanup;
+       }
        
        if (process_info != NULL) {
                process_info->hProcess = handle;

Modified: trunk/mono/mono/io-layer/threads.c
===================================================================
--- trunk/mono/mono/io-layer/threads.c  2005-04-21 11:08:47 UTC (rev 43395)
+++ trunk/mono/mono/io-layer/threads.c  2005-04-21 11:46:55 UTC (rev 43396)
@@ -103,8 +103,12 @@
                _wapi_timed_thread_join (thread_handle->thread, NULL, NULL);
                thread_handle->joined = TRUE;
 
-               _wapi_replace_handle (handle, WAPI_HANDLE_THREAD,
-                                     &shared_handle);
+               ok = _wapi_replace_handle (handle, WAPI_HANDLE_THREAD,
+                                          &shared_handle);
+               if (ok == FALSE) {
+                       SetLastError (ERROR_OUTOFMEMORY);
+                       return (FALSE);
+               }
        }
 
        return(TRUE);
@@ -141,7 +145,11 @@
        thread_handle->exitstatus = exitstatus;
        thread_handle->state = THREAD_STATE_EXITED;
 
-       _wapi_replace_handle (handle, WAPI_HANDLE_THREAD, &shared_handle);
+       ok = _wapi_replace_handle (handle, WAPI_HANDLE_THREAD, &shared_handle);
+       if (ok == FALSE) {
+               SetLastError (ERROR_OUTOFMEMORY);
+               return;
+       }
        
        _wapi_shared_handle_set_signal_state (handle, TRUE);
 
@@ -284,7 +292,12 @@
                goto thread_hash_cleanup;
        }
        shared_handle.u.thread.thread = thread_handle.thread;
-       _wapi_replace_handle (handle, WAPI_HANDLE_THREAD, &shared_handle);
+       ok = _wapi_replace_handle (handle, WAPI_HANDLE_THREAD, &shared_handle);
+       if (ok == FALSE) {
+               SetLastError (ERROR_OUTOFMEMORY);
+               _wapi_handle_unref (handle);
+               goto thread_hash_cleanup;
+       }
        
        /* Hold a reference while the thread is active, because we use
         * the handle to store thread exit information
@@ -477,7 +490,12 @@
                goto thread_hash_cleanup;
        }
        shared_handle.u.thread.thread = thread_handle.thread;
-       _wapi_replace_handle (handle, WAPI_HANDLE_THREAD, &shared_handle);
+       ok = _wapi_replace_handle (handle, WAPI_HANDLE_THREAD, &shared_handle);
+       if (ok == FALSE) {
+               SetLastError (ERROR_OUTOFMEMORY);
+               _wapi_handle_unref (handle);
+               goto thread_hash_cleanup;
+       }
 
        /* Hold a reference while the thread is active, because we use
         * the handle to store thread exit information

Modified: trunk/mono/mono/io-layer/wait.c
===================================================================
--- trunk/mono/mono/io-layer/wait.c     2005-04-21 11:08:47 UTC (rev 43395)
+++ trunk/mono/mono/io-layer/wait.c     2005-04-21 11:46:55 UTC (rev 43396)
@@ -88,7 +88,7 @@
  * occurred. %WAIT_IO_COMPLETION - the wait was ended by an APC.
  */
 guint32 WaitForSingleObjectEx(gpointer handle, guint32 timeout,
-                                               gboolean alertable)
+                             gboolean alertable)
 {
        guint32 ret, waited;
        struct timespec abstime;

Modified: trunk/mono/mono/metadata/ChangeLog
===================================================================
--- trunk/mono/mono/metadata/ChangeLog  2005-04-21 11:08:47 UTC (rev 43395)
+++ trunk/mono/mono/metadata/ChangeLog  2005-04-21 11:46:55 UTC (rev 43396)
@@ -1,3 +1,7 @@
+2005-04-21  Dick Porter  <[EMAIL PROTECTED]>
+
+       * threads.c (mono_thread_create): Turn an assertion into an error.
+
 2005-04-20  Zoltan Varga  <[EMAIL PROTECTED]>
 
        * threads.c object.c icall.c: Fix some gcc 4.0 warnings.

Modified: trunk/mono/mono/metadata/threads.c
===================================================================
--- trunk/mono/mono/metadata/threads.c  2005-04-21 11:08:47 UTC (rev 43395)
+++ trunk/mono/mono/metadata/threads.c  2005-04-21 11:46:55 UTC (rev 43396)
@@ -363,7 +363,11 @@
                                     CREATE_SUSPENDED, &tid);
        THREAD_DEBUG (g_message (G_GNUC_PRETTY_FUNCTION ": Started thread ID %d 
(handle %p)",
                  tid, thread_handle));
-       g_assert (thread_handle);
+       if (thread_handle == NULL) {
+               /* The thread couldn't be created, so throw an exception */
+               mono_raise_exception (mono_get_exception_execution_engine 
("Couldn't create thread"));
+               return;
+       }
 
        thread->handle=thread_handle;
        thread->tid=tid;

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

Reply via email to