Skip to content
Snippets Groups Projects
Commit 220dfce6 authored by Eric Cano's avatar Eric Cano
Browse files

Protected the apparently racy glibc's backtrace (detected in an helgrind run on TeamCity).

parent c395e8b5
No related branches found
No related tags found
No related merge requests found
......@@ -31,7 +31,9 @@
castor::exception::Backtrace::Backtrace(): m_trace() {
void * array[200];
size_t depth = ::backtrace(array, sizeof(array)/sizeof(void*));
g_lock.lock();
char ** strings = ::backtrace_symbols(array, depth);
g_lock.unlock();
if (!strings)
m_trace = "";
else {
......@@ -66,3 +68,5 @@ castor::exception::Backtrace::Backtrace(): m_trace() {
}
}
/* Implementation of the singleton lock */
castor::exception::Backtrace::mutex castor::exception::Backtrace::g_lock;
......@@ -23,6 +23,7 @@
#pragma once
#include <string>
#include <pthread.h>
namespace castor {
namespace exception {
......@@ -33,6 +34,20 @@ namespace castor {
Backtrace& operator= (const Backtrace& bt) { m_trace = bt.m_trace; return *this; }
private:
std::string m_trace;
/**
* Singleton lock around the apparently racy backtrace().
* We write it with no error check as it's used only here.
* We need a class in order to have a constructor for the global object.
*/
class mutex {
public:
mutex() { pthread_mutex_init(&m_mutex, NULL); }
void lock() { pthread_mutex_lock(&m_mutex); }
void unlock() { pthread_mutex_unlock(&m_mutex); }
private:
pthread_mutex_t m_mutex;
};
static mutex g_lock;
};
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment