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

db4
Slava Pestov 2010-08-23 21:08:16 -05:00
parent 2ba279d689
commit 76d2b83685
6 changed files with 17 additions and 17 deletions

8
basis/io/backend/unix/unix.factor Normal file → Executable file
View File

@ -25,25 +25,25 @@ TUPLE: fd < disposable fd ;
fd new-disposable swap >>fd ;
M: fd dispose
dup disposed>> [ drop ] [
[
{
[ cancel-operation ]
[ t >>disposed drop ]
[ unregister-disposable ]
[ fd>> close-file ]
} cleave
] if ;
] unless-disposed ;
M: fd handle-fd dup check-disposed fd>> ;
M: fd cancel-operation ( fd -- )
dup disposed>> [ drop ] [
[
fd>>
mx get-global
[ remove-input-callbacks [ t swap resume-with ] each ]
[ remove-output-callbacks [ t swap resume-with ] each ]
2bi
] if ;
] unless-disposed ;
M: unix tell-handle ( handle -- n )
fd>> 0 SEEK_CUR [ lseek ] unix-system-call [ io-error ] [ ] bi ;

View File

@ -71,7 +71,7 @@ M: winnt add-completion ( win32-handle -- )
] [ resume-callback t ] if ;
M: win32-handle cancel-operation
[ check-disposed ] [ handle>> CancelIo drop ] bi ;
[ handle>> CancelIo win32-error=0/f ] unless-disposed ;
M: winnt io-multiplex ( nanos -- )
handle-overlapped [ 0 io-multiplex ] when ;

View File

@ -30,9 +30,7 @@ TUPLE: win32-file < win32-handle ptr ;
win32-file new-win32-handle ;
M: win32-file dispose
[ dup disposed>> [ drop ] [ cancel-operation ] if ]
[ call-next-method ]
bi ;
[ cancel-operation ] [ call-next-method ] bi ;
HOOK: CreateFile-flags io-backend ( DWORD -- DWORD )
HOOK: FileArgs-overlapped io-backend ( port -- overlapped/f )

4
basis/io/monitors/linux/linux.factor Normal file → Executable file
View File

@ -56,10 +56,10 @@ M: linux (monitor) ( path recursive? mailbox -- monitor )
M: linux-monitor dispose* ( monitor -- )
[ [ wd>> ] [ watches>> ] bi delete-at ]
[
dup inotify>> disposed>> [ drop ] [
dup inotify>> [
[ inotify>> handle>> handle-fd ] [ wd>> ] bi
inotify_rm_watch io-error
] if
] unless-disposed
]
[ call-next-method ]
tri ;

4
basis/io/monitors/recursive/recursive.factor Normal file → Executable file
View File

@ -49,10 +49,10 @@ M: recursive-monitor dispose*
monitor tget children>> values dispose-each ;
: pump-step ( msg -- )
monitor tget disposed>> [ drop ] [
monitor tget [
[ [ monitor>> path>> ] [ path>> ] bi append-path ] [ changed>> ] bi
monitor tget queue-change
] if ;
] unless-disposed ;
: child-added ( path monitor -- )
path>> prepend-path add-child-monitor ;

12
core/destructors/destructors.factor Normal file → Executable file
View File

@ -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.
USING: accessors continuations kernel namespaces make
sequences vectors sets assocs init math ;
@ -40,15 +40,17 @@ ERROR: already-disposed disposable ;
GENERIC: dispose ( disposable -- )
M: object dispose
dup disposed>> [ drop ] [ t >>disposed dispose* ] if ;
: unless-disposed ( disposable quot -- )
[ dup disposed>> [ drop ] ] dip if ; inline
M: object dispose [ t >>disposed dispose* ] unless-disposed ;
M: disposable dispose
dup disposed>> [ drop ] [
[
[ unregister-disposable ]
[ call-next-method ]
bi
] if ;
] unless-disposed ;
: dispose-each ( seq -- )
[