* Author:
* Dick Porter (dick@ximian.com)
*
- * (C) 2002-2006 Novell, Inc.
+ * (C) 2002-2011 Novell, Inc.
+ * Copyright 2011 Xamarin Inc
*/
#include <config.h>
#include <mono/io-layer/wapi.h>
#include <mono/io-layer/wapi-private.h>
#include <mono/io-layer/handles-private.h>
-#include <mono/io-layer/mono-mutex.h>
#include <mono/io-layer/misc-private.h>
#include <mono/io-layer/shared.h>
#include <mono/io-layer/collection.h>
#include <mono/io-layer/process-private.h>
#include <mono/io-layer/critical-section-private.h>
+#include <mono/utils/mono-mutex.h>
#undef DEBUG_REFS
#if 0
static pid_t _wapi_pid;
static mono_once_t pid_init_once = MONO_ONCE_INIT;
-static gpointer _wapi_handle_real_new (WapiHandleType type, gpointer handle_specific);
static void _wapi_handle_unref_full (gpointer handle, gboolean ignore_private_busy_handles);
static void pid_init (void)
}
-static mono_mutex_t scan_mutex = MONO_MUTEX_INITIALIZER;
+static mono_mutex_t scan_mutex;
static void handle_cleanup (void)
{
g_free (_wapi_private_handles [i]);
}
-void _wapi_cleanup ()
-{
- g_assert (_wapi_has_shut_down == FALSE);
-
- _wapi_has_shut_down = TRUE;
-
- _wapi_critical_section_cleanup ();
- _wapi_error_cleanup ();
- _wapi_thread_cleanup ();
-}
-
-static mono_once_t shared_init_once = MONO_ONCE_INIT;
-static void shared_init (void)
+/*
+ * wapi_init:
+ *
+ * Initialize the io-layer.
+ */
+void
+wapi_init (void)
{
g_assert ((sizeof (handle_ops) / sizeof (handle_ops[0]))
== WAPI_HANDLE_COUNT);
if (_wapi_shm_enabled ())
_wapi_collection_init ();
#endif
+ _wapi_io_init ();
+ mono_mutex_init (&scan_mutex);
- /* Can't call wapi_handle_new as it calls us recursively */
- _wapi_global_signal_handle = _wapi_handle_real_new (WAPI_HANDLE_EVENT, NULL);
+ _wapi_global_signal_handle = _wapi_handle_new (WAPI_HANDLE_EVENT, NULL);
_wapi_global_signal_cond = &_WAPI_PRIVATE_HANDLES (GPOINTER_TO_UINT (_wapi_global_signal_handle)).signal_cond;
_wapi_global_signal_mutex = &_WAPI_PRIVATE_HANDLES (GPOINTER_TO_UINT (_wapi_global_signal_handle)).signal_mutex;
+
/* Using g_atexit here instead of an explicit function call in
* a cleanup routine lets us cope when a third-party library
* calls exit (eg if an X client loses the connection to its
g_atexit (handle_cleanup);
}
+void
+wapi_cleanup (void)
+{
+ g_assert (_wapi_has_shut_down == FALSE);
+
+ _wapi_has_shut_down = TRUE;
+
+ _wapi_error_cleanup ();
+ _wapi_thread_cleanup ();
+}
+
static void _wapi_handle_init_shared (struct _WapiHandleShared *handle,
WapiHandleType type,
gpointer handle_specific)
thr_ret = pthread_cond_init (&handle->signal_cond, NULL);
g_assert (thr_ret == 0);
- thr_ret = mono_mutex_init (&handle->signal_mutex, NULL);
+ thr_ret = mono_mutex_init (&handle->signal_mutex);
g_assert (thr_ret == 0);
if (handle_specific != NULL) {
return(0);
}
-static gpointer _wapi_handle_real_new (WapiHandleType type, gpointer handle_specific)
+gpointer
+_wapi_handle_new (WapiHandleType type, gpointer handle_specific)
{
guint32 handle_idx = 0;
gpointer handle;
int thr_ret;
-
+
+ g_assert (_wapi_has_shut_down == FALSE);
+
DEBUG ("%s: Creating new handle of type %s", __func__,
_wapi_handle_typename[type]);
return(handle);
}
-gpointer _wapi_handle_new (WapiHandleType type, gpointer handle_specific)
-{
- g_assert (_wapi_has_shut_down == FALSE);
-
- mono_once (&shared_init_once, shared_init);
-
- return _wapi_handle_real_new (type, handle_specific);
-}
-
gpointer _wapi_handle_new_from_offset (WapiHandleType type, guint32 offset,
gboolean timestamp)
{
g_assert (_wapi_has_shut_down == FALSE);
- mono_once (&shared_init_once, shared_init);
-
DEBUG ("%s: Creating new handle of type %s to offset %d", __func__,
_wapi_handle_typename[type], offset);
g_assert (_wapi_has_shut_down == FALSE);
- mono_once (&shared_init_once, shared_init);
-
DEBUG ("%s: Creating new handle of type %s", __func__,
_wapi_handle_typename[type]);
file_share_hash_lock ();
g_hash_table_remove (file_share_hash, share_info);
file_share_hash_unlock ();
+ /* The hashtable dtor frees share_info */
} else {
memset (share_info, '\0', sizeof(struct _WapiFileShare));
}
*/
DEBUG ("%s: Didn't find it, destroying entry", __func__);
- memset (share_info, '\0', sizeof(struct _WapiFileShare));
+ _wapi_free_share_info (share_info);
}
}
/* Blank out this entry, as it is stale */
DEBUG ("%s: Didn't find it, destroying entry", __func__);
- memset (share_info, '\0', sizeof(struct _WapiFileShare));
+ _wapi_free_share_info (share_info);
}
done: