diff options
author | Eric Blossom | 2010-11-20 18:27:04 -0800 |
---|---|---|
committer | Eric Blossom | 2010-11-20 18:29:03 -0800 |
commit | da6620e6a3d23b78e7231ba70b914974988d3ae1 (patch) | |
tree | 1be26b0f2a83d302dfe2452b3821f22b56028a4b /gnuradio-core/src/guile | |
parent | 5c91f873301a6eca0895788b0b03862fc0060a19 (diff) | |
download | gnuradio-da6620e6a3d23b78e7231ba70b914974988d3ae1.tar.gz gnuradio-da6620e6a3d23b78e7231ba70b914974988d3ae1.tar.bz2 gnuradio-da6620e6a3d23b78e7231ba70b914974988d3ae1.zip |
Add guile SIGINT handler to gr:wait.
Diffstat (limited to 'gnuradio-core/src/guile')
-rw-r--r-- | gnuradio-core/src/guile/gnuradio/runtime-shim.scm | 35 |
1 files changed, 32 insertions, 3 deletions
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) |