Skip to content

Commit

Permalink
actually create one MVar per DB context ...
Browse files Browse the repository at this point in the history
  • Loading branch information
KtorZ committed Dec 16, 2019
1 parent 159c9f4 commit 3835ae3
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions lib/core/src/Cardano/Wallet/DB/Sqlite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -220,28 +220,30 @@ newDBFactory
-- ^ Path to database directory, or Nothing for in-memory database
-> IO (DBFactory IO s k)
newDBFactory cfg tr mDatabaseDir = do
mvar <- newEmptyMVar
case mDatabaseDir of
Nothing -> pure DBFactory
{ withDatabase = \_ action ->
withDBLayer cfg tracerDB Nothing (action . snd)
, removeDatabase = \_ ->
pure ()
}
Just databaseDir -> pure DBFactory
{ withDatabase = \wid action ->
withDBLayer cfg tracerDB (Just $ databaseFile wid) $ \(ctx,db) -> do
putMVar mvar ctx
action db
, removeDatabase = \wid -> do
let files =
[ databaseFile wid
, databaseFile wid <> "-wal"
, databaseFile wid <> "-shm"
]
readMVar mvar >>= destroyDBLayer
mapM_ removePathForcibly files
}
Just databaseDir -> do
mvar <- newEmptyMVar
pure DBFactory
{ withDatabase = \wid action ->
withDBLayer cfg tracerDB (Just $ databaseFile wid)
$ \(ctx,db) -> do
putMVar mvar ctx
action db
, removeDatabase = \wid -> do
let files =
[ databaseFile wid
, databaseFile wid <> "-wal"
, databaseFile wid <> "-shm"
]
readMVar mvar >>= destroyDBLayer
mapM_ removePathForcibly files
}
where
databaseFilePrefix = keyTypeDescriptor $ Proxy @k
databaseFile wid =
Expand Down

0 comments on commit 3835ae3

Please sign in to comment.