[geos-commits] r3642 - in trunk: capi include/geos/util src/util

svn_geos at osgeo.org svn_geos at osgeo.org
Fri May 25 06:54:38 EDT 2012


Author: strk
Date: 2012-05-25 03:54:37 -0700 (Fri, 25 May 2012)
New Revision: 3642

Added:
   trunk/include/geos/util/Interrupt.h
   trunk/src/util/Interrupt.cpp
Modified:
   trunk/capi/geos_c.cpp
   trunk/capi/geos_c.h.in
   trunk/include/geos/util/Makefile.am
   trunk/src/util/Makefile.am
Log:
Initial support for an explicit mechanism to request interruption

This commit provides a GEOS_CHECK_FOR_INTERRUPTS macro for internal
use but adds no users.

Early tests shows that registering a SIGINT handler is an effective
way to request interruption of running GEOS operations.

Modified: trunk/capi/geos_c.cpp
===================================================================
--- trunk/capi/geos_c.cpp	2012-05-24 06:00:52 UTC (rev 3641)
+++ trunk/capi/geos_c.cpp	2012-05-25 10:54:37 UTC (rev 3642)
@@ -25,6 +25,7 @@
 #include <geos/operation/overlay/OverlayOp.h>
 #include <geos/operation/union/CascadedPolygonUnion.h>
 #include <geos/algorithm/distance/DiscreteHausdorffDistance.h>
+#include <geos/util/Interrupt.h>
 
 #include <stdexcept>
 #include <new>
@@ -112,6 +113,12 @@
     }
 }
 
+void
+GEOS_requestInterruption()
+{
+  geos::util::Interrupt::request();
+}
+
 void 
 GEOSFree (void* buffer) 
 { 

Modified: trunk/capi/geos_c.h.in
===================================================================
--- trunk/capi/geos_c.h.in	2012-05-24 06:00:52 UTC (rev 3641)
+++ trunk/capi/geos_c.h.in	2012-05-25 10:54:37 UTC (rev 3642)
@@ -154,7 +154,10 @@
 extern GEOSAllocator GEOS_DLL GEOS_setAllocator(GEOSAllocator nf);
 extern GEOSDeallocator GEOS_DLL GEOS_setDeallocator(GEOSDeallocator nf);
 
+/* Request safe interruption of operations */
+extern void GEOS_DLL GEOS_requestInterruption();
 
+
 extern GEOSContextHandle_t GEOS_DLL initGEOS_r(
                                     GEOSMessageHandler notice_function,
                                     GEOSMessageHandler error_function);

Added: trunk/include/geos/util/Interrupt.h
===================================================================
--- trunk/include/geos/util/Interrupt.h	                        (rev 0)
+++ trunk/include/geos/util/Interrupt.h	2012-05-25 10:54:37 UTC (rev 3642)
@@ -0,0 +1,53 @@
+/**********************************************************************
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.osgeo.org
+ *
+ * Copyright (C) 2012 Sandro Santilli <strk at keybit.net>
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation. 
+ * See the COPYING file for more information.
+ *
+ **********************************************************************/
+
+#ifndef GEOS_UTIL_INTERRUPT_H
+#define GEOS_UTIL_INTERRUPT_H
+
+#include <geos/export.h>
+
+namespace geos {
+namespace util { // geos::util
+
+#define GEOS_CHECK_FOR_INTERRUPTS() geos::util::Interrupt::process()
+
+class GEOS_DLL Interrupt {
+
+public:
+
+  static void request() { requested = true; }
+
+  static bool check() { return requested; }
+
+  static void process() {
+    if ( requested ) {
+      requested = false;
+      interrupt();
+    }
+  }
+
+  static void interrupt();
+
+private:
+
+  static bool requested;
+
+};
+
+
+} // namespace geos::util
+} // namespace geos
+
+
+#endif // GEOS_UTIL_INTERRUPT_H

Modified: trunk/include/geos/util/Makefile.am
===================================================================
--- trunk/include/geos/util/Makefile.am	2012-05-24 06:00:52 UTC (rev 3641)
+++ trunk/include/geos/util/Makefile.am	2012-05-25 10:54:37 UTC (rev 3642)
@@ -16,6 +16,7 @@
     GEOSException.h \
     IllegalArgumentException.h \
     IllegalStateException.h \
+    Interrupt.h \
     math.h \
     Machine.h \
     TopologyException.h \

Added: trunk/src/util/Interrupt.cpp
===================================================================
--- trunk/src/util/Interrupt.cpp	                        (rev 0)
+++ trunk/src/util/Interrupt.cpp	2012-05-25 10:54:37 UTC (rev 3642)
@@ -0,0 +1,34 @@
+/**********************************************************************
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.osgeo.org
+ *
+ * Copyright (C) 2012 Sandro Santilli <strk at keybit.net>
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation. 
+ * See the COPYING file for more information.
+ *
+ **********************************************************************/
+
+#include <geos/util/Interrupt.h>
+#include <geos/util/GEOSException.h> // for inheritance
+
+namespace geos {
+namespace util { // geos::util
+
+class GEOS_DLL InterruptedException: public GEOSException {
+public:
+	InterruptedException() :
+		GEOSException("InterruptedException", "Interrupted!") {}
+};
+
+void
+Interrupt::interrupt() { throw InterruptedException(); }
+
+bool Interrupt::requested = false;
+
+} // namespace geos::util
+} // namespace geos
+

Modified: trunk/src/util/Makefile.am
===================================================================
--- trunk/src/util/Makefile.am	2012-05-24 06:00:52 UTC (rev 3641)
+++ trunk/src/util/Makefile.am	2012-05-25 10:54:37 UTC (rev 3642)
@@ -11,6 +11,7 @@
 	Assert.cpp \
 	CustomAllocators.cpp \
 	GeometricShapeFactory.cpp \
+	Interrupt.cpp \
 	math.cpp \
 	Profiler.cpp 
 



More information about the geos-commits mailing list