From bc794e3807e988b1bf552f203bedcda465875f02 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 23 Nov 2015 11:01:47 +0000 Subject: [PATCH] Refactored the signal handling to be thread safe --- applications/osgfilecache/osgfilecache.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/applications/osgfilecache/osgfilecache.cpp b/applications/osgfilecache/osgfilecache.cpp index ceadad4fa..0379198db 100644 --- a/applications/osgfilecache/osgfilecache.cpp +++ b/applications/osgfilecache/osgfilecache.cpp @@ -32,7 +32,10 @@ #include #include -static bool s_ExitApplication = false; +#include + +static OpenThreads::Atomic s_ExitApplication; +static OpenThreads::Atomic s_SigValue; struct Extents { @@ -383,8 +386,8 @@ protected: static void signalHandler(int sig) { - printf("\nCaught signal %d, requesting exit...\n\n",sig); - s_ExitApplication = true; + s_SigValue.exchange(sig); + s_ExitApplication.exchange(1); } int main( int argc, char **argv ) @@ -483,7 +486,7 @@ int main( int argc, char **argv ) if (s_ExitApplication) { - std::cout<<"osgfilecache cleanly exited in response to signal."<