本文整理汇总了C++中THREADS_DEBUG函数的典型用法代码示例。如果您正苦于以下问题:C++ THREADS_DEBUG函数的具体用法?C++ THREADS_DEBUG怎么用?C++ THREADS_DEBUG使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了THREADS_DEBUG函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: register_thread
static void*
register_thread (MonoThreadInfo *info, gpointer baseptr)
{
int small_id = mono_thread_info_register_small_id ();
gboolean result;
mono_thread_info_set_tid (info, mono_native_thread_id_get ());
info->small_id = small_id;
InitializeCriticalSection (&info->suspend_lock);
MONO_SEM_INIT (&info->resume_semaphore, 0);
MONO_SEM_INIT (&info->finish_resume_semaphore, 0);
/*set TLS early so SMR works */
mono_native_tls_set_value (thread_info_key, info);
THREADS_DEBUG ("registering info %p tid %p small id %x\n", info, mono_thread_info_get_tid (info), info->small_id);
if (threads_callbacks.thread_register) {
if (threads_callbacks.thread_register (info, baseptr) == NULL) {
g_warning ("thread registation failed\n");
g_free (info);
return NULL;
}
}
mono_threads_platform_register (info);
/*If this fail it means a given thread has been registered twice, which doesn't make sense. */
result = mono_thread_info_insert (info);
g_assert (result);
return info;
}
示例2: mono_thread_info_self_suspend
void
mono_thread_info_self_suspend (void)
{
gboolean ret;
MonoThreadInfo *info = mono_thread_info_current ();
if (!info)
return;
MONO_SEM_WAIT_UNITERRUPTIBLE (&info->suspend_semaphore);
THREADS_DEBUG ("self suspend IN COUNT %d\n", info->suspend_count);
g_assert (info->suspend_count == 0);
++info->suspend_count;
info->thread_state |= STATE_SELF_SUSPENDED;
ret = mono_threads_get_runtime_callbacks ()->thread_state_init_from_sigctx (&info->suspend_state, NULL);
g_assert (ret);
MONO_SEM_POST (&info->suspend_semaphore);
MONO_SEM_WAIT_UNITERRUPTIBLE (&info->resume_semaphore);
g_assert (!info->async_target); /*FIXME this should happen normally for suspend. */
MONO_SEM_POST (&info->finish_resume_semaphore);
}
示例3: mono_thread_info_resume
gboolean
mono_thread_info_resume (MonoNativeThreadId tid)
{
gboolean result = TRUE;
MonoThreadHazardPointers *hp = mono_hazard_pointer_get ();
MonoThreadInfo *info = mono_thread_info_lookup (tid); /*info on HP1*/
if (!info)
return FALSE;
MONO_SEM_WAIT_UNITERRUPTIBLE (&info->suspend_semaphore);
THREADS_DEBUG ("resume %x IN COUNT %d\n",tid, info->suspend_count);
if (info->suspend_count <= 0) {
MONO_SEM_POST (&info->suspend_semaphore);
mono_hazard_pointer_clear (hp, 1);
return FALSE;
}
/*
* The theory here is that if we manage to suspend the thread it means it did not
* start cleanup since it take the same lock.
*/
g_assert (mono_thread_info_get_tid (info));
if (--info->suspend_count == 0)
result = mono_thread_info_resume_internal (info);
MONO_SEM_POST (&info->suspend_semaphore);
mono_hazard_pointer_clear (hp, 1);
mono_atomic_store_release (&mono_thread_info_current ()->inside_critical_region, FALSE);
return result;
}
示例4: mono_thread_info_dettach
void
mono_thread_info_dettach (void)
{
MonoThreadInfo *info;
if (!mono_threads_inited)
{
/* This can happen from DllMain(THREAD_DETACH) on Windows, if a thread
* is created before an embedding API user initialized Mono. */
THREADS_DEBUG ("mono_thread_info_dettach called before mono_threads_init\n");
return;
}
info = mono_native_tls_get_value (thread_info_key);
if (info) {
THREADS_DEBUG ("detaching %p\n", info);
unregister_thread (info);
}
}
示例5: mono_thread_info_dettach
void
mono_thread_info_dettach (void)
{
MonoThreadInfo *info = mono_native_tls_get_value (thread_info_key);
if (info) {
THREADS_DEBUG ("detaching %p\n", info);
unregister_thread (info);
}
}
示例6: unregister_thread
static void
unregister_thread (void *arg)
{
MonoThreadInfo *info = (MonoThreadInfo *) arg;
int small_id = info->small_id;
g_assert (info);
THREADS_DEBUG ("unregistering info %p\n", info);
mono_native_tls_set_value (thread_exited_key, GUINT_TO_POINTER (1));
mono_threads_core_unregister (info);
/*
* TLS destruction order is not reliable so small_id might be cleaned up
* before us.
*/
#ifndef HAVE_KW_THREAD
mono_native_tls_set_value (small_id_key, GUINT_TO_POINTER (info->small_id + 1));
#endif
/*
First perform the callback that requires no locks.
This callback has the potential of taking other locks, so we do it before.
After it completes, the thread remains functional.
*/
if (threads_callbacks.thread_detach)
threads_callbacks.thread_detach (info);
/*
Since the thread info lock is taken from within blocking sections, we can't check from there, so it must be done here.
This ensures that we won't lose any suspend requests as a suspend initiator must hold the lock.
Once we're holding the suspend lock, no threads can suspend us and once we unregister, no thread can find us.
*/
MONO_PREPARE_BLOCKING
mono_thread_info_suspend_lock ();
MONO_FINISH_BLOCKING
/*
Now perform the callback that must be done under locks.
This will render the thread useless and non-suspendable, so it must
be done while holding the suspend lock to give no other thread chance
to suspend it.
*/
if (threads_callbacks.thread_unregister)
threads_callbacks.thread_unregister (info);
mono_threads_unregister_current_thread (info);
mono_threads_transition_detach (info);
mono_thread_info_suspend_unlock ();
/*now it's safe to free the thread info.*/
mono_thread_hazardous_free_or_queue (info, free_thread_info, TRUE, FALSE);
mono_thread_small_id_free (small_id);
}
示例7: mono_thread_info_remove
static gboolean
mono_thread_info_remove (MonoThreadInfo *info)
{
MonoThreadHazardPointers *hp = mono_hazard_pointer_get ();
gboolean res;
THREADS_DEBUG ("removing info %p\n", info);
res = mono_lls_remove (&thread_list, hp, (MonoLinkedListSetNode*)info);
mono_hazard_pointer_clear_all (hp, -1);
return res;
}
示例8: mono_thread_info_attach
MonoThreadInfo*
mono_thread_info_attach (void *baseptr)
{
MonoThreadInfo *info;
if (!mono_threads_inited)
{
/* This can happen from DllMain(DLL_THREAD_ATTACH) on Windows, if a
* thread is created before an embedding API user initialized Mono. */
THREADS_DEBUG ("mono_thread_info_attach called before mono_threads_init\n");
return NULL;
}
info = mono_native_tls_get_value (thread_info_key);
if (!info) {
info = g_malloc0 (thread_info_size);
THREADS_DEBUG ("attaching %p\n", info);
if (!register_thread (info, baseptr))
return NULL;
} else if (threads_callbacks.thread_attach) {
threads_callbacks.thread_attach (info);
}
return info;
}
示例9: mono_thread_info_attach
MonoThreadInfo*
mono_thread_info_attach (void *baseptr)
{
MonoThreadInfo *info = mono_native_tls_get_value (thread_info_key);
if (!info) {
info = g_malloc0 (thread_info_size);
THREADS_DEBUG ("attaching %p\n", info);
if (!register_thread (info, baseptr))
return NULL;
} else if (threads_callbacks.thread_attach) {
threads_callbacks.thread_attach (info);
}
return info;
}
示例10: unregister_thread
static void
unregister_thread (void *arg)
{
MonoThreadInfo *info = (MonoThreadInfo *) arg;
int small_id = info->small_id;
g_assert (info);
THREADS_DEBUG ("unregistering info %p\n", info);
mono_native_tls_set_value (thread_exited_key, GUINT_TO_POINTER (1));
mono_threads_core_unregister (info);
/*
* TLS destruction order is not reliable so small_id might be cleaned up
* before us.
*/
#ifndef HAVE_KW_THREAD
mono_native_tls_set_value (small_id_key, GUINT_TO_POINTER (info->small_id + 1));
#endif
/*
First perform the callback that requires no locks.
This callback has the potential of taking other locks, so we do it before.
After it completes, the thread remains functional.
*/
if (threads_callbacks.thread_detach)
threads_callbacks.thread_detach (info);
mono_thread_info_suspend_lock ();
/*
Now perform the callback that must be done under locks.
This will render the thread useless and non-suspendable, so it must
be done while holding the suspend lock to give no other thread chance
to suspend it.
*/
if (threads_callbacks.thread_unregister)
threads_callbacks.thread_unregister (info);
mono_threads_unregister_current_thread (info);
mono_threads_transition_detach (info);
mono_thread_info_suspend_unlock ();
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_small_id_free (small_id);
}
示例11: mono_thread_info_safe_suspend_sync
/*
WARNING:
If we are trying to suspend a target that is on a critical region
and running a syscall we risk looping forever if @interrupt_kernel is FALSE.
So, be VERY carefull in calling this with @interrupt_kernel == FALSE.
Info is not put on a hazard pointer as a suspended thread cannot exit and be freed.
This function MUST be matched with mono_thread_info_finish_suspend or mono_thread_info_finish_suspend_and_resume
*/
MonoThreadInfo*
mono_thread_info_safe_suspend_sync (MonoNativeThreadId id, gboolean interrupt_kernel)
{
MonoThreadInfo *info = NULL;
int sleep_duration = 0;
/*FIXME: unify this with self-suspend*/
g_assert (id != mono_native_thread_id_get ());
mono_thread_info_suspend_lock ();
for (;;) {
const char *suspend_error = "Unknown error";
if (!(info = mono_thread_info_suspend_sync (id, interrupt_kernel, &suspend_error))) {
g_warning ("failed to suspend thread %p due to %s, hopefully it is dead", (gpointer)id, suspend_error);
mono_thread_info_suspend_unlock ();
return NULL;
}
/*WARNING: We now are in interrupt context until we resume the thread. */
if (!is_thread_in_critical_region (info))
break;
if (!mono_thread_info_core_resume (info)) {
g_warning ("failed to resume thread %p, hopefully it is dead", (gpointer)id);
mono_hazard_pointer_clear (mono_hazard_pointer_get (), 1);
mono_thread_info_suspend_unlock ();
return NULL;
}
THREADS_DEBUG ("restarted thread %p\n", (gpointer)id);
if (!sleep_duration) {
#ifdef HOST_WIN32
SwitchToThread ();
#else
sched_yield ();
#endif
}
else {
g_usleep (sleep_duration);
}
sleep_duration += 10;
}
/* XXX this clears HP 1, so we restated it again */
mono_atomic_store_release (&mono_thread_info_current ()->inside_critical_region, TRUE);
mono_thread_info_suspend_unlock ();
return info;
}
示例12: mono_thread_info_safe_suspend_sync
/*
WARNING:
If we are trying to suspend a target that is on a critical region
and running a syscall we risk looping forever if @interrupt_kernel is FALSE.
So, be VERY carefull in calling this with @interrupt_kernel == FALSE.
*/
MonoThreadInfo*
mono_thread_info_safe_suspend_sync (MonoNativeThreadId id, gboolean interrupt_kernel)
{
MonoThreadInfo *info = NULL;
int sleep_duration = 0;
/*FIXME: unify this with self-suspend*/
g_assert (id != mono_native_thread_id_get ());
mono_thread_info_suspend_lock ();
for (;;) {
if (!(info = mono_thread_info_suspend_sync (id, interrupt_kernel))) {
g_warning ("failed to suspend thread %p, hopefully it is dead", (gpointer)id);
mono_thread_info_suspend_unlock ();
return NULL;
}
/*WARNING: We now are in interrupt context until we resume the thread. */
if (!is_thread_in_critical_region (info))
break;
if (!mono_thread_info_resume (id)) {
g_warning ("failed to result thread %p, hopefully it is dead", (gpointer)id);
mono_thread_info_suspend_unlock ();
return NULL;
}
THREADS_DEBUG ("restarted thread %p\n", (gpointer)id);
if (!sleep_duration) {
#ifdef HOST_WIN32
SwitchToThread ();
#else
sched_yield ();
#endif
}
else {
g_usleep (sleep_duration);
}
sleep_duration += 10;
}
mono_thread_info_suspend_unlock ();
return info;
}
示例13: mono_thread_info_suspend_sync
/*
The return value is only valid until a matching mono_thread_info_resume is called
*/
static MonoThreadInfo*
mono_thread_info_suspend_sync (MonoNativeThreadId tid, gboolean interrupt_kernel, const char **error_condition)
{
MonoThreadHazardPointers *hp = mono_hazard_pointer_get ();
MonoThreadInfo *info = mono_thread_info_lookup (tid); /*info on HP1*/
if (!info) {
*error_condition = "Thread not found";
return NULL;
}
MONO_SEM_WAIT_UNITERRUPTIBLE (&info->suspend_semaphore);
/*thread is on the process of detaching*/
if (mono_thread_info_run_state (info) > STATE_RUNNING) {
mono_hazard_pointer_clear (hp, 1);
*error_condition = "Thread is detaching";
return NULL;
}
THREADS_DEBUG ("suspend %x IN COUNT %d\n", tid, info->suspend_count);
if (info->suspend_count) {
++info->suspend_count;
mono_hazard_pointer_clear (hp, 1);
MONO_SEM_POST (&info->suspend_semaphore);
return info;
}
if (!mono_threads_core_suspend (info)) {
MONO_SEM_POST (&info->suspend_semaphore);
mono_hazard_pointer_clear (hp, 1);
*error_condition = "Could not suspend thread";
return NULL;
}
if (interrupt_kernel)
mono_threads_core_interrupt (info);
++info->suspend_count;
info->thread_state |= STATE_SUSPENDED;
MONO_SEM_POST (&info->suspend_semaphore);
return info;
}
示例14: mono_thread_info_core_resume
static gboolean
mono_thread_info_core_resume (MonoThreadInfo *info)
{
gboolean result;
MonoNativeThreadId tid = mono_thread_info_get_tid (info);
if (info->create_suspended) {
/* Have to special case this, as the normal suspend/resume pair are racy, they don't work if he resume is received before the suspend */
info->create_suspended = FALSE;
mono_threads_core_resume_created (info, tid);
return TRUE;
}
MONO_SEM_WAIT_UNITERRUPTIBLE (&info->suspend_semaphore);
THREADS_DEBUG ("resume %x IN COUNT %d\n", tid, info->suspend_count);
if (info->suspend_count <= 0) {
MONO_SEM_POST (&info->suspend_semaphore);
return FALSE;
}
/*
* The theory here is that if we manage to suspend the thread it means it did not
* start cleanup since it take the same lock.
*/
g_assert (mono_thread_info_get_tid (info));
if (--info->suspend_count == 0) {
if (mono_thread_info_suspend_state (info) == STATE_SELF_SUSPENDED) {
MONO_SEM_POST (&info->resume_semaphore);
MONO_SEM_WAIT_UNITERRUPTIBLE (&info->finish_resume_semaphore);
result = TRUE;
} else {
result = mono_threads_core_resume (info);
}
info->thread_state &= ~SUSPEND_STATE_MASK;
} else {
result = TRUE;
}
MONO_SEM_POST (&info->suspend_semaphore);
return result;
}
示例15: mono_thread_info_suspend_sync
/*
The return value is only valid until a matching mono_thread_info_resume is called
*/
static MonoThreadInfo*
mono_thread_info_suspend_sync (MonoNativeThreadId tid, gboolean interrupt_kernel)
{
MonoThreadHazardPointers *hp = mono_hazard_pointer_get ();
MonoThreadInfo *info = mono_thread_info_lookup (tid); /*info on HP1*/
if (!info)
return NULL;
EnterCriticalSection (&info->suspend_lock);
/*thread is on the process of detaching*/
if (mono_thread_info_run_state (info) > STATE_RUNNING) {
mono_hazard_pointer_clear (hp, 1);
return NULL;
}
THREADS_DEBUG ("suspend %x IN COUNT %d\n", tid, info->suspend_count);
if (info->suspend_count) {
++info->suspend_count;
mono_hazard_pointer_clear (hp, 1);
LeaveCriticalSection (&info->suspend_lock);
return info;
}
if (!mono_threads_core_suspend (info)) {
LeaveCriticalSection (&info->suspend_lock);
mono_hazard_pointer_clear (hp, 1);
return NULL;
}
if (interrupt_kernel)
mono_threads_core_interrupt (info);
++info->suspend_count;
info->thread_state |= STATE_SUSPENDED;
LeaveCriticalSection (&info->suspend_lock);
mono_hazard_pointer_clear (hp, 1);
return info;
}