-
Notifications
You must be signed in to change notification settings - Fork 1
/
exit-hooks.lisp
35 lines (28 loc) · 1.12 KB
/
exit-hooks.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
;;;; exit-hooks.lisp
(in-package #:exit-hooks)
#-(or sbcl ccl ecl abcl allegro clisp cmu)
(error "Sorry, not implement for ~a. If you can provide exit-hooks for your implementation, please contact me at [email protected]~%" (lisp-implementation-type))
#+abcl
(progn
(defparameter *abcl-exit-hooks* nil)
(defun %abcl-exit-hook-controller ()
(mapc #'funcall *abcl-exit-hooks*))
(defparameter *exit-hook-thread*
(java:jnew-runtime-class "ExitHookThread" :superclass "java.lang.Thread"
:methods `(("run" :void () ,#'(lambda (this)
(declare (ignore this))
(funcall #'%abcl-exit-hook-controller))))))
(java:jcall "addShutdownHook" (java:jstatic "getRuntime" "java.lang.Runtime")
(java:jnew *exit-hook-thread*)))
(define-symbol-macro *exit-hooks*
#+sbcl sb-ext:*exit-hooks*
#+ccl ccl:*lisp-cleanup-functions*
#+ecl si:*exit-hooks*
#+abcl *abcl-exit-hooks*
#+allegro sys:*exit-cleanup-forms*
#+clisp custom:*fini-hooks*
#+cmu lisp::*cleanup-functions*)
(defun add-exit-hook (func)
(push #+allegro (list 'funcall func)
#-allegro func
*exit-hooks*))