mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-29 07:25:51 +00:00
Fix msvc static initialization in SHAMapNodeID
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
//==============================================================================
|
||||
|
||||
#include <beast/module/core/text/LexicalCast.h>
|
||||
#include <beast/utility/static_initializer.h>
|
||||
#include <ripple/module/app/shamap/SHAMapNodeID.h>
|
||||
#include <boost/format.hpp>
|
||||
#include <cassert>
|
||||
@@ -25,33 +26,33 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
static std::size_t const mask_size = 65;
|
||||
|
||||
static
|
||||
bool
|
||||
MasksInit (uint256 (&masks)[mask_size])
|
||||
{
|
||||
uint256 selector;
|
||||
|
||||
for (int i = 0; i < mask_size-1; i += 2)
|
||||
{
|
||||
masks[i] = selector;
|
||||
* (selector.begin () + (i / 2)) = 0xF0;
|
||||
masks[i + 1] = selector;
|
||||
* (selector.begin () + (i / 2)) = 0xFF;
|
||||
}
|
||||
|
||||
masks[mask_size-1] = selector;
|
||||
return true;
|
||||
}
|
||||
|
||||
static
|
||||
uint256 const&
|
||||
Masks (int depth)
|
||||
SHAMapNodeID::Masks (int depth)
|
||||
{
|
||||
static uint256 masks[mask_size];
|
||||
static bool initialized = MasksInit(masks);
|
||||
return masks[depth];
|
||||
enum
|
||||
{
|
||||
mask_size = 65
|
||||
};
|
||||
|
||||
struct masks_t
|
||||
{
|
||||
uint256 entry [mask_size];
|
||||
|
||||
masks_t()
|
||||
{
|
||||
uint256 selector;
|
||||
for (int i = 0; i < mask_size-1; i += 2)
|
||||
{
|
||||
entry[i] = selector;
|
||||
* (selector.begin () + (i / 2)) = 0xF0;
|
||||
entry[i + 1] = selector;
|
||||
* (selector.begin () + (i / 2)) = 0xFF;
|
||||
}
|
||||
entry[mask_size-1] = selector;
|
||||
}
|
||||
};
|
||||
static beast::static_initializer <masks_t> masks;
|
||||
return masks->entry[depth];
|
||||
}
|
||||
|
||||
// canonicalize the hash to a node ID for this depth
|
||||
|
||||
@@ -31,10 +31,10 @@ namespace ripple {
|
||||
class SHAMapNodeID
|
||||
{
|
||||
private:
|
||||
|
||||
uint256 mNodeID;
|
||||
int mDepth;
|
||||
int mDepth;
|
||||
mutable size_t mHash;
|
||||
|
||||
public:
|
||||
SHAMapNodeID () : mDepth (0), mHash (0)
|
||||
{
|
||||
@@ -125,14 +125,22 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
static
|
||||
uint256 const&
|
||||
Masks (int depth);
|
||||
|
||||
void setMHash () const;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
inline std::ostream& operator<< (std::ostream& out, SHAMapNodeID const& node)
|
||||
{
|
||||
return out << node.getString ();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class SHAMapNode_hash
|
||||
{
|
||||
public:
|
||||
@@ -146,36 +154,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
} // ripple
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
namespace std {
|
||||
|
||||
template <>
|
||||
struct hash <ripple::SHAMapNodeID>
|
||||
{
|
||||
std::size_t operator() (ripple::SHAMapNodeID const& value) const
|
||||
{
|
||||
return value.getMHash ();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
namespace boost {
|
||||
|
||||
template <>
|
||||
struct hash <ripple::SHAMapNodeID> : std::hash <ripple::SHAMapNodeID>
|
||||
{
|
||||
};
|
||||
|
||||
}
|
||||
*/
|
||||
} // ripple
|
||||
|
||||
#endif
|
||||
|
||||
@@ -70,16 +70,6 @@ int main (int argc, char** argv)
|
||||
"GCC version 4.8.1 or later is required to compile rippled.");
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
static_assert (_MSC_VER >= 1800,
|
||||
"Visual Studio 2013 or later is required to compile rippled.");
|
||||
// Warm up a function-local static under SHAMapNodeID to workaround
|
||||
// vc++ lack of support for thread safe function-local statics
|
||||
{
|
||||
SHAMapNodeID node{0, uint256{}};
|
||||
}
|
||||
#endif
|
||||
|
||||
static_assert (BOOST_VERSION >= 105500,
|
||||
"Boost version 1.55 or later is required to compile rippled");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user