Inline mono_thread_interruption_request_flag. (mono/mono#16906)
authorJay Krell <jaykrell@microsoft.com>
Thu, 19 Sep 2019 20:49:43 +0000 (13:49 -0700)
committerLarry Ewing <lewing@microsoft.com>
Thu, 19 Sep 2019 20:49:43 +0000 (15:49 -0500)
Note that the name mono_thread_interruption_request without trailing flag
was already taken.

Commit migrated from https://github.com/mono/mono/commit/d02c121f79507132f56527ba1338f8186b66dd46

src/mono/mono/metadata/threads-types.h
src/mono/mono/metadata/threads.c
src/mono/mono/mini/interp/interp.c
src/mono/mono/mini/interp/transform.c
src/mono/mono/mini/mini-runtime.c

index f692e5b..6ae27f7 100644 (file)
@@ -382,7 +382,17 @@ MonoExceptionHandle
 mono_thread_interruption_checkpoint_handle (void);
 
 MonoException* mono_thread_force_interruption_checkpoint_noraise (void);
-gint32* mono_thread_interruption_request_flag (void);
+
+/**
+ * mono_thread_interruption_request_flag:
+ *
+ * Returns the address of a flag that will be non-zero if an interruption has
+ * been requested for a thread. The thread to interrupt may not be the current
+ * thread, so an additional call to mono_thread_interruption_requested () or
+ * mono_thread_interruption_checkpoint () is always needed if the flag is not
+ * zero.
+ */
+extern gint32 mono_thread_interruption_request_flag;
 
 uint32_t mono_alloc_special_static_data (uint32_t static_type, uint32_t size, uint32_t align, uintptr_t *bitmap, int numbits);
 void*    mono_get_special_static_data   (uint32_t offset);
index af2d5db..374c52f 100644 (file)
@@ -242,7 +242,7 @@ static mono_mutex_t interlocked_mutex;
 #endif
 
 /* global count of thread interruptions requested */
-static gint32 thread_interruption_requested = 0;
+gint32 mono_thread_interruption_request_flag;
 
 /* Event signaled when a thread changes its background mode */
 static MonoOSEvent background_change_event;
@@ -321,12 +321,12 @@ mono_threads_begin_abort_protected_block (void)
 
        /* Defer async request since we won't be able to process until exiting the block */
        if (new_val == 1 && (new_state & INTERRUPT_ASYNC_REQUESTED_BIT)) {
-               mono_atomic_dec_i32 (&thread_interruption_requested);
-               THREADS_INTERRUPT_DEBUG ("[%d] begin abort protected block old_state %ld new_state %ld, defer tir %d\n", thread->small_id, old_state, new_state, thread_interruption_requested);
-               if (thread_interruption_requested < 0)
-                       g_warning ("bad thread_interruption_requested state");
+               mono_atomic_dec_i32 (&mono_thread_interruption_request_flag);
+               THREADS_INTERRUPT_DEBUG ("[%d] begin abort protected block old_state %ld new_state %ld, defer tir %d\n", thread->small_id, old_state, new_state, mono_thread_interruption_request_flag);
+               if (mono_thread_interruption_request_flag < 0)
+                       g_warning ("bad mono_thread_interruption_request_flag state");
        } else {
-               THREADS_INTERRUPT_DEBUG ("[%d] begin abort protected block old_state %ld new_state %ld, tir %d\n", thread->small_id, old_state, new_state, thread_interruption_requested);
+               THREADS_INTERRUPT_DEBUG ("[%d] begin abort protected block old_state %ld new_state %ld, tir %d\n", thread->small_id, old_state, new_state, mono_thread_interruption_request_flag);
        }
 }
 
@@ -362,10 +362,10 @@ mono_threads_end_abort_protected_block (void)
        } while (mono_atomic_cas_ptr ((volatile gpointer *)&thread->thread_state, (gpointer)new_state, (gpointer)old_state) != (gpointer)old_state);
 
        if (new_val == 0 && (new_state & INTERRUPT_ASYNC_REQUESTED_BIT)) {
-               mono_atomic_inc_i32 (&thread_interruption_requested);
-               THREADS_INTERRUPT_DEBUG ("[%d] end abort protected block old_state %ld new_state %ld, restore tir %d\n", thread->small_id, old_state, new_state, thread_interruption_requested);
+               mono_atomic_inc_i32 (&mono_thread_interruption_request_flag);
+               THREADS_INTERRUPT_DEBUG ("[%d] end abort protected block old_state %ld new_state %ld, restore tir %d\n", thread->small_id, old_state, new_state, mono_thread_interruption_request_flag);
        } else {
-               THREADS_INTERRUPT_DEBUG ("[%d] end abort protected block old_state %ld new_state %ld, tir %d\n", thread->small_id, old_state, new_state, thread_interruption_requested);
+               THREADS_INTERRUPT_DEBUG ("[%d] end abort protected block old_state %ld new_state %ld, tir %d\n", thread->small_id, old_state, new_state, mono_thread_interruption_request_flag);
        }
 
        return mono_thread_state_has_interruption (new_state);
@@ -401,10 +401,10 @@ mono_thread_clear_interruption_requested (MonoInternalThread *thread)
                        new_state = old_state & ~INTERRUPT_ASYNC_REQUESTED_BIT;
        } while (mono_atomic_cas_ptr ((volatile gpointer *)&thread->thread_state, (gpointer)new_state, (gpointer)old_state) != (gpointer)old_state);
 
-       mono_atomic_dec_i32 (&thread_interruption_requested);
-       THREADS_INTERRUPT_DEBUG ("[%d] clear interruption old_state %ld new_state %ld, tir %d\n", thread->small_id, old_state, new_state, thread_interruption_requested);
-       if (thread_interruption_requested < 0)
-               g_warning ("bad thread_interruption_requested state");
+       mono_atomic_dec_i32 (&mono_thread_interruption_request_flag);
+       THREADS_INTERRUPT_DEBUG ("[%d] clear interruption old_state %ld new_state %ld, tir %d\n", thread->small_id, old_state, new_state, mono_thread_interruption_request_flag);
+       if (mono_thread_interruption_request_flag < 0)
+               g_warning ("bad mono_thread_interruption_request_flag state");
        return TRUE;
 }
 
@@ -461,10 +461,10 @@ mono_thread_set_interruption_requested_flags (MonoInternalThread *thread, gboole
        } while (mono_atomic_cas_ptr ((volatile gpointer *)&thread->thread_state, (gpointer)new_state, (gpointer)old_state) != (gpointer)old_state);
 
        if (sync || !(new_state & ABORT_PROT_BLOCK_MASK)) {
-               mono_atomic_inc_i32 (&thread_interruption_requested);
-               THREADS_INTERRUPT_DEBUG ("[%d] set interruption on [%d] old_state %ld new_state %ld, tir %d\n", mono_thread_internal_current ()->small_id, thread->small_id, old_state, new_state, thread_interruption_requested);
+               mono_atomic_inc_i32 (&mono_thread_interruption_request_flag);
+               THREADS_INTERRUPT_DEBUG ("[%d] set interruption on [%d] old_state %ld new_state %ld, tir %d\n", mono_thread_internal_current ()->small_id, thread->small_id, old_state, new_state, mono_thread_interruption_request_flag);
        } else {
-               THREADS_INTERRUPT_DEBUG ("[%d] set interruption on [%d] old_state %ld new_state %ld, tir deferred %d\n", mono_thread_internal_current ()->small_id, thread->small_id, old_state, new_state, thread_interruption_requested);
+               THREADS_INTERRUPT_DEBUG ("[%d] set interruption on [%d] old_state %ld new_state %ld, tir deferred %d\n", mono_thread_internal_current ()->small_id, thread->small_id, old_state, new_state, mono_thread_interruption_request_flag);
        }
 
        return sync || !(new_state & ABORT_PROT_BLOCK_MASK);
@@ -5118,7 +5118,7 @@ mono_thread_resume_interruption (gboolean exec)
 gboolean
 mono_thread_interruption_requested (void)
 {
-       if (thread_interruption_requested) {
+       if (mono_thread_interruption_request_flag) {
                MonoInternalThread *thread = mono_thread_internal_current ();
                /* The thread may already be stopping */
                if (thread != NULL) 
@@ -5250,21 +5250,6 @@ mono_set_pending_exception_handle (MonoExceptionHandle exc)
        mono_thread_request_interruption_native ();
 }
 
-/**
- * mono_thread_interruption_request_flag:
- *
- * Returns the address of a flag that will be non-zero if an interruption has
- * been requested for a thread. The thread to interrupt may not be the current
- * thread, so an additional call to mono_thread_interruption_requested() or
- * mono_thread_interruption_checkpoint() is allways needed if the flag is not
- * zero.
- */
-gint32*
-mono_thread_interruption_request_flag (void)
-{
-       return &thread_interruption_requested;
-}
-
 void 
 mono_thread_init_apartment_state (void)
 {
index b2af948..b41d4ca 100644 (file)
@@ -937,7 +937,7 @@ interp_throw (ThreadContext *context, MonoException *ex, InterpFrame *frame, con
 
 #define EXCEPTION_CHECKPOINT   \
        do {                                                                            \
-               if (*mono_thread_interruption_request_flag () && !mono_threads_is_critical_method (frame->imethod->method)) { \
+               if (mono_thread_interruption_request_flag && !mono_threads_is_critical_method (frame->imethod->method)) { \
                        MonoException *exc = mono_thread_interruption_checkpoint ();    \
                        if (exc)                                                        \
                                THROW_EX (exc, ip);                                     \
@@ -947,7 +947,7 @@ interp_throw (ThreadContext *context, MonoException *ex, InterpFrame *frame, con
 
 #define EXCEPTION_CHECKPOINT_IN_HELPER_FUNCTION        \
        do {                                                                            \
-               if (*mono_thread_interruption_request_flag () && !mono_threads_is_critical_method (frame->imethod->method)) { \
+               if (mono_thread_interruption_request_flag && !mono_threads_is_critical_method (frame->imethod->method)) { \
                        MonoException *exc = mono_thread_interruption_checkpoint ();    \
                        if (exc)                                                        \
                                return exc;                                             \
index 974dba9..20158df 100644 (file)
@@ -5630,7 +5630,7 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header,
                                break;
                        case CEE_MONO_LDPTR_INT_REQ_FLAG:
                                interp_add_ins (td, MINT_MONO_LDPTR);
-                               td->last_ins->data [0] = get_data_item_index (td, mono_thread_interruption_request_flag ());
+                               td->last_ins->data [0] = get_data_item_index (td, &mono_thread_interruption_request_flag);
                                PUSH_TYPE (td, STACK_TYPE_MP, NULL);
                                ++td->ip;
                                break;
index f85736d..c991aa2 100644 (file)
@@ -1571,7 +1571,7 @@ mono_resolve_patch_target (MonoMethod *method, MonoDomain *domain, guint8 *code,
                }
                break;
        case MONO_PATCH_INFO_INTERRUPTION_REQUEST_FLAG:
-               target = mono_thread_interruption_request_flag ();
+               target = &mono_thread_interruption_request_flag;
                break;
        case MONO_PATCH_INFO_METHOD_RGCTX:
                target = mini_method_get_rgctx (patch_info->data.method);