#include "wapi-private.h"
#include "handles-private.h"
-extern WapiHandleOps _wapi_event_ops;
-extern WapiHandleOps _wapi_namedevent_ops;
-
struct _WapiHandle_event
{
gboolean manual;
WapiSharedNamespace sharedns;
};
+void
+_wapi_event_init (void);
+
#endif /* _WAPI_EVENT_PRIVATE_H_ */
static const gchar* namedevent_typename (void);
static gsize namedevent_typesize (void);
-WapiHandleOps _wapi_event_ops = {
+static WapiHandleOps _wapi_event_ops = {
NULL, /* close */
event_signal, /* signal */
event_own, /* own */
event_typesize, /* typesize */
};
-WapiHandleOps _wapi_namedevent_ops = {
+static WapiHandleOps _wapi_namedevent_ops = {
NULL, /* close */
namedevent_signal, /* signal */
namedevent_own, /* own */
namedevent_typesize, /* typesize */
};
-static mono_once_t event_ops_once=MONO_ONCE_INIT;
-
-static void event_ops_init (void)
+void
+_wapi_event_init (void)
{
+ _wapi_handle_register_ops (WAPI_HANDLE_EVENT, &_wapi_event_ops);
+ _wapi_handle_register_ops (WAPI_HANDLE_NAMEDEVENT, &_wapi_namedevent_ops);
+
_wapi_handle_register_capabilities (WAPI_HANDLE_EVENT,
(WapiHandleCapability)(WAPI_HANDLE_CAP_WAIT | WAPI_HANDLE_CAP_SIGNAL));
_wapi_handle_register_capabilities (WAPI_HANDLE_NAMEDEVENT,
gboolean manual, gboolean initial,
const gunichar2 *name G_GNUC_UNUSED)
{
- mono_once (&event_ops_once, event_ops_init);
-
/* Need to blow away any old errors here, because code tests
* for ERROR_ALREADY_EXISTS on success (!) to see if an event
* was freshly created
gpointer handle;
gchar *utf8_name;
int thr_ret;
-
- mono_once (&event_ops_once, event_ops_init);
/* w32 seems to guarantee that opening named objects can't
* race each other
void
_wapi_handle_cleanup (void);
+void
+_wapi_handle_register_ops (WapiHandleType type, WapiHandleOps *ops);
+
extern gpointer _wapi_handle_new (WapiHandleType type,
gpointer handle_specific);
extern gpointer _wapi_handle_new_fd (WapiHandleType type, int fd,
static void (*_wapi_handle_ops_get_close_func (WapiHandleType type))(gpointer, gpointer);
-static WapiHandleCapability handle_caps[WAPI_HANDLE_COUNT] = { (WapiHandleCapability)0 };
-static WapiHandleOps *handle_ops[WAPI_HANDLE_COUNT]={
- NULL,
- &_wapi_file_ops,
- &_wapi_console_ops,
- &_wapi_thread_ops,
- &_wapi_sem_ops,
- &_wapi_mutex_ops,
- &_wapi_event_ops,
-#ifndef DISABLE_SOCKETS
- &_wapi_socket_ops,
-#endif
- &_wapi_find_ops,
- &_wapi_process_ops,
- &_wapi_pipe_ops,
- &_wapi_namedmutex_ops,
- &_wapi_namedsem_ops,
- &_wapi_namedevent_ops,
-};
+static WapiHandleCapability handle_caps [WAPI_HANDLE_COUNT];
+static WapiHandleOps *handle_ops [WAPI_HANDLE_COUNT];
/*
* We can hold _WAPI_PRIVATE_MAX_SLOTS * _WAPI_HANDLE_INITIAL_COUNT handles.
_wapi_handle_unref_full (handle, FALSE);
}
+void
+_wapi_handle_register_ops (WapiHandleType type, WapiHandleOps *ops)
+{
+ handle_ops [type] = ops;
+}
+
void _wapi_handle_register_capabilities (WapiHandleType type,
WapiHandleCapability caps)
{
#include <mono/io-layer/wapi-private.h>
#include "handles-private.h"
-extern WapiHandleOps _wapi_file_ops;
-extern WapiHandleOps _wapi_console_ops;
-extern WapiHandleOps _wapi_find_ops;
-extern WapiHandleOps _wapi_pipe_ops;
-
extern gboolean _wapi_lock_file_region (int fd, off_t offset, off_t length);
extern gboolean _wapi_unlock_file_region (int fd, off_t offset, off_t length);
extern gpointer _wapi_stdhandle_create (int fd, const gchar *name);
static guint32 GetDriveTypeFromPath (const gchar *utf8_root_path_name);
/* File handle is only signalled for overlapped IO */
-WapiHandleOps _wapi_file_ops = {
+static WapiHandleOps _wapi_file_ops = {
file_close, /* close */
NULL, /* signal */
NULL, /* own */
/* Console is mostly the same as file, except it can block waiting for
* input or output
*/
-WapiHandleOps _wapi_console_ops = {
+static WapiHandleOps _wapi_console_ops = {
console_close, /* close */
NULL, /* signal */
NULL, /* own */
static const gchar* find_typename (void);
static gsize find_typesize (void);
-WapiHandleOps _wapi_find_ops = {
+static WapiHandleOps _wapi_find_ops = {
NULL, /* close */
NULL, /* signal */
NULL, /* own */
/* Pipe handles
*/
-WapiHandleOps _wapi_pipe_ops = {
+static WapiHandleOps _wapi_pipe_ops = {
pipe_close, /* close */
NULL, /* signal */
NULL, /* own */
NULL, NULL, NULL, NULL, NULL, NULL},
};
-static mono_once_t io_ops_once=MONO_ONCE_INIT;
static gboolean lock_while_writing = FALSE;
-static void io_ops_init (void)
-{
-/* _wapi_handle_register_capabilities (WAPI_HANDLE_FILE, */
-/* WAPI_HANDLE_CAP_WAIT); */
-/* _wapi_handle_register_capabilities (WAPI_HANDLE_CONSOLE, */
-/* WAPI_HANDLE_CAP_WAIT); */
-
- if (g_getenv ("MONO_STRICT_IO_EMULATION") != NULL) {
- lock_while_writing = TRUE;
- }
-}
-
/* Some utility functions.
*/
int fd, ret;
WapiHandleType handle_type;
struct stat statbuf;
-
- mono_once (&io_ops_once, io_ops_init);
if (attrs & FILE_ATTRIBUTE_TEMPORARY)
perms = 0600;
int filedes[2];
int ret;
- mono_once (&io_ops_once, io_ops_init);
-
MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Creating pipe", __func__);
ret=pipe (filedes);
}
#endif
-
void
_wapi_io_init (void)
{
mono_os_mutex_init (&stdhandle_mutex);
+
+ _wapi_handle_register_ops (WAPI_HANDLE_FILE, &_wapi_file_ops);
+ _wapi_handle_register_ops (WAPI_HANDLE_CONSOLE, &_wapi_console_ops);
+ _wapi_handle_register_ops (WAPI_HANDLE_FIND, &_wapi_find_ops);
+ _wapi_handle_register_ops (WAPI_HANDLE_PIPE, &_wapi_pipe_ops);
+
+/* _wapi_handle_register_capabilities (WAPI_HANDLE_FILE, */
+/* WAPI_HANDLE_CAP_WAIT); */
+/* _wapi_handle_register_capabilities (WAPI_HANDLE_CONSOLE, */
+/* WAPI_HANDLE_CAP_WAIT); */
+
+ if (g_getenv ("MONO_STRICT_IO_EMULATION"))
+ lock_while_writing = TRUE;
}
void
#include "wapi-private.h"
#include "handles-private.h"
-extern WapiHandleOps _wapi_mutex_ops;
-extern WapiHandleOps _wapi_namedmutex_ops;
-
struct _WapiHandle_mutex
{
pthread_t tid;
WapiSharedNamespace sharedns;
};
+void
+_wapi_mutex_init (void);
+
extern void _wapi_mutex_abandon (gpointer data, pid_t pid, pthread_t tid);
#endif /* _WAPI_MUTEX_PRIVATE_H_ */
static const gchar* namedmutex_typename (void);
static gsize namedmutex_typesize (void);
-WapiHandleOps _wapi_mutex_ops = {
+static WapiHandleOps _wapi_mutex_ops = {
NULL, /* close */
mutex_signal, /* signal */
mutex_own, /* own */
mutex_typesize, /* typesize */
};
-WapiHandleOps _wapi_namedmutex_ops = {
+static WapiHandleOps _wapi_namedmutex_ops = {
NULL, /* close */
namedmutex_signal, /* signal */
namedmutex_own, /* own */
namedmutex_typesize, /* typesize */
};
-static mono_once_t mutex_ops_once=MONO_ONCE_INIT;
-
-static void mutex_ops_init (void)
+void
+_wapi_mutex_init (void)
{
+ _wapi_handle_register_ops (WAPI_HANDLE_MUTEX, &_wapi_mutex_ops);
+ _wapi_handle_register_ops (WAPI_HANDLE_NAMEDMUTEX, &_wapi_namedmutex_ops);
+
_wapi_handle_register_capabilities (WAPI_HANDLE_MUTEX,
(WapiHandleCapability)(WAPI_HANDLE_CAP_WAIT | WAPI_HANDLE_CAP_SIGNAL | WAPI_HANDLE_CAP_OWN));
_wapi_handle_register_capabilities (WAPI_HANDLE_NAMEDMUTEX,
*/
gpointer CreateMutex(WapiSecurityAttributes *security G_GNUC_UNUSED, gboolean owned, const gunichar2 *name)
{
- mono_once (&mutex_ops_once, mutex_ops_init);
-
/* Need to blow away any old errors here, because code tests
* for ERROR_ALREADY_EXISTS on success (!) to see if a mutex
* was freshly created */
gchar *utf8_name;
int thr_ret;
- mono_once (&mutex_ops_once, mutex_ops_init);
-
/* w32 seems to guarantee that opening named objects can't
* race each other
*/
#define WAPI_PID_TO_HANDLE(pid) GINT_TO_POINTER (_WAPI_PROCESS_UNHANDLED + (pid))
#define WAPI_HANDLE_TO_PID(handle) (GPOINTER_TO_UINT ((handle)) - _WAPI_PROCESS_UNHANDLED)
-void wapi_processes_init (void);
+void _wapi_processes_init (void);
extern gpointer _wapi_process_duplicate (void);
extern void wapi_processes_cleanup (void);
-extern WapiHandleOps _wapi_process_ops;
-
/*
* MonoProcess describes processes we create.
* It contains a semaphore that can be waited on in order to wait
open_process_map (int pid, const char *mode);
#endif
-WapiHandleOps _wapi_process_ops = {
+static WapiHandleOps _wapi_process_ops = {
process_close, /* close_shared */
NULL, /* signal */
NULL, /* own */
}
void
-wapi_processes_init (void)
+_wapi_processes_init (void)
{
pid_t pid = _wapi_getpid ();
WapiHandle_process process_handle = {0};
+ _wapi_handle_register_ops (WAPI_HANDLE_PROCESS, &_wapi_process_ops);
+
_wapi_handle_register_capabilities (WAPI_HANDLE_PROCESS,
(WapiHandleCapability)(WAPI_HANDLE_CAP_WAIT | WAPI_HANDLE_CAP_SPECIAL_WAIT));
#include "wapi-private.h"
#include "handles-private.h"
-extern WapiHandleOps _wapi_sem_ops;
-extern WapiHandleOps _wapi_namedsem_ops;
-
/* emulate sem_t, so that we can prod the internal state more easily */
struct _WapiHandle_sem
{
WapiSharedNamespace sharedns;
};
+void
+_wapi_semaphore_init (void);
+
#endif /* _WAPI_SEMAPHORE_PRIVATE_H_ */
static const gchar* namedsema_typename (void);
static gsize namedsema_typesize (void);
-WapiHandleOps _wapi_sem_ops = {
+static WapiHandleOps _wapi_sem_ops = {
NULL, /* close */
sema_signal, /* signal */
sema_own, /* own */
sema_typesize, /* typesize */
};
-WapiHandleOps _wapi_namedsem_ops = {
+static WapiHandleOps _wapi_namedsem_ops = {
NULL, /* close */
namedsema_signal, /* signal */
namedsema_own, /* own */
namedsema_typesize, /* typesize */
};
-static mono_once_t sem_ops_once=MONO_ONCE_INIT;
-
-static void sem_ops_init (void)
+void
+_wapi_semaphore_init (void)
{
+ _wapi_handle_register_ops (WAPI_HANDLE_SEM, &_wapi_sem_ops);
+ _wapi_handle_register_ops (WAPI_HANDLE_NAMEDSEM, &_wapi_namedsem_ops);
+
_wapi_handle_register_capabilities (WAPI_HANDLE_SEM,
(WapiHandleCapability)(WAPI_HANDLE_CAP_WAIT | WAPI_HANDLE_CAP_SIGNAL));
_wapi_handle_register_capabilities (WAPI_HANDLE_NAMEDSEM,
*/
gpointer CreateSemaphore(WapiSecurityAttributes *security G_GNUC_UNUSED, gint32 initial, gint32 max, const gunichar2 *name)
{
- mono_once (&sem_ops_once, sem_ops_init);
-
if (max <= 0) {
MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: max <= 0", __func__);
gchar *utf8_name;
int thr_ret;
- mono_once (&sem_ops_once, sem_ops_init);
-
/* w32 seems to guarantee that opening named objects can't
* race each other
*/
#include "wapi-private.h"
#include "handles-private.h"
-extern WapiHandleOps _wapi_socket_ops;
-
struct _WapiHandle_socket
{
int domain;
int still_readable;
};
+void
+_wapi_socket_init (void);
+
#endif /* _WAPI_SOCKET_PRIVATE_H_ */
static const gchar* socket_typename (void);
static gsize socket_typesize (void);
-WapiHandleOps _wapi_socket_ops = {
+static WapiHandleOps _wapi_socket_ops = {
socket_close, /* close */
NULL, /* signal */
NULL, /* own */
socket_typesize, /* typesize */
};
-static mono_once_t socket_ops_once=MONO_ONCE_INIT;
-
-static void socket_ops_init (void)
+void
+_wapi_socket_init (void)
{
- /* No capabilities to register */
+ _wapi_handle_register_ops (WAPI_HANDLE_SOCKET, &_wapi_socket_ops);
}
static void socket_close (gpointer handle, gpointer data)
}
- mono_once (&socket_ops_once, socket_ops_init);
-
handle = _wapi_handle_new_fd (WAPI_HANDLE_SOCKET, fd, &socket_handle);
if (handle == _WAPI_HANDLE_INVALID) {
g_warning ("%s: error creating socket handle", __func__);
/* There doesn't seem to be a defined symbol for this */
#define _WAPI_THREAD_CURRENT (gpointer)0xFFFFFFFE
-extern WapiHandleOps _wapi_thread_ops;
-
struct _WapiHandle_thread
{
pthread_t id;
typedef struct _WapiHandle_thread WapiHandle_thread;
+void
+_wapi_thread_init (void);
+
extern gboolean _wapi_thread_cur_apc_pending (void);
extern void _wapi_thread_own_mutex (gpointer mutex);
extern void _wapi_thread_disown_mutex (gpointer mutex);
_wapi_handle_init ();
_wapi_shm_semaphores_init ();
_wapi_io_init ();
- wapi_processes_init ();
+ _wapi_processes_init ();
+ _wapi_thread_init ();
+ _wapi_semaphore_init ();
+ _wapi_mutex_init ();
+ _wapi_event_init ();
+ _wapi_socket_init ();
}
void
static const gchar* thread_typename (void);
static gsize thread_typesize (void);
-WapiHandleOps _wapi_thread_ops = {
+static WapiHandleOps _wapi_thread_ops = {
NULL, /* close */
NULL, /* signal */
NULL, /* own */
thread_typesize, /* typesize */
};
-static mono_once_t thread_ops_once = MONO_ONCE_INIT;
-
-static void
-thread_ops_init (void)
+void
+_wapi_thread_init (void)
{
- _wapi_handle_register_capabilities (WAPI_HANDLE_THREAD,
- WAPI_HANDLE_CAP_WAIT);
+ _wapi_handle_register_ops (WAPI_HANDLE_THREAD, &_wapi_thread_ops);
+
+ _wapi_handle_register_capabilities (WAPI_HANDLE_THREAD, WAPI_HANDLE_CAP_WAIT);
}
static void thread_details (gpointer data)
WapiHandle_thread thread_handle = {0}, *thread;
gpointer handle;
- mono_once (&thread_ops_once, thread_ops_init);
-
thread_handle.owned_mutexes = g_ptr_array_new ();
handle = _wapi_handle_new (WAPI_HANDLE_THREAD, &thread_handle);