util: Explain why the path is cached
This commit is contained in:
parent
3077f11dad
commit
fa69c3e6ca
2 changed files with 11 additions and 18 deletions
|
@ -1,5 +1,5 @@
|
||||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||||
// Copyright (c) 2009-2018 The Bitcoin Core developers
|
// Copyright (c) 2009-2019 The Bitcoin Core developers
|
||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
@ -705,19 +705,16 @@ fs::path GetDefaultDataDir()
|
||||||
static fs::path g_blocks_path_cache_net_specific;
|
static fs::path g_blocks_path_cache_net_specific;
|
||||||
static fs::path pathCached;
|
static fs::path pathCached;
|
||||||
static fs::path pathCachedNetSpecific;
|
static fs::path pathCachedNetSpecific;
|
||||||
static CCriticalSection csPathCached;
|
static RecursiveMutex csPathCached;
|
||||||
|
|
||||||
const fs::path &GetBlocksDir()
|
const fs::path &GetBlocksDir()
|
||||||
{
|
{
|
||||||
|
|
||||||
LOCK(csPathCached);
|
LOCK(csPathCached);
|
||||||
|
|
||||||
fs::path &path = g_blocks_path_cache_net_specific;
|
fs::path &path = g_blocks_path_cache_net_specific;
|
||||||
|
|
||||||
// This can be called during exceptions by LogPrintf(), so we cache the
|
// Cache the path to avoid calling fs::create_directories on every call of
|
||||||
// value so we don't have to do memory allocations after that.
|
// this function
|
||||||
if (!path.empty())
|
if (!path.empty()) return path;
|
||||||
return path;
|
|
||||||
|
|
||||||
if (gArgs.IsArgSet("-blocksdir")) {
|
if (gArgs.IsArgSet("-blocksdir")) {
|
||||||
path = fs::system_complete(gArgs.GetArg("-blocksdir", ""));
|
path = fs::system_complete(gArgs.GetArg("-blocksdir", ""));
|
||||||
|
@ -737,15 +734,12 @@ const fs::path &GetBlocksDir()
|
||||||
|
|
||||||
const fs::path &GetDataDir(bool fNetSpecific)
|
const fs::path &GetDataDir(bool fNetSpecific)
|
||||||
{
|
{
|
||||||
|
|
||||||
LOCK(csPathCached);
|
LOCK(csPathCached);
|
||||||
|
|
||||||
fs::path &path = fNetSpecific ? pathCachedNetSpecific : pathCached;
|
fs::path &path = fNetSpecific ? pathCachedNetSpecific : pathCached;
|
||||||
|
|
||||||
// This can be called during exceptions by LogPrintf(), so we cache the
|
// Cache the path to avoid calling fs::create_directories on every call of
|
||||||
// value so we don't have to do memory allocations after that.
|
// this function
|
||||||
if (!path.empty())
|
if (!path.empty()) return path;
|
||||||
return path;
|
|
||||||
|
|
||||||
if (gArgs.IsArgSet("-datadir")) {
|
if (gArgs.IsArgSet("-datadir")) {
|
||||||
path = fs::system_complete(gArgs.GetArg("-datadir", ""));
|
path = fs::system_complete(gArgs.GetArg("-datadir", ""));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||||
// Copyright (c) 2009-2018 The Bitcoin Core developers
|
// Copyright (c) 2009-2019 The Bitcoin Core developers
|
||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
@ -20,18 +20,16 @@
|
||||||
#include <fs.h>
|
#include <fs.h>
|
||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
#include <sync.h>
|
#include <sync.h>
|
||||||
#include <util/threadnames.h>
|
|
||||||
#include <tinyformat.h>
|
#include <tinyformat.h>
|
||||||
#include <util/memory.h>
|
#include <util/memory.h>
|
||||||
|
#include <util/threadnames.h>
|
||||||
#include <util/time.h>
|
#include <util/time.h>
|
||||||
|
|
||||||
#include <atomic>
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_set>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -85,6 +83,7 @@ fs::path GetDefaultDataDir();
|
||||||
// The blocks directory is always net specific.
|
// The blocks directory is always net specific.
|
||||||
const fs::path &GetBlocksDir();
|
const fs::path &GetBlocksDir();
|
||||||
const fs::path &GetDataDir(bool fNetSpecific = true);
|
const fs::path &GetDataDir(bool fNetSpecific = true);
|
||||||
|
/** Tests only */
|
||||||
void ClearDatadirCache();
|
void ClearDatadirCache();
|
||||||
fs::path GetConfigFile(const std::string& confPath);
|
fs::path GetConfigFile(const std::string& confPath);
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
Loading…
Reference in a new issue