wip: fixing TCP busyloop

This commit is contained in:
voidlizard 2025-03-15 07:39:50 +03:00 committed by Dmitry Zuykov
parent 622b9ef531
commit 55d1743a93
1 changed files with 13 additions and 2 deletions

View File

@ -94,6 +94,7 @@ data NCQStorage =
, ncqRefsMem :: TVar (HashMap HashRef HashRef) , ncqRefsMem :: TVar (HashMap HashRef HashRef)
, ncqRefsDirty :: TVar Int , ncqRefsDirty :: TVar Int
, ncqWriteQueue :: TVar (HashPSQ HashRef TimeSpec LBS.ByteString) , ncqWriteQueue :: TVar (HashPSQ HashRef TimeSpec LBS.ByteString)
, ncqDeleteQueue :: TVar (HashPSQ HashRef TimeSpec LBS.ByteString)
, ncqWaitIndex :: TVar (HashPSQ HashRef TimeSpec (Word64,Word64)) , ncqWaitIndex :: TVar (HashPSQ HashRef TimeSpec (Word64,Word64))
, ncqTrackedFiles :: TVar (HashSet FileKey) , ncqTrackedFiles :: TVar (HashSet FileKey)
, ncqCachedIndexes :: TVar (HashPSQ FileKey TimeSpec (ByteString,NWayHash)) , ncqCachedIndexes :: TVar (HashPSQ FileKey TimeSpec (ByteString,NWayHash))
@ -642,8 +643,17 @@ ncqStorageDelRef :: MonadUnliftIO m => NCQStorage -> HashRef -> m ()
ncqStorageDelRef NCQStorage{..} ref = atomically do ncqStorageDelRef NCQStorage{..} ref = atomically do
modifyTVar ncqRefsMem (HM.delete ref) modifyTVar ncqRefsMem (HM.delete ref)
ncqStorageDel :: MonadUnliftIO m => NCQStorage -> HashRef -> m NCQStorage ncqStorageDel :: MonadUnliftIO m => NCQStorage -> HashRef -> m ()
ncqStorageDel sto h = do ncqStorageDel ncq@NCQStorage{..} h = flip runContT pure $ callCC \exit -> do
readTVarIO ncqStopped >>= \case
True -> exit ()
_ -> none
atomically $ modifyTVar ncqWriteQueue (HPSQ.delete h)
ncqLocate ncq h >>= \case
_ -> none
error "not implemented yet" error "not implemented yet"
ncqStorageSync :: MonadUnliftIO m => NCQStorage -> m () ncqStorageSync :: MonadUnliftIO m => NCQStorage -> m ()
@ -770,6 +780,7 @@ ncqStorageInit_ check path = do
let ncqMaxCachedData = ncqMaxCachedIdx `div` 2 let ncqMaxCachedData = ncqMaxCachedIdx `div` 2
ncqWriteQueue <- newTVarIO HPSQ.empty ncqWriteQueue <- newTVarIO HPSQ.empty
ncqDeleteQueue <- newTVarIO HPSQ.empty
ncqNotWritten <- newTVarIO 0 ncqNotWritten <- newTVarIO 0
ncqLastWritten <- getTimeCoarse >>= newTVarIO ncqLastWritten <- getTimeCoarse >>= newTVarIO