if (IsServer) {
SetPrivateCertificate (nativeServerCertificate);
} else {
- ssl.SetServerName (TargetHost);
+ ssl.SetServerName (ServerName);
}
}
if (!IsServer)
ctx.SetSelectCallback (SelectCallback);
- var host = TargetHost;
- if (!string.IsNullOrEmpty (host)) {
- var pos = TargetHost.IndexOf (':');
- if (pos > 0)
- host = host.Substring (0, pos);
- }
-
- ctx.SetVerifyParam (MonoBtlsProvider.GetVerifyParam (host, IsServer));
+ ctx.SetVerifyParam (MonoBtlsProvider.GetVerifyParam (ServerName, IsServer));
TlsProtocolCode minProtocol, maxProtocol;
GetProtocolVersions (out minProtocol, out maxProtocol);
MobileAuthenticatedStream parent;
bool serverMode;
string targetHost;
+ string serverName;
SslProtocols enabledProtocols;
X509Certificate serverCertificate;
X509CertificateCollection clientCertificates;
this.clientCertificates = clientCertificates;
this.askForClientCert = askForClientCert;
+ serverName = targetHost;
+ if (!string.IsNullOrEmpty (serverName)) {
+ var pos = serverName.IndexOf (':');
+ if (pos > 0)
+ serverName = serverName.Substring (0, pos);
+ }
+
certificateValidator = CertificateValidationHelper.GetInternalValidator (
parent.Settings, parent.Provider);
}
get { return targetHost; }
}
+ protected string ServerName {
+ get { return serverName; }
+ }
+
protected bool AskForClientCertificate {
get { return askForClientCert; }
}
cleanup_close (gpointer handle, gpointer data, gpointer user_data)
{
if (mono_w32handle_get_type (handle) == MONO_W32HANDLE_SOCKET)
- mono_w32handle_ops_close (handle, data);
+ mono_w32handle_force_close (handle, data);
return FALSE;
}
#include <mono/metadata/metadata.h>
#include <mono/metadata/image.h>
#include <mono/utils/mono-error.h>
-#include <mono/utils/mono-dl.h>
MONO_BEGIN_DECLS
void*
mono_lookup_internal_call_full (MonoMethod *method, mono_bool *uses_handles);
-void
-mono_loader_register_module (const char *name, MonoDl *module);
-
MONO_API const char*
mono_lookup_icall_symbol (MonoMethod *m);
MonoImageSet *
mono_find_image_set_owner (void *ptr);
+void
+mono_loader_register_module (const char *name, MonoDl *module);
+
#endif /* __MONO_METADATA_INTERNALS_H__ */
ok = mono_w32handle_lookup (handle, type, (gpointer *)&event_handle);
if (!ok) {
g_warning ("%s: error looking up %s handle %p",
- __func__, mono_w32handle_ops_typename (type), handle);
+ __func__, mono_w32handle_get_typename (type), handle);
return FALSE;
}
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: owning %s handle %p",
- __func__, mono_w32handle_ops_typename (type), handle);
+ __func__, mono_w32handle_get_typename (type), handle);
if (!event_handle->manual) {
g_assert (event_handle->set_count > 0);
handle = mono_w32handle_new (type, event_handle);
if (handle == INVALID_HANDLE_VALUE) {
g_warning ("%s: error creating %s handle",
- __func__, mono_w32handle_ops_typename (type));
+ __func__, mono_w32handle_get_typename (type));
SetLastError (ERROR_GEN_FAILURE);
return NULL;
}
mono_w32handle_unlock_handle (handle);
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: created %s handle %p",
- __func__, mono_w32handle_ops_typename (type), handle);
+ __func__, mono_w32handle_get_typename (type), handle);
return handle;
}
{
MonoW32HandleEvent event_handle;
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: creating %s handle",
- __func__, mono_w32handle_ops_typename (MONO_W32HANDLE_EVENT));
+ __func__, mono_w32handle_get_typename (MONO_W32HANDLE_EVENT));
return event_handle_create (&event_handle, MONO_W32HANDLE_EVENT, manual, initial);
}
gchar *utf8_name;
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: creating %s handle",
- __func__, mono_w32handle_ops_typename (MONO_W32HANDLE_NAMEDEVENT));
+ __func__, mono_w32handle_get_typename (MONO_W32HANDLE_NAMEDEVENT));
/* w32 seems to guarantee that opening named objects can't race each other */
mono_w32handle_namespace_lock ();
if (!mono_w32handle_lookup (handle, type, (gpointer *)&event_handle)) {
g_warning ("%s: error looking up %s handle %p",
- __func__, mono_w32handle_ops_typename (type), handle);
+ __func__, mono_w32handle_get_typename (type), handle);
return FALSE;
}
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: setting %s handle %p",
- __func__, mono_w32handle_ops_typename (type), handle);
+ __func__, mono_w32handle_get_typename (type), handle);
mono_w32handle_lock_handle (handle);
if (!mono_w32handle_lookup (handle, type, (gpointer *)&event_handle)) {
g_warning ("%s: error looking up %s handle %p",
- __func__, mono_w32handle_ops_typename (type), handle);
+ __func__, mono_w32handle_get_typename (type), handle);
return FALSE;
}
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: resetting %s handle %p",
- __func__, mono_w32handle_ops_typename (type), handle);
+ __func__, mono_w32handle_get_typename (type), handle);
mono_w32handle_lock_handle (handle);
if (!mono_w32handle_issignalled (handle)) {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: no need to reset %s handle %p",
- __func__, mono_w32handle_ops_typename (type), handle);
+ __func__, mono_w32handle_get_typename (type), handle);
} else {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: obtained write lock on %s handle %p",
- __func__, mono_w32handle_ops_typename (type), handle);
+ __func__, mono_w32handle_get_typename (type), handle);
mono_w32handle_set_signal_state (handle, FALSE, FALSE);
}
if (type != search_data->type) {
/* Its the wrong type, so fail now */
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p matches name but is wrong type: %s",
- __func__, handle, mono_w32handle_ops_typename (type));
+ __func__, handle, mono_w32handle_get_typename (type));
search_data->ret = INVALID_HANDLE_VALUE;
} else {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p matches name and type",
g_error ("%s: type %s does not have a namespace", __func__, type);
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Lookup for handle named [%s] type %s",
- __func__, name, mono_w32handle_ops_typename (type));
+ __func__, name, mono_w32handle_get_typename (type));
search_data.ret = NULL;
search_data.type = type;
*/
#include <config.h>
-
-#if !defined(HOST_WIN32)
-
#include <glib.h>
-#include <pthread.h>
-#include <errno.h>
-#include <unistd.h>
-#ifdef HAVE_SIGNAL_H
-#include <signal.h>
-#endif
-#include <string.h>
-#include <sys/types.h>
-#ifdef HAVE_SYS_SOCKET_H
-# include <sys/socket.h>
-#endif
-#ifdef HAVE_SYS_UN_H
-# include <sys/un.h>
-#endif
-#ifdef HAVE_SYS_MMAN_H
-# include <sys/mman.h>
-#endif
-#ifdef HAVE_DIRENT_H
-# include <dirent.h>
-#endif
-#include <sys/stat.h>
-#ifdef HAVE_SYS_RESOURCE_H
-# include <sys/resource.h>
-#endif
#include "w32handle.h"
return handle_data->type;
}
+static const gchar*
+mono_w32handle_ops_typename (MonoW32HandleType type);
+
+const gchar*
+mono_w32handle_get_typename (MonoW32HandleType type)
+{
+ return mono_w32handle_ops_typename (type);
+}
+
void
mono_w32handle_set_signal_state (gpointer handle, gboolean state, gboolean broadcast)
{
g_free (private_handles [i]);
}
+static gsize
+mono_w32handle_ops_typesize (MonoW32HandleType type);
+
static void mono_w32handle_init_handle (MonoW32HandleBase *handle,
MonoW32HandleType type, gpointer handle_specific)
{
}
}
+static void
+mono_w32handle_ops_close (gpointer handle, gpointer data);
+
+void
+mono_w32handle_force_close (gpointer handle, gpointer data)
+{
+ mono_w32handle_ops_close (handle, data);
+}
+
void
mono_w32handle_register_ops (MonoW32HandleType type, MonoW32HandleOps *ops)
{
return (NULL);
}
-void mono_w32handle_ops_close (gpointer handle, gpointer data)
+static void
+mono_w32handle_ops_close (gpointer handle, gpointer data)
{
MonoW32HandleBase *handle_data;
MonoW32HandleType type;
}
}
-void mono_w32handle_ops_details (MonoW32HandleType type, gpointer data)
+static void
+mono_w32handle_ops_details (MonoW32HandleType type, gpointer data)
{
if (handle_ops[type] != NULL &&
handle_ops[type]->details != NULL) {
}
}
-const gchar* mono_w32handle_ops_typename (MonoW32HandleType type)
+static const gchar*
+mono_w32handle_ops_typename (MonoW32HandleType type)
{
g_assert (handle_ops [type]);
g_assert (handle_ops [type]->typename);
return handle_ops [type]->typename ();
}
-gsize mono_w32handle_ops_typesize (MonoW32HandleType type)
+static gsize
+mono_w32handle_ops_typesize (MonoW32HandleType type)
{
g_assert (handle_ops [type]);
g_assert (handle_ops [type]->typesize);
return handle_ops [type]->typesize ();
}
-void mono_w32handle_ops_signal (gpointer handle)
+static void
+mono_w32handle_ops_signal (gpointer handle)
{
MonoW32HandleBase *handle_data;
MonoW32HandleType type;
}
}
-gboolean mono_w32handle_ops_own (gpointer handle, guint32 *statuscode)
+static gboolean
+mono_w32handle_ops_own (gpointer handle, guint32 *statuscode)
{
MonoW32HandleBase *handle_data;
MonoW32HandleType type;
}
}
-gboolean mono_w32handle_ops_isowned (gpointer handle)
+static gboolean
+mono_w32handle_ops_isowned (gpointer handle)
{
MonoW32HandleBase *handle_data;
MonoW32HandleType type;
}
}
-MonoW32HandleWaitRet
+static MonoW32HandleWaitRet
mono_w32handle_ops_specialwait (gpointer handle, guint32 timeout, gboolean *alerted)
{
MonoW32HandleBase *handle_data;
}
}
-void mono_w32handle_ops_prewait (gpointer handle)
+static void
+mono_w32handle_ops_prewait (gpointer handle)
{
MonoW32HandleBase *handle_data;
MonoW32HandleType type;
static void
spin (guint32 ms)
{
+#ifdef HOST_WIN32
+ SleepEx (ms, TRUE);
+#else
struct timespec sleepytime;
g_assert (ms < 1000);
sleepytime.tv_sec = 0;
sleepytime.tv_nsec = ms * 1000000;
nanosleep (&sleepytime, NULL);
+#endif /* HOST_WIN32 */
}
static void
return ret;
}
-
-#endif /* !defined(HOST_WIN32) */
MonoW32HandleType
mono_w32handle_get_type (gpointer handle);
+const gchar*
+mono_w32handle_get_typename (MonoW32HandleType type);
+
gboolean
mono_w32handle_lookup (gpointer handle, MonoW32HandleType type, gpointer *handle_specific);
mono_w32handle_test_capabilities (gpointer handle, MonoW32HandleCapability caps);
void
-mono_w32handle_ops_close (gpointer handle, gpointer data);
-
-void
-mono_w32handle_ops_signal (gpointer handle);
-
-gboolean
-mono_w32handle_ops_own (gpointer handle, guint32 *statuscode);
-
-gboolean
-mono_w32handle_ops_isowned (gpointer handle);
-
-MonoW32HandleWaitRet
-mono_w32handle_ops_specialwait (gpointer handle, guint32 timeout, gboolean *alerted);
-
-void
-mono_w32handle_ops_prewait (gpointer handle);
-
-void
-mono_w32handle_ops_details (MonoW32HandleType type, gpointer data);
-
-const gchar*
-mono_w32handle_ops_typename (MonoW32HandleType type);
-
-gsize
-mono_w32handle_ops_typesize (MonoW32HandleType type);
+mono_w32handle_force_close (gpointer handle, gpointer data);
void
mono_w32handle_set_signal_state (gpointer handle, gboolean state, gboolean broadcast);
*statuscode = WAIT_OBJECT_0;
if (!mono_w32handle_lookup (handle, type, (gpointer *)&mutex_handle)) {
- g_warning ("%s: error looking up %s handle %p", __func__, mono_w32handle_ops_typename (type), handle);
+ g_warning ("%s: error looking up %s handle %p", __func__, mono_w32handle_get_typename (type), handle);
return FALSE;
}
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: owning %s handle %p, before: [tid: %p, recursion: %d], after: [tid: %p, recursion: %d], abandoned: %s",
- __func__, mono_w32handle_ops_typename (type), handle, (gpointer) mutex_handle->tid, mutex_handle->recursion, (gpointer) pthread_self (), mutex_handle->recursion + 1, mutex_handle->abandoned ? "true" : "false");
+ __func__, mono_w32handle_get_typename (type), handle, (gpointer) mutex_handle->tid, mutex_handle->recursion, (gpointer) pthread_self (), mutex_handle->recursion + 1, mutex_handle->abandoned ? "true" : "false");
if (mutex_handle->recursion != 0) {
g_assert (pthread_equal (pthread_self (), mutex_handle->tid));
MonoW32HandleMutex *mutex_handle;
if (!mono_w32handle_lookup (handle, type, (gpointer *)&mutex_handle)) {
- g_warning ("%s: error looking up %s handle %p", __func__, mono_w32handle_ops_typename (type), handle);
+ g_warning ("%s: error looking up %s handle %p", __func__, mono_w32handle_get_typename (type), handle);
return FALSE;
}
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: testing ownership %s handle %p",
- __func__, mono_w32handle_ops_typename (type), handle);
+ __func__, mono_w32handle_get_typename (type), handle);
if (mutex_handle->recursion > 0 && pthread_equal (mutex_handle->tid, pthread_self ())) {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: %s handle %p owned by %p",
- __func__, mono_w32handle_ops_typename (type), handle, (gpointer) pthread_self ());
+ __func__, mono_w32handle_get_typename (type), handle, (gpointer) pthread_self ());
return TRUE;
} else {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: %s handle %p not owned by %p, tid: %p recursion: %d",
- __func__, mono_w32handle_ops_typename (type), handle, (gpointer) pthread_self (), (gpointer) mutex_handle->tid, mutex_handle->recursion);
+ __func__, mono_w32handle_get_typename (type), handle, (gpointer) pthread_self (), (gpointer) mutex_handle->tid, mutex_handle->recursion);
return FALSE;
}
}
if (!mono_w32handle_lookup (handle, type, (gpointer *)&mutex_handle)) {
g_warning ("%s: error looking up %s handle %p",
- __func__, mono_w32handle_ops_typename (type), handle);
+ __func__, mono_w32handle_get_typename (type), handle);
return;
}
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: pre-waiting %s handle %p, owned? %s",
- __func__, mono_w32handle_ops_typename (type), handle, mutex_handle->recursion != 0 ? "true" : "false");
+ __func__, mono_w32handle_get_typename (type), handle, mutex_handle->recursion != 0 ? "true" : "false");
}
/* The shared state is not locked when prewait methods are called */
handle = mono_w32handle_new (type, mutex_handle);
if (handle == INVALID_HANDLE_VALUE) {
g_warning ("%s: error creating %s handle",
- __func__, mono_w32handle_ops_typename (type));
+ __func__, mono_w32handle_get_typename (type));
SetLastError (ERROR_GEN_FAILURE);
return NULL;
}
mono_w32handle_unlock_handle (handle);
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: created %s handle %p",
- __func__, mono_w32handle_ops_typename (type), handle);
+ __func__, mono_w32handle_get_typename (type), handle);
return handle;
}
{
MonoW32HandleMutex mutex_handle;
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: creating %s handle",
- __func__, mono_w32handle_ops_typename (MONO_W32HANDLE_MUTEX));
+ __func__, mono_w32handle_get_typename (MONO_W32HANDLE_MUTEX));
return mutex_handle_create (&mutex_handle, MONO_W32HANDLE_MUTEX, owned);
}
gchar *utf8_name;
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: creating %s handle",
- __func__, mono_w32handle_ops_typename (MONO_W32HANDLE_NAMEDMUTEX));
+ __func__, mono_w32handle_get_typename (MONO_W32HANDLE_NAMEDMUTEX));
/* w32 seems to guarantee that opening named objects can't race each other */
mono_w32handle_namespace_lock ();
if (!mono_w32handle_lookup (handle, type, (gpointer *)&mutex_handle)) {
g_warning ("%s: error looking up %s handle %p",
- __func__, mono_w32handle_ops_typename (type), handle);
+ __func__, mono_w32handle_get_typename (type), handle);
return FALSE;
}
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: releasing %s handle %p, tid: %p recursion: %d",
- __func__, mono_w32handle_ops_typename (type), handle, (gpointer) mutex_handle->tid, mutex_handle->recursion);
+ __func__, mono_w32handle_get_typename (type), handle, (gpointer) mutex_handle->tid, mutex_handle->recursion);
mono_w32handle_lock_handle (handle);
ret = FALSE;
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: we don't own %s handle %p (owned by %ld, me %ld)",
- __func__, mono_w32handle_ops_typename (type), handle, (long)mutex_handle->tid, (long)tid);
+ __func__, mono_w32handle_get_typename (type), handle, (long)mutex_handle->tid, (long)tid);
} else {
ret = TRUE;
thread_disown_mutex (mono_thread_internal_current (), handle);
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unlocking %s handle %p, tid: %p recusion : %d",
- __func__, mono_w32handle_ops_typename (type), handle, (gpointer) mutex_handle->tid, mutex_handle->recursion);
+ __func__, mono_w32handle_get_typename (type), handle, (gpointer) mutex_handle->tid, mutex_handle->recursion);
mutex_handle->tid = 0;
mono_w32handle_set_signal_state (handle, TRUE, FALSE);
if (!mono_w32handle_lookup (handle, type, (gpointer *)&mutex_handle)) {
g_error ("%s: error looking up %s handle %p",
- __func__, mono_w32handle_ops_typename (type), handle);
+ __func__, mono_w32handle_get_typename (type), handle);
}
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: abandoning %s handle %p",
- __func__, mono_w32handle_ops_typename (type), handle);
+ __func__, mono_w32handle_get_typename (type), handle);
tid = MONO_UINT_TO_NATIVE_THREAD_ID (internal->tid);
thread_disown_mutex (internal, handle);
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: abandoned %s handle %p",
- __func__, mono_w32handle_ops_typename (type), handle);
+ __func__, mono_w32handle_get_typename (type), handle);
mono_w32handle_unlock_handle (handle);
}
if (!mono_w32handle_lookup (handle, type, (gpointer *)&sem_handle)) {
g_warning ("%s: error looking up %s handle %p",
- __func__, mono_w32handle_ops_typename (type), handle);
+ __func__, mono_w32handle_get_typename (type), handle);
return FALSE;
}
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: owning %s handle %p",
- __func__, mono_w32handle_ops_typename (type), handle);
+ __func__, mono_w32handle_get_typename (type), handle);
sem_handle->val--;
handle = mono_w32handle_new (type, sem_handle);
if (handle == INVALID_HANDLE_VALUE) {
g_warning ("%s: error creating %s handle",
- __func__, mono_w32handle_ops_typename (type));
+ __func__, mono_w32handle_get_typename (type));
SetLastError (ERROR_GEN_FAILURE);
return NULL;
}
mono_w32handle_unlock_handle (handle);
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: created %s handle %p",
- __func__, mono_w32handle_ops_typename (type), handle);
+ __func__, mono_w32handle_get_typename (type), handle);
return handle;
}
{
MonoW32HandleSemaphore sem_handle;
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: creating %s handle, initial %d max %d",
- __func__, mono_w32handle_ops_typename (MONO_W32HANDLE_SEM), initial, max);
+ __func__, mono_w32handle_get_typename (MONO_W32HANDLE_SEM), initial, max);
return sem_handle_create (&sem_handle, MONO_W32HANDLE_SEM, initial, max);
}
gchar *utf8_name;
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: creating %s handle, initial %d max %d name \"%s\"",
- __func__, mono_w32handle_ops_typename (MONO_W32HANDLE_NAMEDSEM), initial, max, (const char*)name);
+ __func__, mono_w32handle_get_typename (MONO_W32HANDLE_NAMEDSEM), initial, max, (const char*)name);
/* w32 seems to guarantee that opening named objects can't race each other */
mono_w32handle_namespace_lock ();
}
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: releasing %s handle %p",
- __func__, mono_w32handle_ops_typename (type), handle);
+ __func__, mono_w32handle_get_typename (type), handle);
mono_w32handle_lock_handle (handle);
/* No idea why max is signed, but thats the spec :-( */
if (sem_handle->val + releaseCount > (guint32)sem_handle->max) {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: %s handle %p val %d count %d max %d, max value would be exceeded",
- __func__, mono_w32handle_ops_typename (type), handle, sem_handle->val, releaseCount, sem_handle->max);
+ __func__, mono_w32handle_get_typename (type), handle, sem_handle->val, releaseCount, sem_handle->max);
ret = FALSE;
} else {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: %s handle %p val %d count %d max %d",
- __func__, mono_w32handle_ops_typename (type), handle, sem_handle->val, releaseCount, sem_handle->max);
+ __func__, mono_w32handle_get_typename (type), handle, sem_handle->val, releaseCount, sem_handle->max);
sem_handle->val += releaseCount;
mono_w32handle_set_signal_state (handle, TRUE, TRUE);
static mono_lazy_init_t status = MONO_LAZY_INIT_STATUS_NOT_INITIALIZED;
static mono_mutex_t signal_mutex;
-static mono_cond_t signal_cond;
static void
initialize (void)
{
mono_os_mutex_init (&signal_mutex);
- mono_os_cond_init (&signal_cond);
}
void
mono_lazy_initialize (&status, initialize);
- mono_os_mutex_init (&event->mutex);
- mono_os_cond_init (&event->cond);
+ event->conds = g_ptr_array_new ();
event->signalled = initial;
}
g_assert (event);
- mono_os_mutex_destroy (&event->mutex);
- mono_os_cond_destroy (&event->cond);
+ if (event->conds->len > 0)
+ g_error ("%s: cannot destroy osevent, there are still %d threads waiting on it", __func__, event->conds->len);
+
+ g_ptr_array_free (event->conds, TRUE);
}
static gboolean
void
mono_os_event_set (MonoOSEvent *event)
{
+ gsize i;
+
g_assert (mono_lazy_is_initialized (&status));
g_assert (event);
- mono_os_mutex_lock (&event->mutex);
mono_os_mutex_lock (&signal_mutex);
event->signalled = TRUE;
- mono_os_cond_broadcast (&event->cond);
- mono_os_cond_broadcast (&signal_cond);
+ for (i = 0; i < event->conds->len; ++i)
+ mono_os_cond_signal ((mono_cond_t*) event->conds->pdata [i]);
- mono_os_mutex_unlock (&event->mutex);
mono_os_mutex_unlock (&signal_mutex);
}
g_assert (event);
- mono_os_mutex_lock (&event->mutex);
+ mono_os_mutex_lock (&signal_mutex);
event->signalled = FALSE;
- mono_os_mutex_unlock (&event->mutex);
+ mono_os_mutex_unlock (&signal_mutex);
}
MonoOSEventWaitRet
}
}
-static void
-mono_os_event_lock_events (MonoOSEvent **events, gsize nevents)
-{
- gint i, j;
-
-retry:
- for (i = 0; i < nevents; ++i) {
- gint res;
-
- res = mono_os_mutex_trylock (&events [i]->mutex);
- if (res != 0) {
- for (j = i - 1; j >= 0; j--)
- mono_os_mutex_unlock (&events [j]->mutex);
-
- mono_thread_info_yield ();
-
- goto retry;
- }
- }
-}
-
-static void
-mono_os_event_unlock_events (MonoOSEvent **events, gsize nevents)
-{
- gint i;
-
- for (i = 0; i < nevents; ++i)
- mono_os_mutex_unlock (&events [i]->mutex);
-}
-
MonoOSEventWaitRet
mono_os_event_wait_multiple (MonoOSEvent **events, gsize nevents, gboolean waitall, guint32 timeout)
{
MonoOSEventWaitRet ret;
- MonoOSEvent *innerevents [MONO_OS_EVENT_WAIT_MAXIMUM_OBJECTS + 1];
+ mono_cond_t signal_cond;
OSEventWaitData *data;
gboolean alerted;
gint64 start;
for (i = 0; i < nevents; ++i)
g_assert (events [i]);
- memcpy (innerevents, events, sizeof (MonoOSEvent*) * nevents);
-
data = g_new0 (OSEventWaitData, 1);
data->ref = 2;
mono_os_event_init (&data->event, FALSE);
- innerevents [nevents ++] = &data->event;
-
alerted = FALSE;
mono_thread_info_install_interrupt (signal_and_unref, data, &alerted);
if (alerted) {
if (timeout != MONO_INFINITE_WAIT)
start = mono_msec_ticks ();
+ mono_os_cond_init (&signal_cond);
+
+ mono_os_mutex_lock (&signal_mutex);
+
+ for (i = 0; i < nevents; ++i)
+ g_ptr_array_add (events [i]->conds, &signal_cond);
+
+ g_ptr_array_add (data->event.conds, &signal_cond);
+
for (;;) {
gint count, lowest;
gboolean signalled;
- mono_os_event_lock_events (innerevents, nevents);
-
count = 0;
lowest = -1;
- for (i = 0; i < nevents - 1; ++i) {
- if (mono_os_event_is_signalled (innerevents [i])) {
+ for (i = 0; i < nevents; ++i) {
+ if (mono_os_event_is_signalled (events [i])) {
count += 1;
if (lowest == -1)
lowest = i;
if (mono_os_event_is_signalled (&data->event))
signalled = TRUE;
else if (waitall)
- signalled = (count == nevents - 1);
+ signalled = (count == nevents);
else /* waitany */
signalled = (count > 0);
- mono_os_event_unlock_events (innerevents, nevents);
-
if (signalled) {
ret = MONO_OS_EVENT_WAIT_RET_SUCCESS_0 + lowest;
goto done;
}
- mono_os_mutex_lock (&signal_mutex);
-
- if (mono_os_event_is_signalled (&data->event)) {
- signalled = TRUE;
- } else if (waitall) {
- signalled = TRUE;
- for (i = 0; i < nevents - 1; ++i) {
- if (!mono_os_event_is_signalled (innerevents [i])) {
- signalled = FALSE;
- break;
- }
- }
- } else {
- signalled = FALSE;
- for (i = 0; i < nevents - 1; ++i) {
- if (mono_os_event_is_signalled (innerevents [i])) {
- signalled = TRUE;
- break;
- }
- }
- }
-
- if (signalled) {
- mono_os_mutex_unlock (&signal_mutex);
- continue;
- }
-
if (timeout == MONO_INFINITE_WAIT) {
mono_os_cond_wait (&signal_cond, &signal_mutex);
} else {
elapsed = mono_msec_ticks () - start;
if (elapsed >= timeout) {
- mono_os_mutex_unlock (&signal_mutex);
-
ret = MONO_OS_EVENT_WAIT_RET_TIMEOUT;
goto done;
}
res = mono_os_cond_timedwait (&signal_cond, &signal_mutex, timeout - elapsed);
if (res != 0) {
- mono_os_mutex_unlock (&signal_mutex);
-
ret = MONO_OS_EVENT_WAIT_RET_TIMEOUT;
goto done;
}
}
-
- mono_os_mutex_unlock (&signal_mutex);
}
done:
+ for (i = 0; i < nevents; ++i)
+ g_ptr_array_remove (events [i]->conds, &signal_cond);
+
+ g_ptr_array_remove (data->event.conds, &signal_cond);
+
+ mono_os_mutex_unlock (&signal_mutex);
+
+ mono_os_cond_destroy (&signal_cond);
+
mono_thread_info_uninstall_interrupt (&alerted);
if (alerted) {
if (InterlockedDecrement ((gint32*) &data->ref) == 0) {
#ifdef HOST_WIN32
gpointer handle;
#else
- mono_mutex_t mutex;
- mono_cond_t cond;
+ GPtrArray *conds;
gboolean signalled;
#endif
};
mono_disasm_code_one
mono_dl_fallback_register
mono_dl_fallback_unregister
-mono_dl_open
mono_dllmap_insert
mono_domain_add_class_static_data
mono_domain_assembly_open
mono_ldtoken
mono_load_remote_field
mono_load_remote_field_new
-mono_loader_register_module
mono_lock_free_alloc
mono_lock_free_allocator_check_consistency
mono_lock_free_allocator_init_allocator
mono_disasm_code_one
mono_dl_fallback_register
mono_dl_fallback_unregister
-mono_dl_open
mono_dllmap_insert
mono_domain_add_class_static_data
mono_domain_assembly_open
mono_ldtoken
mono_load_remote_field
mono_load_remote_field_new
-mono_loader_register_module
mono_lock_free_alloc
mono_lock_free_allocator_check_consistency
mono_lock_free_allocator_init_allocator