|
@@ -40,28 +40,9 @@
|
|
* Trace records are written out by a dedicated thread. The thread waits for
|
|
* Trace records are written out by a dedicated thread. The thread waits for
|
|
* records to become available, writes them out, and then waits again.
|
|
* records to become available, writes them out, and then waits again.
|
|
*/
|
|
*/
|
|
-#if GLIB_CHECK_VERSION(2, 32, 0)
|
|
|
|
-static GMutex trace_lock;
|
|
|
|
-#define lock_trace_lock() g_mutex_lock(&trace_lock)
|
|
|
|
-#define unlock_trace_lock() g_mutex_unlock(&trace_lock)
|
|
|
|
-#define get_trace_lock_mutex() (&trace_lock)
|
|
|
|
-#else
|
|
|
|
-static GStaticMutex trace_lock = G_STATIC_MUTEX_INIT;
|
|
|
|
-#define lock_trace_lock() g_static_mutex_lock(&trace_lock)
|
|
|
|
-#define unlock_trace_lock() g_static_mutex_unlock(&trace_lock)
|
|
|
|
-#define get_trace_lock_mutex() g_static_mutex_get_mutex(&trace_lock)
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
-/* g_cond_new() was deprecated in glib 2.31 but we still need to support it */
|
|
|
|
-#if GLIB_CHECK_VERSION(2, 31, 0)
|
|
|
|
-static GCond the_trace_available_cond;
|
|
|
|
-static GCond the_trace_empty_cond;
|
|
|
|
-static GCond *trace_available_cond = &the_trace_available_cond;
|
|
|
|
-static GCond *trace_empty_cond = &the_trace_empty_cond;
|
|
|
|
-#else
|
|
|
|
-static GCond *trace_available_cond;
|
|
|
|
-static GCond *trace_empty_cond;
|
|
|
|
-#endif
|
|
|
|
|
|
+static CompatGMutex trace_lock;
|
|
|
|
+static CompatGCond trace_available_cond;
|
|
|
|
+static CompatGCond trace_empty_cond;
|
|
|
|
|
|
static bool trace_available;
|
|
static bool trace_available;
|
|
static bool trace_writeout_enabled;
|
|
static bool trace_writeout_enabled;
|
|
@@ -151,26 +132,26 @@ static bool get_trace_record(unsigned int idx, TraceRecord **recordptr)
|
|
*/
|
|
*/
|
|
static void flush_trace_file(bool wait)
|
|
static void flush_trace_file(bool wait)
|
|
{
|
|
{
|
|
- lock_trace_lock();
|
|
|
|
|
|
+ g_mutex_lock(&trace_lock);
|
|
trace_available = true;
|
|
trace_available = true;
|
|
- g_cond_signal(trace_available_cond);
|
|
|
|
|
|
+ g_cond_signal(&trace_available_cond);
|
|
|
|
|
|
if (wait) {
|
|
if (wait) {
|
|
- g_cond_wait(trace_empty_cond, get_trace_lock_mutex());
|
|
|
|
|
|
+ g_cond_wait(&trace_empty_cond, &trace_lock);
|
|
}
|
|
}
|
|
|
|
|
|
- unlock_trace_lock();
|
|
|
|
|
|
+ g_mutex_unlock(&trace_lock);
|
|
}
|
|
}
|
|
|
|
|
|
static void wait_for_trace_records_available(void)
|
|
static void wait_for_trace_records_available(void)
|
|
{
|
|
{
|
|
- lock_trace_lock();
|
|
|
|
|
|
+ g_mutex_lock(&trace_lock);
|
|
while (!(trace_available && trace_writeout_enabled)) {
|
|
while (!(trace_available && trace_writeout_enabled)) {
|
|
- g_cond_signal(trace_empty_cond);
|
|
|
|
- g_cond_wait(trace_available_cond, get_trace_lock_mutex());
|
|
|
|
|
|
+ g_cond_signal(&trace_empty_cond);
|
|
|
|
+ g_cond_wait(&trace_available_cond, &trace_lock);
|
|
}
|
|
}
|
|
trace_available = false;
|
|
trace_available = false;
|
|
- unlock_trace_lock();
|
|
|
|
|
|
+ g_mutex_unlock(&trace_lock);
|
|
}
|
|
}
|
|
|
|
|
|
static gpointer writeout_thread(gpointer opaque)
|
|
static gpointer writeout_thread(gpointer opaque)
|
|
@@ -383,11 +364,7 @@ static GThread *trace_thread_create(GThreadFunc fn)
|
|
pthread_sigmask(SIG_SETMASK, &set, &oldset);
|
|
pthread_sigmask(SIG_SETMASK, &set, &oldset);
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-#if GLIB_CHECK_VERSION(2, 31, 0)
|
|
|
|
thread = g_thread_new("trace-thread", fn, NULL);
|
|
thread = g_thread_new("trace-thread", fn, NULL);
|
|
-#else
|
|
|
|
- thread = g_thread_create(fn, NULL, FALSE, NULL);
|
|
|
|
-#endif
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
#ifndef _WIN32
|
|
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
|
|
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
|
|
@@ -402,11 +379,6 @@ bool st_init(const char *file)
|
|
|
|
|
|
trace_pid = getpid();
|
|
trace_pid = getpid();
|
|
|
|
|
|
-#if !GLIB_CHECK_VERSION(2, 31, 0)
|
|
|
|
- trace_available_cond = g_cond_new();
|
|
|
|
- trace_empty_cond = g_cond_new();
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
thread = trace_thread_create(writeout_thread);
|
|
thread = trace_thread_create(writeout_thread);
|
|
if (!thread) {
|
|
if (!thread) {
|
|
fprintf(stderr, "warning: unable to initialize simple trace backend\n");
|
|
fprintf(stderr, "warning: unable to initialize simple trace backend\n");
|