} 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? */
#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];
return(fd);
}
-static gboolean wapi_shm_disabled = 0;
-
/*
* _wapi_shm_attach:
* @success: Was it a success
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);
}
}
return(shm_seg);
}
-void _wapi_shm_semaphores_init ()
+static void shm_semaphores_init (void)
{
key_t key;
key_t oldkey;
_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;
}
}
-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;
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;
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;
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));
+ }
+}