2007-04-13 Dick Porter <dick@ximian.com>
authorDick Porter <dick@acm.org>
Fri, 13 Apr 2007 16:09:07 +0000 (16:09 -0000)
committerDick Porter <dick@acm.org>
Fri, 13 Apr 2007 16:09:07 +0000 (16:09 -0000)
* shared.h:
* shared.c: Complete the reimplementation of disabling of shared
memory, by not allocating sysv semaphores when shm disabling has
been requested (either at compile time or run time.)

* processes.c (CreateProcess): Don't synchronize locking across
processes when forking, when shared memory has been disabled.

svn path=/trunk/mono/; revision=75681

mono/io-layer/ChangeLog
mono/io-layer/processes.c
mono/io-layer/shared.c
mono/io-layer/shared.h

index bce57ab5f7b8660b0083daf4c3ec58ccbb179be6..62fdc5ecfd83bbbeb54b9fee17edd868bc19ab10 100644 (file)
@@ -1,3 +1,13 @@
+2007-04-13  Dick Porter  <dick@ximian.com>
+
+       * shared.h:
+       * shared.c: Complete the reimplementation of disabling of shared
+       memory, by not allocating sysv semaphores when shm disabling has
+       been requested (either at compile time or run time.)
+
+       * processes.c (CreateProcess): Don't synchronize locking across
+       processes when forking, when shared memory has been disabled.
+
 2007-04-06  Andreas Faerber  <andreas.faerber@web.de>
 
        * wapi_glob.h:
index 647fc35e70219948cc73c5138795675d62c6925c..d4b49b8e673b2e41eb3887631029b892c60e2f8e 100644 (file)
@@ -868,15 +868,19 @@ gboolean CreateProcess (const gunichar2 *appname, const gunichar2 *cmdline,
        } else if (pid == 0) {
                /* Child */
                
-               /* Wait for the parent to finish setting up the
-                * handle.  The semaphore lock is safe because the
-                * sem_undo structures of a semaphore aren't inherited
-                * across a fork ()
-                */
-               thr_ret = _wapi_handle_lock_shared_handles ();
-               g_assert (thr_ret == 0);
+               if (_wapi_shm_disabled == FALSE) {
+                       /* Wait for the parent to finish setting up
+                        * the handle.  The semaphore lock is safe
+                        * because the sem_undo structures of a
+                        * semaphore aren't inherited across a fork
+                        * (), but we can't do this if we're not using
+                        * the shared memory
+                        */
+                       thr_ret = _wapi_handle_lock_shared_handles ();
+                       g_assert (thr_ret == 0);
        
-               _wapi_handle_unlock_shared_handles ();
+                       _wapi_handle_unlock_shared_handles ();
+               }
                
                /* should we detach from the process group? */
 
index 9a1c9d52caadef981fffce9914ccdf2b2981f5d7..00b9ecb1bae30e0a0bdaa27225f30df5d0eba684 100644 (file)
 
 #undef DEBUG
 
+#ifdef DISABLE_SHARED_HANDLES
+gboolean _wapi_shm_disabled = TRUE;
+#else
+gboolean _wapi_shm_disabled = FALSE;
+#endif
+
 static gchar *_wapi_shm_file (_wapi_shm_t type)
 {
        static gchar file[_POSIX_PATH_MAX];
@@ -214,8 +220,6 @@ try_again:
        return(fd);
 }
 
-static gboolean wapi_shm_disabled = 0;
-
 /*
  * _wapi_shm_attach:
  * @success: Was it a success
@@ -244,10 +248,10 @@ gpointer _wapi_shm_attach (_wapi_shm_t type)
                return NULL;
        }
 
-       if (g_getenv ("MONO_DISABLE_SHM")) {
+       if (_wapi_shm_disabled || g_getenv ("MONO_DISABLE_SHM")) {
                const char* val = g_getenv ("MONO_DISABLE_SHM");
-               if (*val == '1' || *val == 'y' || *val == 'Y') {
-                       wapi_shm_disabled = TRUE;
+               if (val == NULL || *val == '1' || *val == 'y' || *val == 'Y') {
+                       _wapi_shm_disabled = TRUE;
                        return g_malloc0 (size);
                }
        }
@@ -282,7 +286,7 @@ gpointer _wapi_shm_attach (_wapi_shm_t type)
        return(shm_seg);
 }
 
-void _wapi_shm_semaphores_init ()
+static void shm_semaphores_init (void)
 {
        key_t key;
        key_t oldkey;
@@ -432,13 +436,20 @@ again:
        
        _wapi_shm_sem_unlock (_WAPI_SHARED_SEM_PROCESS_COUNT_LOCK);
 
-       if (wapi_shm_disabled)
+       if (_wapi_shm_disabled)
                g_free (tmp_shared);
        else
                munmap (tmp_shared, sizeof(struct _WapiHandleSharedLayout));
 }
 
-void _wapi_shm_semaphores_remove (void)
+static mono_mutex_t noshm_sems[_WAPI_SHARED_SEM_COUNT] = {MONO_MUTEX_INITIALIZER};
+
+static void noshm_semaphores_init (void)
+{
+       /* No need to do anything */
+}
+
+static void shm_semaphores_remove (void)
 {
        int thr_ret;
        int proc_count;
@@ -475,7 +486,12 @@ void _wapi_shm_semaphores_remove (void)
        }
 }
 
-int _wapi_shm_sem_lock (int sem)
+static void noshm_semaphores_remove (void)
+{
+       /* No need to do anything */
+}
+
+static int shm_sem_lock (int sem)
 {
        struct sembuf ops;
        int ret;
@@ -521,7 +537,20 @@ int _wapi_shm_sem_lock (int sem)
        return(ret);
 }
 
-int _wapi_shm_sem_trylock (int sem)
+static int noshm_sem_lock (int sem)
+{
+       int ret;
+       
+#ifdef DEBUG
+       g_message ("%s: locking nosem %d", __func__, sem);
+#endif
+       
+       ret = mono_mutex_lock (&noshm_sems[sem]);
+       
+       return(ret);
+}
+
+static int shm_sem_trylock (int sem)
 {
        struct sembuf ops;
        int ret;
@@ -572,7 +601,20 @@ int _wapi_shm_sem_trylock (int sem)
        return(ret);
 }
 
-int _wapi_shm_sem_unlock (int sem)
+static int noshm_sem_trylock (int sem)
+{
+       int ret;
+       
+#ifdef DEBUG
+       g_message ("%s: trying to lock nosem %d", __func__, sem);
+#endif
+       
+       ret = mono_mutex_trylock (&noshm_sems[sem]);
+       
+       return(ret);
+}
+
+static int shm_sem_unlock (int sem)
 {
        struct sembuf ops;
        int ret;
@@ -619,3 +661,60 @@ int _wapi_shm_sem_unlock (int sem)
        return(ret);
 }
 
+static int noshm_sem_unlock (int sem)
+{
+       int ret;
+       
+#ifdef DEBUG
+       g_message ("%s: unlocking nosem %d", __func__, sem);
+#endif
+       
+       ret = mono_mutex_unlock (&noshm_sems[sem]);
+       
+       return(ret);
+}
+
+void _wapi_shm_semaphores_init (void)
+{
+       if (_wapi_shm_disabled) {
+               noshm_semaphores_init ();
+       } else {
+               shm_semaphores_init ();
+       }
+}
+
+void _wapi_shm_semaphores_remove (void)
+{
+       if (_wapi_shm_disabled) {
+               noshm_semaphores_remove ();
+       } else {
+               shm_semaphores_remove ();
+       }
+}
+
+int _wapi_shm_sem_lock (int sem)
+{
+       if (_wapi_shm_disabled) {
+               return(noshm_sem_lock (sem));
+       } else {
+               return(shm_sem_lock (sem));
+       }
+}
+
+int _wapi_shm_sem_trylock (int sem)
+{
+       if (_wapi_shm_disabled) {
+               return(noshm_sem_trylock (sem));
+       } else {
+               return(shm_sem_trylock (sem));
+       }
+}
+
+int _wapi_shm_sem_unlock (int sem)
+{
+       if (_wapi_shm_disabled) {
+               return(noshm_sem_unlock (sem));
+       } else {
+               return(shm_sem_unlock (sem));
+       }
+}
index be256f23fc6a3cd0a009e5e2bb024e7e0cf3b85a..b2accf82c30399776d33ba827a7acc388195e2f7 100644 (file)
@@ -17,6 +17,8 @@ typedef enum {
        WAPI_SHM_FILESHARE
 } _wapi_shm_t;
 
+extern gboolean _wapi_shm_disabled;
+
 extern gpointer _wapi_shm_attach (_wapi_shm_t type);
 extern void _wapi_shm_semaphores_init (void);
 extern void _wapi_shm_semaphores_remove (void);