Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move the mono_thread_create () function into utils/mono-threads.h/c, …
…change/simplify its signature a bit.
  • Loading branch information
vargaz committed Jan 13, 2014
1 parent b71c0d6 commit a0afa38
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 44 deletions.
6 changes: 3 additions & 3 deletions mono/metadata/appdomain.c
Expand Up @@ -62,6 +62,7 @@
#include <mono/utils/mono-error-internals.h>
#include <mono/utils/atomic.h>
#include <mono/utils/mono-memory-model.h>
#include <mono/utils/mono-threads.h>
#ifdef HOST_WIN32
#include <direct.h>
#endif
Expand Down Expand Up @@ -2383,7 +2384,6 @@ void
mono_domain_try_unload (MonoDomain *domain, MonoObject **exc)
{
HANDLE thread_handle;
gsize tid;
MonoAppDomainState prev_state;
MonoMethod *method;
unload_data *thread_data;
Expand Down Expand Up @@ -2442,9 +2442,9 @@ mono_domain_try_unload (MonoDomain *domain, MonoObject **exc)
* http://bugzilla.ximian.com/show_bug.cgi?id=27663
*/
#if 0
thread_handle = mono_create_thread (NULL, 0, unload_thread_main, &thread_data, 0, &tid);
thread_handle = mono_threads_create_thread (unload_thread_main, thread_data, 0, 0, NULL);
#else
thread_handle = mono_create_thread (NULL, 0, (LPTHREAD_START_ROUTINE)unload_thread_main, thread_data, CREATE_SUSPENDED, &tid);
thread_handle = mono_threads_create_thread ((LPTHREAD_START_ROUTINE)unload_thread_main, thread_data, 0, CREATE_SUSPENDED, NULL);
if (thread_handle == NULL) {
return;
}
Expand Down
6 changes: 2 additions & 4 deletions mono/metadata/attach.c
Expand Up @@ -31,13 +31,13 @@
#include <netdb.h>
#include <unistd.h>


#include <mono/metadata/assembly.h>
#include <mono/metadata/metadata.h>
#include <mono/metadata/class-internals.h>
#include <mono/metadata/object-internals.h>
#include <mono/metadata/threads-types.h>
#include <mono/metadata/gc-internal.h>
#include <mono/utils/mono-threads.h>
#include "attach.h"

/*
Expand Down Expand Up @@ -473,14 +473,12 @@ transport_send (int fd, guint8 *data, int len)
static void
transport_start_receive (void)
{
gsize tid;

transport_connect ();

if (!listen_fd)
return;

receiver_thread_handle = mono_create_thread (NULL, 0, receiver_thread, NULL, 0, &tid);
receiver_thread_handle = mono_threads_create_thread (receiver_thread, NULL, 0, 0, NULL);
g_assert (receiver_thread_handle);
}

Expand Down
4 changes: 0 additions & 4 deletions mono/metadata/threads-types.h
Expand Up @@ -54,10 +54,6 @@ typedef struct _MonoInternalThread MonoInternalThread;

typedef void (*MonoThreadCleanupFunc) (MonoInternalThread* thread);

gpointer mono_create_thread (WapiSecurityAttributes *security,
guint32 stacksize, WapiThreadStart start,
gpointer param, guint32 create, gsize *tid) MONO_INTERNAL;

MonoInternalThread* mono_thread_create_internal (MonoDomain *domain, gpointer func, gpointer arg, gboolean threadpool_thread, gboolean no_detach, guint32 stack_size) MONO_INTERNAL;

void mono_threads_install_cleanup (MonoThreadCleanupFunc func) MONO_INTERNAL;
Expand Down
33 changes: 4 additions & 29 deletions mono/metadata/threads.c
Expand Up @@ -673,7 +673,7 @@ create_thread (MonoThread *thread, MonoInternalThread *internal, StartInfo *star
gboolean throw_on_failure)
{
HANDLE thread_handle;
gsize tid;
MonoNativeThreadId tid;
guint32 create_flags;

mono_threads_lock ();
Expand Down Expand Up @@ -721,8 +721,8 @@ create_thread (MonoThread *thread, MonoInternalThread *internal, StartInfo *star
if (no_detach)
create_flags |= CREATE_NO_DETACH;
#endif
thread_handle = mono_create_thread (NULL, stack_size, (LPTHREAD_START_ROUTINE)start_wrapper, start_info,
create_flags, &tid);
thread_handle = mono_threads_create_thread ((LPTHREAD_START_ROUTINE)start_wrapper, start_info,
stack_size, create_flags, &tid);
if (thread_handle == NULL) {
/* The thread couldn't be created, so throw an exception */
mono_threads_lock ();
Expand All @@ -738,7 +738,7 @@ create_thread (MonoThread *thread, MonoInternalThread *internal, StartInfo *star
THREAD_DEBUG (g_message ("%s: Started thread ID %"G_GSIZE_FORMAT" (handle %p)", __func__, tid, thread_handle));

internal->handle = thread_handle;
internal->tid = tid;
internal->tid = MONO_NATIVE_THREAD_ID_TO_UINT (tid);

internal->threadpool_thread = threadpool_thread;
if (threadpool_thread)
Expand Down Expand Up @@ -791,31 +791,6 @@ guint32 mono_threads_get_default_stacksize (void)
return default_stacksize;
}

/*
* mono_create_thread:
*
* This is a wrapper around CreateThread which handles differences in the type of
* the the 'tid' argument.
*/
gpointer mono_create_thread (WapiSecurityAttributes *security,
guint32 stacksize, WapiThreadStart start,
gpointer param, guint32 create, gsize *tid)
{
gpointer res;

#ifdef HOST_WIN32
DWORD real_tid;

res = mono_threads_CreateThread (security, stacksize, start, param, create, &real_tid);
if (tid)
*tid = real_tid;
#else
res = CreateThread (security, stacksize, start, param, create, tid);
#endif

return res;
}

/*
* mono_thread_create_internal:
*
Expand Down
2 changes: 1 addition & 1 deletion mono/mini/aot-compiler.c
Expand Up @@ -8386,7 +8386,7 @@ compile_methods (MonoAotCompile *acfg)
user_data [1] = acfg;
user_data [2] = frag;

handle = mono_create_thread (NULL, 0, (gpointer)compile_thread_main, user_data, 0, NULL);
handle = mono_threads_create_thread ((gpointer)compile_thread_main, user_data, 0, 0, NULL);
g_ptr_array_add (threads, handle);
}
g_free (methods);
Expand Down
4 changes: 1 addition & 3 deletions mono/mini/debugger-agent.c
Expand Up @@ -1576,9 +1576,7 @@ stop_debugger_thread (void)
static void
start_debugger_thread (void)
{
gsize tid;

debugger_thread_handle = mono_create_thread (NULL, 0, debugger_thread, NULL, 0, &tid);
debugger_thread_handle = mono_threads_create_thread (debugger_thread, NULL, 0, 0, NULL);
g_assert (debugger_thread_handle);
}

Expand Down
28 changes: 28 additions & 0 deletions mono/utils/mono-threads.c
Expand Up @@ -690,3 +690,31 @@ mono_thread_info_is_async_context (void)
return FALSE;
}

/*
* mono_threads_create_thread:
*
* Create a new thread executing START with argument ARG. Store its id into OUT_TID.
* Returns: a windows or io-layer handle for the thread.
*/
HANDLE
mono_threads_create_thread (LPTHREAD_START_ROUTINE start, gpointer arg, guint32 stack_size, guint32 creation_flags, MonoNativeThreadId *out_tid)
{
HANDLE res;

#ifdef HOST_WIN32
DWORD real_tid;

res = mono_threads_CreateThread (NULL, stack_size, start, arg, creation_flags, &real_tid);
if (out_tid)
*out_tid = real_tid;
#else
gsize real_tid;

res = CreateThread (NULL, stack_size, start, arg, creation_flags, &real_tid);
if (out_tid)
*out_tid = (gpointer)real_tid;
#endif

return res;
}

7 changes: 7 additions & 0 deletions mono/utils/mono-threads.h
Expand Up @@ -26,6 +26,8 @@ typedef HANDLE MonoNativeThreadHandle; /* unused */

typedef DWORD mono_native_thread_return_t;

#define MONO_NATIVE_THREAD_ID_TO_UINT(tid) (tid)

#else

#include <pthread.h>
Expand All @@ -47,6 +49,8 @@ typedef pthread_t MonoNativeThreadId;

typedef void* mono_native_thread_return_t;

#define MONO_NATIVE_THREAD_ID_TO_UINT(tid) GPOINTER_TO_UINT((tid))

#endif /* #ifdef HOST_WIN32 */

/*
Expand Down Expand Up @@ -251,6 +255,9 @@ mono_thread_info_set_is_async_context (gboolean async_context) MONO_INTERNAL;
gboolean
mono_thread_info_is_async_context (void) MONO_INTERNAL;

HANDLE
mono_threads_create_thread (LPTHREAD_START_ROUTINE start, gpointer arg, guint32 stack_size, guint32 creation_flags, MonoNativeThreadId *out_tid);

#if !defined(HOST_WIN32)

int
Expand Down

0 comments on commit a0afa38

Please sign in to comment.