gboolean mono_profiler_should_instrument_method (MonoMethod *method, gboolean entry);
gboolean mono_profiler_sampling_enabled (void);
-void mono_profiler_sampling_thread_sleep (void);
+void mono_profiler_sampling_thread_post (void);
+void mono_profiler_sampling_thread_wait (void);
static inline gboolean
mono_profiler_allocations_enabled (void)
mono_profiler_state.sample_mode = mode;
mono_profiler_state.sample_freq = freq;
- mono_os_sem_post (&mono_profiler_state.sampling_semaphore);
+ mono_profiler_sampling_thread_post ();
return TRUE;
}
}
void
-mono_profiler_sampling_thread_sleep (void)
+mono_profiler_sampling_thread_post (void)
+{
+ mono_os_sem_post (&mono_profiler_state.sampling_semaphore);
+}
+
+void
+mono_profiler_sampling_thread_wait (void)
{
mono_os_sem_wait (&mono_profiler_state.sampling_semaphore, MONO_SEM_FLAGS_NONE);
}
mono_profiler_get_sample_mode (NULL, &mode, NULL);
if (mode == MONO_PROFILER_SAMPLE_MODE_NONE) {
- mono_profiler_sampling_thread_sleep ();
+ mono_profiler_sampling_thread_wait ();
+
+ if (!InterlockedRead (&sampling_thread_running))
+ goto done;
+
goto init;
}
} FOREACH_THREAD_SAFE_END
}
- InterlockedWrite (&sampling_thread_exiting, 1);
-
clock_cleanup ();
+done:
+ InterlockedWrite (&sampling_thread_exiting, 1);
+
pthread_setschedparam (pthread_self (), old_policy, &old_sched);
mono_thread_info_detach ();
{
InterlockedWrite (&sampling_thread_running, 0);
+ mono_profiler_sampling_thread_post ();
+
#ifndef PLATFORM_MACOSX
/*
* There is a slight problem when we're using CLOCK_PROCESS_CPUTIME_ID: If