diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2007-12-16 17:19:02 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2007-12-16 17:19:02 +0000 |
commit | cdbffbf376fd5974102bf7ad4ca6fdbc12043350 (patch) | |
tree | 822d8300fe6077d10779f4da08d46c3b54ba6452 | |
parent | b826e08294179e9b096f23098567b946f7e956bc (diff) |
Drop the event mutex around backtrace.
-rw-r--r-- | src/lwp.c | 21 |
1 files changed, 14 insertions, 7 deletions
@@ -664,16 +664,12 @@ _lwp_record_event (LWP_EventType type, const LWP_Event *ev) { static LWP_EventRecord events[N_EVENTS]; static guint n_events; - static guint depth; static gboolean _write_failed; + static __thread guint depth; gboolean lookup_allocator = TRUE; gboolean force_send = FALSE; - pthread_mutex_lock (&event_mutex); - if (depth++ || _write_failed) - goto unlock; - switch (type) { case LWP_INIT: force_send = TRUE; @@ -702,6 +698,10 @@ _lwp_record_event (LWP_EventType type, const LWP_Event *ev) break; } + pthread_mutex_lock (&event_mutex); + if (depth++ || _write_failed) + goto unlock; + if (! lookup_allocator) { events[n_events].allocator = 0; } else if (! _lwp_disable_stacktraces) { @@ -712,6 +712,9 @@ _lwp_record_event (LWP_EventType type, const LWP_Event *ev) if (max_ips > _lwp_num_callers) max_ips = _lwp_num_callers; + /* drop the mutex to avoid a deadlock with dl */ + pthread_mutex_unlock (&event_mutex); + ips = stack_ips; n_ips = backtrace (ips, max_ips); while (n_ips == max_ips && max_ips < _lwp_num_callers) { @@ -725,12 +728,16 @@ _lwp_record_event (LWP_EventType type, const LWP_Event *ev) n_ips = backtrace (ips, max_ips); } + pthread_mutex_lock (&event_mutex); + if (_write_failed) /* need to recheck after acquiring mutex */ + goto unlock; + if (G_UNLIKELY (n_ips + n_pending_symbols > G_MAXUSHORT)) { _write_failed = ! _lwp_write_events (events, n_events); + n_events = 0; + if (_write_failed) goto unlock; - - n_events = 0; } events[n_events].allocator = _lwp_add_allocator (ips+1, n_ips-1); |