diff options
-rw-r--r-- | Guile-TODO | 4 | ||||
-rw-r--r-- | gnuradio-core/src/guile/gnuradio/runtime-shim.scm | 35 |
2 files changed, 34 insertions, 5 deletions
diff --git a/Guile-TODO b/Guile-TODO index 93d96fa17..6f770c936 100644 --- a/Guile-TODO +++ b/Guile-TODO @@ -1,7 +1,5 @@ In no particular order: -2) SIGINT handling in gr_top_block::wait - 3) Ensure that all 4 combinations of --{enable,disable}-python --{enable,disable}-guile work correctly. @@ -72,6 +70,8 @@ These are done: 1) [DONE] Ensure that libraries containing swig generated code are regenerated when any relevant .i file is touched. +2) [DONE] SIGINT handling in gr_top_block::wait + 4) [DONE] Fix GR_SWIG_BLOCK_MAGIC so that in the guile case we don't map all the constructors into the same name. E.g. audio_alsa_sink -> sink. (Causes problem when multiple gr-* modules are used.) diff --git a/gnuradio-core/src/guile/gnuradio/runtime-shim.scm b/gnuradio-core/src/guile/gnuradio/runtime-shim.scm index 105f4ddb8..bba702670 100644 --- a/gnuradio-core/src/guile/gnuradio/runtime-shim.scm +++ b/gnuradio-core/src/guile/gnuradio/runtime-shim.scm @@ -19,6 +19,7 @@ (define-module (gnuradio runtime-shim) #:use-module (oop goops) + #:use-module (ice-9 threads) #:use-module (gnuradio gnuradio_core_runtime) #:duplicates (merge-generics replace check)) @@ -92,9 +93,37 @@ (gr:start self) (gr:wait self)) -(define-method (gr:wait (self <gr-top-block-sptr>)) - ;; FIXME Set up SIGINT handling here... - (gr:top-block-wait-unlocked self)) + +(define-method (gr:wait (tb <gr-top-block-sptr>)) + + (define (sigint-handler sig) + ;;(display "\nSIGINT!\n" (current-error-port)) + ;; tell flow graph to stop + (gr:stop tb)) + + (let ((old-handler #f)) + (dynamic-wind + + ;; Called at entry + (lambda () + ;; Install SIGINT handler + (set! old-handler (sigaction SIGINT sigint-handler))) + + ;; Protected thunk + (lambda () + (let ((waiter (begin-thread (gr:top-block-wait-unlocked tb)))) + (join-thread waiter) + ;;(display "\nAfter join-thread\n" (current-error-port)) + )) + + ;; Called at exit + (lambda () + ;; Restore SIGINT handler + (if (not (car old-handler)) + ;; restore original C handler + (sigaction SIGINT #f) + ;; restore Scheme handler, SIG_IGN or SIG_DFL + (sigaction SIGINT (car old-handler) (cdr old-handler))))))) (export-safely <gr-endpoint> gr:ep gr:connect gr:disconnect gr:run gr:wait) |