summaryrefslogtreecommitdiff
path: root/cpp/src/slice2py/Main.cpp
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2008-11-20 10:22:31 -0330
committerDwayne Boone <dwayne@zeroc.com>2008-11-20 10:22:31 -0330
commitaa4f3340e17e227a26659a75a8f60d24c2dd5323 (patch)
treec118d1d651d48f236c911d25f8a3f3b34320783f /cpp/src/slice2py/Main.cpp
parentBug 3550 - slice compiler not able to open tmp file on Vista (diff)
downloadice-aa4f3340e17e227a26659a75a8f60d24c2dd5323.tar.bz2
ice-aa4f3340e17e227a26659a75a8f60d24c2dd5323.tar.xz
ice-aa4f3340e17e227a26659a75a8f60d24c2dd5323.zip
Refactored CtrlCHandler usage in slice compilers
Diffstat (limited to 'cpp/src/slice2py/Main.cpp')
-rw-r--r--cpp/src/slice2py/Main.cpp48
1 files changed, 27 insertions, 21 deletions
diff --git a/cpp/src/slice2py/Main.cpp b/cpp/src/slice2py/Main.cpp
index fcae12e5e5e..0084e68b549 100644
--- a/cpp/src/slice2py/Main.cpp
+++ b/cpp/src/slice2py/Main.cpp
@@ -12,9 +12,9 @@
#include <IceUtil/Options.h>
#include <IceUtil/StringUtil.h>
#include <IceUtil/CtrlCHandler.h>
+#include <IceUtil/StaticMutex.h>
#include <Slice/Preprocessor.h>
#include <Slice/PythonUtil.h>
-#include <Slice/SignalHandler.h>
#include <cstring>
#include <fstream>
@@ -34,14 +34,15 @@ using namespace std;
using namespace Slice;
using namespace Slice::Python;
-//
-// Callback for Crtl-C signal handling
-//
-static IceUtilInternal::Output _out;
+static IceUtil::StaticMutex _mutex = ICE_STATIC_MUTEX_INITIALIZER;
+static bool _interrupted = false;
-static void closeCallback()
+void
+interruptedCallback(int signal)
{
- _out.close();
+ IceUtil::StaticMutex::Lock lock(_mutex);
+
+ _interrupted = true;
}
//
@@ -486,12 +487,11 @@ main(int argc, char* argv[])
int status = EXIT_SUCCESS;
+ IceUtil::CtrlCHandler ctrlCHandler;
+ ctrlCHandler.setCallback(interruptedCallback);
+
for(i = args.begin(); i != args.end(); ++i)
{
- SignalHandler::clearCleanupFileList();
- IceUtil::CtrlCHandler ctrlCHandler;
- ctrlCHandler.setCallback(SignalHandler::removeFilesOnInterrupt);
-
Preprocessor icecpp(argv[0], *i, cppArgs);
FILE* cppHandle = icecpp.preprocess(false);
@@ -551,27 +551,24 @@ main(int argc, char* argv[])
file = output + '/' + file;
}
- SignalHandler::setCloseCallback(closeCallback);
-
- SignalHandler::addFileForCleanup(file);
- _out.open(file.c_str());
- if(!_out)
+ IceUtilInternal::Output out;
+ out.open(file.c_str());
+ if(!out)
{
cerr << argv[0] << ": can't open `" << file << "' for writing" << endl;
u->destroy();
return EXIT_FAILURE;
}
- printHeader(_out);
- _out << "\n# Generated from file `" << base << ".ice'\n";
+ printHeader(out);
+ out << "\n# Generated from file `" << base << ".ice'\n";
//
// Generate the Python mapping.
//
- generate(u, all, checksum, includePaths, _out);
+ generate(u, all, checksum, includePaths, out);
- _out.close();
- SignalHandler::setCloseCallback(0);
+ out.close();
//
// Create or update the Python package hierarchy.
@@ -586,6 +583,15 @@ main(int argc, char* argv[])
u->destroy();
}
+
+ {
+ IceUtil::StaticMutex::Lock lock(_mutex);
+
+ if(_interrupted)
+ {
+ return EXIT_FAILURE;
+ }
+ }
}
return status;