Add unless-disposed combinator to clean up some repetition, and fix bogus error reported from timer thread if an I/O operation with a set timeout fails on Windows
parent
2ba279d689
commit
76d2b83685
|
|
@ -25,25 +25,25 @@ TUPLE: fd < disposable fd ;
|
||||||
fd new-disposable swap >>fd ;
|
fd new-disposable swap >>fd ;
|
||||||
|
|
||||||
M: fd dispose
|
M: fd dispose
|
||||||
dup disposed>> [ drop ] [
|
[
|
||||||
{
|
{
|
||||||
[ cancel-operation ]
|
[ cancel-operation ]
|
||||||
[ t >>disposed drop ]
|
[ t >>disposed drop ]
|
||||||
[ unregister-disposable ]
|
[ unregister-disposable ]
|
||||||
[ fd>> close-file ]
|
[ fd>> close-file ]
|
||||||
} cleave
|
} cleave
|
||||||
] if ;
|
] unless-disposed ;
|
||||||
|
|
||||||
M: fd handle-fd dup check-disposed fd>> ;
|
M: fd handle-fd dup check-disposed fd>> ;
|
||||||
|
|
||||||
M: fd cancel-operation ( fd -- )
|
M: fd cancel-operation ( fd -- )
|
||||||
dup disposed>> [ drop ] [
|
[
|
||||||
fd>>
|
fd>>
|
||||||
mx get-global
|
mx get-global
|
||||||
[ remove-input-callbacks [ t swap resume-with ] each ]
|
[ remove-input-callbacks [ t swap resume-with ] each ]
|
||||||
[ remove-output-callbacks [ t swap resume-with ] each ]
|
[ remove-output-callbacks [ t swap resume-with ] each ]
|
||||||
2bi
|
2bi
|
||||||
] if ;
|
] unless-disposed ;
|
||||||
|
|
||||||
M: unix tell-handle ( handle -- n )
|
M: unix tell-handle ( handle -- n )
|
||||||
fd>> 0 SEEK_CUR [ lseek ] unix-system-call [ io-error ] [ ] bi ;
|
fd>> 0 SEEK_CUR [ lseek ] unix-system-call [ io-error ] [ ] bi ;
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ M: winnt add-completion ( win32-handle -- )
|
||||||
] [ resume-callback t ] if ;
|
] [ resume-callback t ] if ;
|
||||||
|
|
||||||
M: win32-handle cancel-operation
|
M: win32-handle cancel-operation
|
||||||
[ check-disposed ] [ handle>> CancelIo drop ] bi ;
|
[ handle>> CancelIo win32-error=0/f ] unless-disposed ;
|
||||||
|
|
||||||
M: winnt io-multiplex ( nanos -- )
|
M: winnt io-multiplex ( nanos -- )
|
||||||
handle-overlapped [ 0 io-multiplex ] when ;
|
handle-overlapped [ 0 io-multiplex ] when ;
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,7 @@ TUPLE: win32-file < win32-handle ptr ;
|
||||||
win32-file new-win32-handle ;
|
win32-file new-win32-handle ;
|
||||||
|
|
||||||
M: win32-file dispose
|
M: win32-file dispose
|
||||||
[ dup disposed>> [ drop ] [ cancel-operation ] if ]
|
[ cancel-operation ] [ call-next-method ] bi ;
|
||||||
[ call-next-method ]
|
|
||||||
bi ;
|
|
||||||
|
|
||||||
HOOK: CreateFile-flags io-backend ( DWORD -- DWORD )
|
HOOK: CreateFile-flags io-backend ( DWORD -- DWORD )
|
||||||
HOOK: FileArgs-overlapped io-backend ( port -- overlapped/f )
|
HOOK: FileArgs-overlapped io-backend ( port -- overlapped/f )
|
||||||
|
|
|
||||||
|
|
@ -56,10 +56,10 @@ M: linux (monitor) ( path recursive? mailbox -- monitor )
|
||||||
M: linux-monitor dispose* ( monitor -- )
|
M: linux-monitor dispose* ( monitor -- )
|
||||||
[ [ wd>> ] [ watches>> ] bi delete-at ]
|
[ [ wd>> ] [ watches>> ] bi delete-at ]
|
||||||
[
|
[
|
||||||
dup inotify>> disposed>> [ drop ] [
|
dup inotify>> [
|
||||||
[ inotify>> handle>> handle-fd ] [ wd>> ] bi
|
[ inotify>> handle>> handle-fd ] [ wd>> ] bi
|
||||||
inotify_rm_watch io-error
|
inotify_rm_watch io-error
|
||||||
] if
|
] unless-disposed
|
||||||
]
|
]
|
||||||
[ call-next-method ]
|
[ call-next-method ]
|
||||||
tri ;
|
tri ;
|
||||||
|
|
|
||||||
|
|
@ -49,10 +49,10 @@ M: recursive-monitor dispose*
|
||||||
monitor tget children>> values dispose-each ;
|
monitor tget children>> values dispose-each ;
|
||||||
|
|
||||||
: pump-step ( msg -- )
|
: pump-step ( msg -- )
|
||||||
monitor tget disposed>> [ drop ] [
|
monitor tget [
|
||||||
[ [ monitor>> path>> ] [ path>> ] bi append-path ] [ changed>> ] bi
|
[ [ monitor>> path>> ] [ path>> ] bi append-path ] [ changed>> ] bi
|
||||||
monitor tget queue-change
|
monitor tget queue-change
|
||||||
] if ;
|
] unless-disposed ;
|
||||||
|
|
||||||
: child-added ( path monitor -- )
|
: child-added ( path monitor -- )
|
||||||
path>> prepend-path add-child-monitor ;
|
path>> prepend-path add-child-monitor ;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
! Copyright (C) 2007, 2009 Doug Coleman, Slava Pestov.
|
! Copyright (C) 2007, 2010 Doug Coleman, Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors continuations kernel namespaces make
|
USING: accessors continuations kernel namespaces make
|
||||||
sequences vectors sets assocs init math ;
|
sequences vectors sets assocs init math ;
|
||||||
|
|
@ -40,15 +40,17 @@ ERROR: already-disposed disposable ;
|
||||||
|
|
||||||
GENERIC: dispose ( disposable -- )
|
GENERIC: dispose ( disposable -- )
|
||||||
|
|
||||||
M: object dispose
|
: unless-disposed ( disposable quot -- )
|
||||||
dup disposed>> [ drop ] [ t >>disposed dispose* ] if ;
|
[ dup disposed>> [ drop ] ] dip if ; inline
|
||||||
|
|
||||||
|
M: object dispose [ t >>disposed dispose* ] unless-disposed ;
|
||||||
|
|
||||||
M: disposable dispose
|
M: disposable dispose
|
||||||
dup disposed>> [ drop ] [
|
[
|
||||||
[ unregister-disposable ]
|
[ unregister-disposable ]
|
||||||
[ call-next-method ]
|
[ call-next-method ]
|
||||||
bi
|
bi
|
||||||
] if ;
|
] unless-disposed ;
|
||||||
|
|
||||||
: dispose-each ( seq -- )
|
: dispose-each ( seq -- )
|
||||||
[
|
[
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue