#include <string.h>
#include <unistd.h>
-#ifdef HAVE_SYS_SEM_H
+#if defined(HAVE_SYS_SEM_H) && !(defined(__native_client__) && defined(__GLIBC__))
# include <sys/sem.h>
#else
# define DISABLE_SHARED_HANDLES
gboolean _wapi_shm_disabled = TRUE;
+static gpointer wapi_storage [16];
+
static void
noshm_semaphores_init (void)
{
gpointer
_wapi_shm_attach (_wapi_shm_t type)
{
- guint32 size;
+ gpointer res;
switch(type) {
case WAPI_SHM_DATA:
- return g_malloc0 (sizeof(struct _WapiHandleSharedLayout));
-
+ res = g_malloc0 (sizeof(struct _WapiHandleSharedLayout));
+ break;
case WAPI_SHM_FILESHARE:
- return g_malloc0 (sizeof(struct _WapiFileShareLayout));
-
+ res = g_malloc0 (sizeof(struct _WapiFileShareLayout));
+ break;
default:
g_error ("Invalid type in _wapi_shm_attach ()");
return NULL;
}
+
+ wapi_storage [type] = res;
+ return res;
+}
+
+void
+_wapi_shm_detach (_wapi_shm_t type)
+{
+ g_free (wapi_storage [type]);
+}
+
+gboolean
+_wapi_shm_enabled (void)
+{
+ return FALSE;
}
+
#else
/*
* Use POSIX shared memory if possible, it is simpler, and it has the advantage that
return fd;
}
-static gboolean
-check_disabled (void)
+gboolean
+_wapi_shm_enabled (void)
{
static gboolean env_checked;
env_checked = TRUE;
}
- return _wapi_shm_disabled;
+ return !_wapi_shm_disabled;
}
/*
return NULL;
}
- if (check_disabled ()) {
- return g_malloc0 (size);
+ if (!_wapi_shm_enabled ()) {
+ wapi_storage [type] = g_malloc0 (size);
+ return wapi_storage [type];
}
#ifdef USE_SHM
return shm_seg;
}
+void
+_wapi_shm_detach (_wapi_shm_t type)
+{
+ if (!_wapi_shm_enabled ())
+ g_free (wapi_storage [type]);
+}
+
static void
shm_semaphores_init (void)
{
void
_wapi_shm_semaphores_init (void)
{
- if (check_disabled ())
+ if (!_wapi_shm_enabled ())
noshm_semaphores_init ();
else
shm_semaphores_init ();