From dc596951dd60b1f219494f0e7ef3e1d75f7a8ad6 Mon Sep 17 00:00:00 2001 From: Jim Chen Date: Tue, 19 May 2015 11:27:18 -0400 Subject: [PATCH] Bug 1163135 - Make it safer to start the profiler via signal; r=snorp --- tools/profiler/platform-linux.cc | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tools/profiler/platform-linux.cc b/tools/profiler/platform-linux.cc index 5958d423c83d..e45798c0f549 100644 --- a/tools/profiler/platform-linux.cc +++ b/tools/profiler/platform-linux.cc @@ -646,11 +646,7 @@ static void ReadProfilerVars(const char* fileName, const char** features, } } - -static void StartSignalHandler(int signal, siginfo_t* info, void* context) { - // XXX: Everything we do here is NOT async signal safe. We risk nasty things - // like deadlocks but we typically only do this once so it tends to be ok. - // See bug 909403 +static void DoStartTask() { uint32_t featureCount = 0; uint32_t threadCount = 0; @@ -674,6 +670,20 @@ static void StartSignalHandler(int signal, siginfo_t* info, void* context) { freeArray(features, featureCount); } +static void StartSignalHandler(int signal, siginfo_t* info, void* context) { + class StartTask : public nsRunnable { + public: + NS_IMETHOD Run() { + DoStartTask(); + return NS_OK; + } + }; + // XXX: technically NS_DispatchToMainThread is NOT async signal safe. We risk + // nasty things like deadlocks, but the probability is very low and we + // typically only do this once so it tends to be ok. See bug 909403. + NS_DispatchToMainThread(new StartTask()); +} + void OS::Startup() { LOG("Registering start signal");