THREAD_PRIORITY_HIGHEST = 2
} WapiThreadPriority;
-gpointer wapi_create_thread_handle (void);
-
extern gint32 GetThreadPriority (gpointer handle);
extern gboolean SetThreadPriority (gpointer handle, gint32 priority);
{
}
-static MonoW32HandleThread*
-lookup_thread (HANDLE handle)
-{
- MonoW32HandleThread *thread;
- gboolean ok;
-
- ok = mono_w32handle_lookup (handle, MONO_W32HANDLE_THREAD,
- (gpointer *)&thread);
- g_assert (ok);
- return thread;
-}
-
-/*
- * wapi_create_thread_handle:
- *
- * Create a thread handle for the current thread.
- */
-gpointer
-wapi_create_thread_handle (void)
-{
- MonoW32HandleThread thread_handle = {0}, *thread;
- gpointer handle;
-
- thread_handle.owned_mutexes = g_ptr_array_new ();
-
- handle = mono_w32handle_new (MONO_W32HANDLE_THREAD, &thread_handle);
- if (handle == INVALID_HANDLE_VALUE) {
- g_warning ("%s: error creating thread handle", __func__);
- SetLastError (ERROR_GEN_FAILURE);
-
- return NULL;
- }
-
- thread = lookup_thread (handle);
-
- thread->id = pthread_self ();
-
- /*
- * Hold a reference while the thread is active, because we use
- * the handle to store thread exit information
- */
- mono_w32handle_ref (handle);
-
- MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: started thread id %ld", __func__, thread->id);
-
- return handle;
-}
-
/**
* wapi_init_thread_info_priority:
* @param handle: The thread handle to set.
#if defined(_POSIX_VERSION) || defined(__native_client__)
+#include <pthread.h>
+
#include <sys/resource.h>
#if defined(__native_client__)
void nacl_shutdown_gc_thread(void);
#endif
+static gpointer
+thread_handle_create (void)
+{
+ MonoW32HandleThread thread_data;
+ gpointer thread_handle;
+
+ thread_data.id = pthread_self ();
+ thread_data.owned_mutexes = g_ptr_array_new ();
+ thread_data.priority = THREAD_PRIORITY_NORMAL;
+
+ thread_handle = mono_w32handle_new (MONO_W32HANDLE_THREAD, (gpointer) &thread_data);
+ if (thread_handle == INVALID_HANDLE_VALUE)
+ return NULL;
+
+ /* We need to keep the handle alive, as long as the corresponding managed
+ * thread object is alive. The handle is going to be unref when calling
+ * the finalizer on the MonoThreadInternal object */
+ mono_w32handle_ref (thread_handle);
+
+ return thread_handle;
+}
+
typedef struct {
void *(*start_routine)(void*);
void *arg;
MonoThreadInfo *info;
/* Register the thread with the io-layer */
- handle = wapi_create_thread_handle ();
+ handle = thread_handle_create ();
if (!handle) {
mono_coop_sem_post (&(start_info->registered));
return NULL;
g_assert (info);
if (!info->handle)
- info->handle = wapi_create_thread_handle ();
+ info->handle = thread_handle_create ();
else
mono_w32handle_ref (info->handle);
return info->handle;
#endif
g_assert (!info->handle);
- info->handle = wapi_create_thread_handle ();
+ info->handle = thread_handle_create ();
}
void