* Dietmar Maurer (dietmar@ximian.com)
* Gonzalo Paniagua Javier (gonzalo@ximian.com)
*
- * (C) 2001-2003 Ximian, Inc.
- * (c) 2004,2005 Novell, Inc. (http://www.novell.com)
+ * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
+ * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
*/
#include <config.h>
#include <unistd.h>
#endif
#include <string.h>
-
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
#include <mono/utils/mono-poll.h>
#ifdef HAVE_EPOLL
#include <sys/epoll.h>
#endif
+#ifndef DISABLE_SOCKETS
#include "mono/io-layer/socket-wrappers.h"
+#endif
#include "threadpool.h"
AIO_OP_LAST
};
+#ifdef DISABLE_SOCKETS
+#define socket_io_cleanup(x)
+#else
static void
socket_io_cleanup (SocketIOData *data)
{
(SOCKET)(gssize)x->handle, x->buffer, x->offset, x->size,\
x->socket_flags, &x->error);
+#endif /* !DISABLE_SOCKETS */
static void
unregister_job (MonoAsyncResult *obj)
return FALSE;
}
+#ifndef DISABLE_SOCKETS
static void
async_invoke_io_thread (gpointer data)
{
timeout -= mono_msec_ticks () - start_time;
- if (wr != WAIT_TIMEOUT)
+ if (wr != WAIT_TIMEOUT && wr != WAIT_IO_COMPLETION)
data = dequeue_job (&io_queue_lock, &async_io_queue);
}
while (!data && timeout > 0);
}
io_job_added = CreateSemaphore (NULL, 0, 0x7fffffff, NULL);
g_assert (io_job_added != NULL);
- InitializeCriticalSection (&io_queue_lock);
if (data->epoll_disabled) {
mono_thread_create_internal (mono_get_root_domain (), socket_io_poll_main, data, TRUE);
}
MonoMList *list;
SocketIOData *data = &socket_io_data;
-#if defined(PLATFORM_MACOSX) || defined(PLATFORM_BSD6) || defined(PLATFORM_WIN32) || defined(PLATFORM_SOLARIS)
+#if defined(PLATFORM_MACOSX) || defined(PLATFORM_BSD) || defined(PLATFORM_WIN32) || defined(PLATFORM_SOLARIS)
/* select() for connect() does not work well on the Mac. Bug #75436. */
/* Bug #77637 for the BSD 6 case */
/* Bug #78888 for the Windows case */
return TRUE;
}
+#endif /* !DISABLE_SOCKETS */
static void
mono_async_invoke (MonoAsyncResult *ares)
if (ares->execution_context) {
/* use captured ExecutionContext (if available) */
thread = mono_thread_current ();
- MONO_OBJECT_SETREF (ares, original_context, thread->execution_context);
- MONO_OBJECT_SETREF (thread, execution_context, ares->execution_context);
+ MONO_OBJECT_SETREF (ares, original_context, mono_thread_get_execution_context ());
+ mono_thread_set_execution_context (ares->execution_context);
} else {
ares->original_context = NULL;
}
/* restore original thread execution context if flow isn't suppressed, i.e. non null */
if (ares->original_context) {
- MONO_OBJECT_SETREF (thread, execution_context, ares->original_context);
+ mono_thread_set_execution_context (ares->original_context);
ares->original_context = NULL;
}
MONO_GC_REGISTER_ROOT (socket_io_data.sock_to_state);
InitializeCriticalSection (&socket_io_data.io_lock);
InitializeCriticalSection (&ares_lock);
+ InitializeCriticalSection (&io_queue_lock);
ares_htable = mono_g_hash_table_new_type (NULL, NULL, MONO_HASH_KEY_VALUE_GC);
job_added = CreateSemaphore (NULL, 0, 0x7fffffff, NULL);
g_assert (job_added != NULL);
ares = mono_async_result_new (domain, NULL, ac->state, NULL, (MonoObject*)ac);
MONO_OBJECT_SETREF (ares, async_delegate, target);
+ if (domain->state == MONO_APPDOMAIN_UNLOADED || domain->state == MONO_APPDOMAIN_UNLOADING)
+ return ares;
+
EnterCriticalSection (&ares_lock);
mono_g_hash_table_insert (ares_htable, ares, ares);
LeaveCriticalSection (&ares_lock);
+#ifndef DISABLE_SOCKETS
if (socket_io_filter (target, state)) {
socket_io_add (ares, (MonoSocketAsyncResult *) state);
return ares;
}
-
+#endif
+
start_thread_or_queue (ares);
return ares;
}
}
if (!list->array) {
MONO_GC_REGISTER_ROOT (list->array);
- list->array = mono_array_new (mono_get_root_domain (), mono_defaults.object_class, 16);
+ list->array = mono_array_new_cached (mono_get_root_domain (), mono_defaults.object_class, 16);
} else {
int count = list->next_elem - list->first_elem;
/* slide the array or create a larger one if it's full */
if (list->first_elem) {
mono_array_memcpy_refs (list->array, 0, list->array, list->first_elem, count);
} else {
- MonoArray *newa = mono_array_new (mono_get_root_domain (), mono_defaults.object_class, mono_array_length (list->array) * 2);
+ MonoArray *newa = mono_array_new_cached (mono_get_root_domain (), mono_defaults.object_class, mono_array_length (list->array) * 2);
mono_array_memcpy_refs (newa, 0, list->array, list->first_elem, count);
list->array = newa;
}
return NULL;
}
ar = mono_array_get (list->array, MonoObject*, list->first_elem);
+ mono_array_setref (list->array, list->first_elem, NULL);
list->first_elem++;
count = list->next_elem - list->first_elem;
/* reduce the size of the array if it's mostly empty */
if (mono_array_length (list->array) > 16 && count < (mono_array_length (list->array) / 3)) {
- MonoArray *newa = mono_array_new (mono_get_root_domain (), mono_defaults.object_class, mono_array_length (list->array) / 2);
+ MonoArray *newa = mono_array_new_cached (mono_get_root_domain (), mono_defaults.object_class, mono_array_length (list->array) / 2);
mono_array_memcpy_refs (newa, 0, list->array, list->first_elem, count);
list->array = newa;
list->first_elem = 0;
timeout -= mono_msec_ticks () - start_time;
- if (wr != WAIT_TIMEOUT)
+ if (wr != WAIT_TIMEOUT && wr != WAIT_IO_COMPLETION)
data = dequeue_job (&mono_delegate_section, &async_call_queue);
}
while (!data && timeout > 0);