1
1
// Copyright (c) 2009-2010 Satoshi Nakamoto
2
- // Copyright (c) 2009-2018 The Bitcoin Core developers
2
+ // Copyright (c) 2009-2019 The Bitcoin Core developers
3
3
// Distributed under the MIT software license, see the accompanying
4
4
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
@@ -705,19 +705,16 @@ fs::path GetDefaultDataDir()
705
705
static fs::path g_blocks_path_cache_net_specific;
706
706
static fs::path pathCached;
707
707
static fs::path pathCachedNetSpecific;
708
- static CCriticalSection csPathCached;
708
+ static RecursiveMutex csPathCached;
709
709
710
710
const fs::path &GetBlocksDir ()
711
711
{
712
-
713
712
LOCK (csPathCached);
714
-
715
713
fs::path &path = g_blocks_path_cache_net_specific;
716
714
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;
721
718
722
719
if (gArgs .IsArgSet (" -blocksdir" )) {
723
720
path = fs::system_complete (gArgs .GetArg (" -blocksdir" , " " ));
@@ -737,15 +734,12 @@ const fs::path &GetBlocksDir()
737
734
738
735
const fs::path &GetDataDir (bool fNetSpecific )
739
736
{
740
-
741
737
LOCK (csPathCached);
742
-
743
738
fs::path &path = fNetSpecific ? pathCachedNetSpecific : pathCached;
744
739
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;
749
743
750
744
if (gArgs .IsArgSet (" -datadir" )) {
751
745
path = fs::system_complete (gArgs .GetArg (" -datadir" , " " ));
0 commit comments