11// Copyright (c) 2009-2010 Satoshi Nakamoto
2- // Copyright (c) 2009-2018 The Bitcoin Core developers
2+ // Copyright (c) 2009-2019 The Bitcoin Core developers
33// Distributed under the MIT software license, see the accompanying
44// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
@@ -705,19 +705,16 @@ fs::path GetDefaultDataDir()
705705static fs::path g_blocks_path_cache_net_specific;
706706static fs::path pathCached;
707707static fs::path pathCachedNetSpecific;
708- static CCriticalSection csPathCached;
708+ static RecursiveMutex csPathCached;
709709
710710const fs::path &GetBlocksDir ()
711711{
712-
713712 LOCK (csPathCached);
714-
715713 fs::path &path = g_blocks_path_cache_net_specific;
716714
717- // This can be called during exceptions by LogPrintf(), so we cache the
718- // value so we don't have to do memory allocations after that.
719- if (!path.empty ())
720- return path;
715+ // Cache the path to avoid calling fs::create_directories on every call of
716+ // this function
717+ if (!path.empty ()) return path;
721718
722719 if (gArgs .IsArgSet (" -blocksdir" )) {
723720 path = fs::system_complete (gArgs .GetArg (" -blocksdir" , " " ));
@@ -737,15 +734,12 @@ const fs::path &GetBlocksDir()
737734
738735const fs::path &GetDataDir (bool fNetSpecific )
739736{
740-
741737 LOCK (csPathCached);
742-
743738 fs::path &path = fNetSpecific ? pathCachedNetSpecific : pathCached;
744739
745- // This can be called during exceptions by LogPrintf(), so we cache the
746- // value so we don't have to do memory allocations after that.
747- if (!path.empty ())
748- return path;
740+ // Cache the path to avoid calling fs::create_directories on every call of
741+ // this function
742+ if (!path.empty ()) return path;
749743
750744 if (gArgs .IsArgSet (" -datadir" )) {
751745 path = fs::system_complete (gArgs .GetArg (" -datadir" , " " ));
0 commit comments