* New Features *
+ - Interruptibility API for liblwgeom (Sandro Santilli / CartoDB)
- #2939, ST_ClipByBox2D (Sandro Santilli / CartoDB)
- #2247, ST_Retile and ST_CreateOverview: in-db raster overviews creation
(Sandro Santilli / Vizzuality)
lwreallocator reallocator, lwfreeor freeor, lwreporter errorreporter,
lwreporter noticereporter);
+/**
+ * Request interruption of any running code
+ *
+ * Safe for use from signal handlers
+ *
+ * Interrupted code will (as soon as it finds out
+ * to be interrupted) cleanup and return as soon as possible.
+ *
+ * The return value from interrupted code is undefined,
+ * it is the caller responsibility to not take it in consideration.
+ *
+ */
+extern void lwgeom_request_interrupt(void);
+
+/**
+ * Install a callback to be called periodically during
+ * algorithm execution. Mostly only needed on WIN32 to
+ * dispatch queued signals.
+ *
+ * The callback is invoked before checking for interrupt
+ * being requested, so you can request interruption from
+ * the callback, if you want (see lwgeom_request_interrupt).
+ *
+ */
+typedef void (lwinterrupt_callback)();
+extern lwinterrupt_callback *lwgeom_register_interrupt_callback(lwinterrupt_callback *);
+
/**
* Write a notice out to the notice handler.
*
extern uint8_t MULTITYPE[NUMTYPES];
+extern lwinterrupt_callback *_lwgeom_interrupt_callback;
+extern int _lwgeom_interrupt_requested;
+#define LW_ON_INTERRUPT(x) { \
+ if ( _lwgeom_interrupt_callback ) { \
+ (*_lwgeom_interrupt_callback)(); \
+ } \
+ if ( _lwgeom_interrupt_requested ) { \
+ _lwgeom_interrupt_requested = 0; \
+ lwnotice("liblwgeom code interrupted"); \
+ x; \
+ } \
+}
+
#endif /* _LIBLWGEOM_INTERNAL_H */
}
+int _lwgeom_interrupt_requested = 0;
+void
+lwgeom_request_interrupt() {
+ _lwgeom_interrupt_requested = 1;
+}
+lwinterrupt_callback *_lwgeom_interrupt_callback = 0;
+lwinterrupt_callback *
+lwgeom_register_interrupt_callback(lwinterrupt_callback *cb) {
+ lwinterrupt_callback *old = _lwgeom_interrupt_callback;
+ _lwgeom_interrupt_callback = cb;
+ return old;
+}
static void handleInterrupt(int sig);
#ifdef WIN32
-#if POSTGIS_GEOS_VERSION >= 34
-static void geosInterruptCallback() {
+static void interruptCallback() {
if (UNBLOCKED_SIGNAL_QUEUE())
pgwin32_dispatch_queued_signals();
}
#endif
-#endif
/*
* Module load callback
#ifdef WIN32
#if POSTGIS_GEOS_VERSION >= 34
- GEOS_interruptRegisterCallback(geosInterruptCallback);
+ GEOS_interruptRegisterCallback(interruptCallback);
#endif
+ lwgeom_register_interrupt_callback(interruptCallback);
#endif
#if 0
GEOS_interruptRequest();
#endif
- /* TODO: request interruption of liblwgeom as well ? */
+ /* request interruption of liblwgeom as well */
+ lwgeom_request_interrupt();
if ( coreIntHandler ) {
(*coreIntHandler)(sig);