*
* Copyright 2011 Novell, Inc (http://www.novell.com)
* Copyright 2011 Xamarin, Inc (http://www.xamarin.com)
+ * Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/
#include <config.h>
static void
dump_threads (void)
{
- MonoThreadInfo *info;
MonoThreadInfo *cur = mono_thread_info_current ();
MOSTLY_ASYNC_SAFE_PRINTF ("STATE CUE CARD: (? means a positive number, usually 1 or 2, * means any number)\n");
#else
MOSTLY_ASYNC_SAFE_PRINTF ("--thread %p id %p [%p] state %x %s\n", info, (void *) mono_thread_info_get_tid (info), (void*)(size_t)info->native_handle, info->thread_state, info == cur ? "GC INITIATOR" : "" );
#endif
-
- } END_FOREACH_THREAD_SAFE
+ } FOREACH_THREAD_SAFE_END
}
gboolean
{
MonoThreadHazardPointers *hp = mono_hazard_pointer_get ();
- if (!mono_lls_find (&thread_list, hp, (uintptr_t)id)) {
+ if (!mono_lls_find (&thread_list, hp, (uintptr_t)id, HAZARD_FREE_ASYNC_CTX)) {
mono_hazard_pointer_clear_all (hp, -1);
return NULL;
}
{
MonoThreadHazardPointers *hp = mono_hazard_pointer_get ();
- if (!mono_lls_insert (&thread_list, hp, (MonoLinkedListSetNode*)info)) {
+ if (!mono_lls_insert (&thread_list, hp, (MonoLinkedListSetNode*)info, HAZARD_FREE_SAFE_CTX)) {
mono_hazard_pointer_clear_all (hp, -1);
return FALSE;
}
gboolean res;
THREADS_DEBUG ("removing info %p\n", info);
- res = mono_lls_remove (&thread_list, hp, (MonoLinkedListSetNode*)info);
+ res = mono_lls_remove (&thread_list, hp, (MonoLinkedListSetNode*)info, HAZARD_FREE_SAFE_CTX);
mono_hazard_pointer_clear_all (hp, -1);
return res;
}
g_byte_array_free (info->stackdata, /*free_segment=*/TRUE);
/*now it's safe to free the thread info.*/
- mono_thread_hazardous_free_or_queue (info, free_thread_info, TRUE, FALSE);
+ mono_thread_hazardous_try_free (info, free_thread_info);
+ /* Pump the HP queue */
+ mono_thread_hazardous_try_free_some ();
+
mono_thread_small_id_free (small_id);
}
mono_coop_sem_init (&global_suspend_semaphore, 1);
mono_os_sem_init (&suspend_semaphore, 0);
- mono_lls_init (&thread_list, NULL);
+ mono_lls_init (&thread_list, NULL, HAZARD_FREE_NO_LOCK);
mono_thread_smr_init ();
mono_threads_init_platform ();
mono_threads_init_coop ();
return mono_thread_info_core_resume (info);
}
-gboolean
-mono_thread_info_check_suspend_result (MonoThreadInfo *info)
-{
- return check_async_suspend (info);
-}
-
/*
FIXME fix cardtable WB to be out of line and check with the runtime if the target is not the
WB trampoline. Another option is to encode wb ranges in MonoJitInfo, but that is somewhat hard.
mono_threads_wait_pending_operations ();
if (!check_async_suspend (info)) {
+ mono_thread_info_core_resume (info);
+ mono_threads_wait_pending_operations ();
mono_hazard_pointer_clear (hp, 1);
return NULL;
}
if (alerted)
return sleep_interruptable (ms, alerted);
- MONO_PREPARE_BLOCKING;
+ MONO_ENTER_GC_SAFE;
if (ms == INFINITE) {
do {
#endif /* __linux__ */
}
- MONO_FINISH_BLOCKING;
+ MONO_EXIT_GC_SAFE;
return 0;
}
gint
mono_thread_info_usleep (guint64 us)
{
- MONO_PREPARE_BLOCKING;
+ MONO_ENTER_GC_SAFE;
g_usleep (us);
- MONO_FINISH_BLOCKING;
+ MONO_EXIT_GC_SAFE;
return 0;
}
return mono_threads_core_open_thread_handle (handle, tid);
}
-void
-mono_thread_info_set_name (MonoNativeThreadId tid, const char *name)
-{
- mono_threads_core_set_name (tid, name);
-}
-
#define INTERRUPT_STATE ((MonoThreadInfoInterruptToken*) (size_t) -1)
struct _MonoThreadInfoInterruptToken {
else
g_string_append_printf (text, "waiting");
}
-
-/* info must be self or be held in a hazard pointer. */
-gboolean
-mono_threads_add_async_job (MonoThreadInfo *info, MonoAsyncJob job)
-{
- MonoAsyncJob old_job;
- do {
- old_job = (MonoAsyncJob) info->service_requests;
- if (old_job & job)
- return FALSE;
- } while (InterlockedCompareExchange (&info->service_requests, old_job | job, old_job) != old_job);
- return TRUE;
-}
-
-MonoAsyncJob
-mono_threads_consume_async_jobs (void)
-{
- MonoThreadInfo *info = (MonoThreadInfo*)mono_native_tls_get_value (thread_info_key);
-
- if (!info)
- return (MonoAsyncJob) 0;
-
- return (MonoAsyncJob) InterlockedExchange (&info->service_requests, 0);
-}