| 122 | } |
| 123 | |
| 124 | BackTrace TraceResolver::getBackTrace(std::string thread_name, std::thread::native_handle_type thread_handle) { |
| 125 | // lock so that we only perform one backtrace at a time. |
| 126 | #ifdef HAS_EXECINFO |
| 127 | std::lock_guard<std::mutex> lock(mutex_); |
| 128 | trace_ = BackTrace(std::move(thread_name)); |
| 129 | |
| 130 | if (0 == thread_handle || pthread_equal(pthread_self(), thread_handle)) { |
| 131 | pull_trace(); |
| 132 | } else { |
| 133 | if (thread_handle == 0) { |
| 134 | return std::move(trace_); |
| 135 | } |
| 136 | emplace_handler(); |
| 137 | std::unique_lock<std::mutex> ulock(trace_mutex_); |
| 138 | if (pthread_kill(thread_handle, SIGUSR2) != 0) { |
| 139 | return std::move(trace_); |
| 140 | } |
| 141 | pull_traces_ = false; |
| 142 | trace_condition_.wait(ulock, [this] { return pull_traces_; }); |
| 143 | } |
| 144 | #else |
| 145 | // even if tracing is disabled, include thread name into the trace object |
| 146 | trace_ = BackTrace(std::move(thread_name)); |
| 147 | #endif |
| 148 | return std::move(trace_); |
| 149 | } |
| 150 | #ifdef HAS_EXECINFO |
| 151 | void handler(int /*signr*/, siginfo_t* /*info*/, void* /*secret*/) { |
| 152 | std::unique_lock<std::mutex> lock(TraceResolver::getResolver().lock()); |
no test coverage detected