static int noshm_sem_trylock (int sem) { int ret; DEBUGLOG ("%s: trying to lock nosem %d", __func__, sem); ret = mono_os_mutex_trylock (&noshm_sems[sem]); return ret; }
GrayQueueSection* sgen_gray_object_steal_section (SgenGrayQueue *queue) { gint32 sections_remaining; GrayQueueSection *section = NULL; /* * With each push/pop into the queue we increment the number of sections. * There is only one thread accessing the top (the owner) and potentially * multiple workers trying to steal sections from the bottom, so we need * to lock. A num sections decrement from the owner means that the first * section is reserved, while a decrement by the stealer means that the * last section is reserved. If after we decrement the num sections, we * have at least one more section present, it means we can't race with * the other thread. If this is not the case the steal end abandons the * pop, setting back the num_sections, while the owner end will take a * lock to make sure we are not racing with the stealer (since the stealer * might have popped an entry and be in the process of updating the entry * that the owner is trying to pop. */ if (queue->num_sections <= 1) return NULL; /* Give up if there is contention on the last section */ if (mono_os_mutex_trylock (&queue->steal_mutex) != 0) return NULL; sections_remaining = mono_atomic_dec_i32 (&queue->num_sections); if (sections_remaining <= 0) { /* The section that we tried to steal might be the head of the queue. */ mono_atomic_inc_i32 (&queue->num_sections); } else { /* We have reserved for us the tail section of the queue */ section = queue->last; SGEN_ASSERT (0, section, "Why we don't have any sections to steal?"); SGEN_ASSERT (0, !section->next, "Why aren't we stealing the tail?"); queue->last = section->prev; section->prev = NULL; SGEN_ASSERT (0, queue->last, "Why are we stealing the last section?"); queue->last->next = NULL; STATE_TRANSITION (section, GRAY_QUEUE_SECTION_STATE_ENQUEUED, GRAY_QUEUE_SECTION_STATE_FLOATING); } mono_os_mutex_unlock (&queue->steal_mutex); return section; }
int mono_w32handle_trylock_handle (gpointer handle) { MonoW32HandleBase *handle_data; int ret; #ifdef DEBUG g_message ("%s: locking handle %p", __func__, handle); #endif if (!mono_w32handle_lookup_data (handle, &handle_data)) { return(0); } mono_w32handle_ref (handle); ret = mono_os_mutex_trylock (&handle_data->signal_mutex); if (ret != 0) { mono_w32handle_unref (handle); } return(ret); }