]> gitweb.factorcode.org Git - factor.git/commitdiff
io.monitors: if a monitor is disposed while other threads are waiting on it, an error...
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 19 Feb 2010 11:23:24 +0000 (00:23 +1300)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 19 Feb 2010 11:23:24 +0000 (00:23 +1300)
basis/io/monitors/linux/linux.factor
basis/io/monitors/macosx/macosx.factor
basis/io/monitors/monitors-tests.factor
basis/io/monitors/monitors.factor
basis/io/monitors/recursive/recursive.factor
basis/io/monitors/windows/nt/nt.factor

index 7653eaa84cbcbd563ef06ede7266c6a0b2045601..eacc9203031a8961dd488c755802caaf2fa8a203 100644 (file)
@@ -59,7 +59,9 @@ M: linux-monitor dispose* ( monitor -- )
             [ inotify>> handle>> handle-fd ] [ wd>> ] bi
             inotify_rm_watch io-error
         ] if
-    ] bi ;
+    ]
+    [ call-next-method ]
+    tri ;
 
 : ignore-flags? ( mask -- ? )
     {
index e71fb2eca2f9476ac364fbae266684a252104e80..dbbbe7c7e37b9d28d47476d0413435c7773cc46c 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2008 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: io.backend io.monitors
 core-foundation.fsevents continuations kernel sequences
@@ -16,6 +16,7 @@ M:: macosx (monitor) ( path recursive? mailbox -- monitor )
     dup [ enqueue-notifications ] curry
     path 1array 0 0 <event-stream> >>handle ;
 
-M: macosx-monitor dispose* handle>> dispose ;
+M: macosx-monitor dispose*
+    [ handle>> dispose ] [ call-next-method ] bi ;
 
 macosx set-io-backend
index 576ac7ca304146f7cf08492d371e613184122f16..ac17c4a39fe0dd867a1ed68723ead5cdf5ec1b1f 100644 (file)
@@ -3,7 +3,7 @@ USING: io.monitors tools.test io.files system sequences
 continuations namespaces concurrency.count-downs kernel io
 threads calendar prettyprint destructors io.timeouts
 io.files.temp io.directories io.directories.hierarchy
-io.pathnames accessors ;
+io.pathnames accessors concurrency.promises ;
 
 os { winnt linux macosx } member? [
     [
@@ -110,4 +110,23 @@ os { winnt linux macosx } member? [
         [ [ t ] [ "m" get next-change drop ] while ] must-fail
         [ ] [ "m" get dispose ] unit-test
     ] with-monitors
+
+    ! Disposing a monitor should throw an error in any threads
+    ! waiting on notifications
+    [
+        [ ] [
+            <promise> "p" set
+            "monitor-test" temp-file t <monitor> "m" set
+            10 seconds "m" get set-timeout
+        ] unit-test
+
+        [
+            [ "m" get next-change ] [ ] recover
+            "p" get fulfill
+        ] in-thread
+
+        [ ] [ 1 seconds sleep ] unit-test
+        [ ] [ "m" get dispose ] unit-test
+        [ t ] [ "p" get 10 seconds ?promise-timeout already-disposed? ] unit-test
+    ] with-monitors
 ] when
index cb2f552a324187cf619a4dde2c72226a94ab1a4d..731798c424f01b0cd4d32002d5984335823d753a 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2008, 2009 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: io.backend kernel continuations destructors namespaces
 sequences assocs hashtables sorting arrays threads boxes
@@ -26,6 +26,15 @@ M: monitor timeout timeout>> ;
 
 M: monitor set-timeout (>>timeout) ;
 
+<PRIVATE
+
+SYMBOL: monitor-disposed
+
+PRIVATE>
+
+M: monitor dispose*
+    [ monitor-disposed ] dip queue>> mailbox-put ;
+
 : new-monitor ( path mailbox class -- monitor )
     new-disposable
         swap >>queue
@@ -34,8 +43,11 @@ M: monitor set-timeout (>>timeout) ;
 TUPLE: file-change path changed monitor ;
 
 : queue-change ( path changes monitor -- )
-    3dup and and
-    [ [ file-change boa ] keep queue>> mailbox-put ] [ 3drop ] if ;
+    3dup and and [
+        [ check-disposed ] keep
+        [ file-change boa ] keep
+        queue>> mailbox-put
+    ] [ 3drop ] if ;
 
 HOOK: (monitor) io-backend ( path recursive? mailbox -- monitor )
 
@@ -43,7 +55,11 @@ HOOK: (monitor) io-backend ( path recursive? mailbox -- monitor )
     <mailbox> (monitor) ;
 
 : next-change ( monitor -- change )
-    [ queue>> ] [ timeout ] bi mailbox-get-timeout ;
+    [ check-disposed ]
+    [
+        [ ] [ queue>> ] [ timeout ] tri mailbox-get-timeout
+        dup monitor-disposed eq? [ drop already-disposed ] [ nip ] if
+    ] bi ;
 
 SYMBOL: +add-file+
 SYMBOL: +remove-file+
index 33477abdb639b738943e177a1240c6fa96322204..83c088e8824e023734eadb22c8398623b2f436a8 100644 (file)
@@ -41,7 +41,7 @@ DEFER: add-child-monitor
 
 M: recursive-monitor dispose*
     [ "stop" swap thread>> send-synchronous drop ]
-    [ queue>> dispose ]
+    [ call-next-method ]
     bi ;
 
 : stop-pump ( -- )
index 9cd8bc4df8ff03001fd760ffa53a7551c6a0bc9a..4d061cbb1ad2df8a0c79cad79cf738509998ba4b 100644 (file)
@@ -100,4 +100,4 @@ M:: winnt (monitor) ( path recursive? mailbox -- monitor )
     ] with-destructors ;
 
 M: win32-monitor dispose
-    port>> dispose ;
+    [ port>> dispose ] [ call-next-method ] bi ;