run file transfers in threads, not processes
This should fix OSX/BSD issues with not noticing transfer information files with kqueue. Now that threads are used, the thread can manage the transfer slot allocation and deallocation by itself; much cleaner.
This commit is contained in:
parent
eea0a3616c
commit
cf47bb3f50
7 changed files with 29 additions and 53 deletions
|
@ -10,6 +10,9 @@ module Assistant.TransferSlots where
|
|||
import Control.Exception
|
||||
import Control.Concurrent
|
||||
|
||||
import Common.Annex
|
||||
import Assistant.ThreadedMonad
|
||||
|
||||
type TransferSlots = QSemN
|
||||
|
||||
{- Number of concurrent transfers allowed to be run from the assistant.
|
||||
|
@ -24,16 +27,13 @@ newTransferSlots :: IO TransferSlots
|
|||
newTransferSlots = newQSemN numSlots
|
||||
|
||||
{- Waits until a transfer slot becomes available, and runs a transfer
|
||||
- action in the slot. If the action throws an exception, its slot is
|
||||
- freed here, otherwise it should be freed by the TransferWatcher when
|
||||
- the transfer is complete.
|
||||
-}
|
||||
inTransferSlot :: TransferSlots -> IO a -> IO a
|
||||
inTransferSlot s a = bracketOnError start abort run
|
||||
- action in the slot, in its own thread. -}
|
||||
inTransferSlot :: TransferSlots -> ThreadState -> Annex a -> IO ThreadId
|
||||
inTransferSlot s st a = forkIO $ bracket_ start done run
|
||||
where
|
||||
start = waitQSemN s 1
|
||||
abort = const $ transferComplete s
|
||||
run = const a
|
||||
done = transferComplete s
|
||||
run = unsafeRunThreadState st a
|
||||
|
||||
{- Call when a transfer is complete. -}
|
||||
transferComplete :: TransferSlots -> IO ()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue