X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=gtk%2Fgtk.main_loop_events.lisp;h=244a7d770f3c8fc5b617a6f9d24ac8673e75d6a4;hb=abaf786e18ebc8dde225e05927c9f2d032ee30fd;hp=6b5b9eb3adab074c77d9bedfeee05ada66b0ab03;hpb=1393c0a9351e56d7011b44ae5eadadb8a02f6e4b;p=cl-gtk2.git diff --git a/gtk/gtk.main_loop_events.lisp b/gtk/gtk.main_loop_events.lisp index 6b5b9eb..244a7d7 100644 --- a/gtk/gtk.main_loop_events.lisp +++ b/gtk/gtk.main_loop_events.lisp @@ -25,44 +25,53 @@ (with-gdk-threads-lock (%gtk-main))) #+thread-support -(defvar *main-thread* nil) - -#+thread-support -(at-finalize () - (when (and *main-thread* (bt:thread-alive-p *main-thread*)) - (bt:destroy-thread *main-thread*) - (setf *main-thread* nil))) - -#+thread-support -(defun ensure-gtk-main () - (when (and *main-thread* (not (bt:thread-alive-p *main-thread*))) - (setf *main-thread* nil)) - (unless *main-thread* - (setf *main-thread* (bt:make-thread (lambda () (gtk-main)) :name "cl-gtk2 main thread")))) - -#+thread-support -(defun join-main-thread () - (when *main-thread* - (bt:join-thread *main-thread*))) - -#+thread-support -(export 'join-main-thread) +(progn + (defvar *main-thread* nil) + (defvar *main-thread-level* nil) + (defvar *main-thread-lock* (bt:make-lock "*main-thread* lock")) + + (at-finalize () + (when (and *main-thread* (bt:thread-alive-p *main-thread*)) + (bt:destroy-thread *main-thread*) + (setf *main-thread* nil))) + + (defun ensure-gtk-main () + (bt:with-lock-held (*main-thread-lock*) + (when (and *main-thread* (not (bt:thread-alive-p *main-thread*))) + (setf *main-thread* nil)) + (unless *main-thread* + (setf *main-thread* (bt:make-thread (lambda () (gtk-main)) :name "cl-gtk2 main thread") + *main-thread-level* 0)) + (incf *main-thread-level*)) + (values)) + + (defun join-gtk-main () + (when *main-thread* + (bt:join-thread *main-thread*))) + + (defun leave-gtk-main () + (bt:with-lock-held (*main-thread-lock*) + (decf *main-thread-level*) + (when (zerop *main-thread-level*) + (gtk-main-quit))))) #-thread-support -(defun ensure-gtk-main () - (gtk-main)) - -(export 'ensure-gtk-main) +(progn + (defun ensure-gtk-main () + (gtk-main) + (values)) -#+thread-support -(defun leave-gtk-main ()) ;noop on multithreading + (defun leave-gtk-main () + (gtk-main-quit)) + + (defun join-gtk-main ())) -#-thread-support -(defun leave-gtk-main () - (gtk-main-quit)) +(export 'ensure-gtk-main) (export 'leave-gtk-main) +(export 'join-gtk-main) + (defcfun gtk-main-level :uint) (defcfun gtk-main-quit :void)