mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-01 08: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/module/core/text/LexicalCast.h>
|
||||||
|
#include <beast/utility/static_initializer.h>
|
||||||
#include <ripple/module/app/shamap/SHAMapNodeID.h>
|
#include <ripple/module/app/shamap/SHAMapNodeID.h>
|
||||||
#include <boost/format.hpp>
|
#include <boost/format.hpp>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
@@ -25,33 +26,33 @@
|
|||||||
|
|
||||||
namespace ripple {
|
namespace ripple {
|
||||||
|
|
||||||
static std::size_t const mask_size = 65;
|
uint256 const&
|
||||||
|
SHAMapNodeID::Masks (int depth)
|
||||||
|
{
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
mask_size = 65
|
||||||
|
};
|
||||||
|
|
||||||
static
|
struct masks_t
|
||||||
bool
|
{
|
||||||
MasksInit (uint256 (&masks)[mask_size])
|
uint256 entry [mask_size];
|
||||||
|
|
||||||
|
masks_t()
|
||||||
{
|
{
|
||||||
uint256 selector;
|
uint256 selector;
|
||||||
|
|
||||||
for (int i = 0; i < mask_size-1; i += 2)
|
for (int i = 0; i < mask_size-1; i += 2)
|
||||||
{
|
{
|
||||||
masks[i] = selector;
|
entry[i] = selector;
|
||||||
* (selector.begin () + (i / 2)) = 0xF0;
|
* (selector.begin () + (i / 2)) = 0xF0;
|
||||||
masks[i + 1] = selector;
|
entry[i + 1] = selector;
|
||||||
* (selector.begin () + (i / 2)) = 0xFF;
|
* (selector.begin () + (i / 2)) = 0xFF;
|
||||||
}
|
}
|
||||||
|
entry[mask_size-1] = selector;
|
||||||
masks[mask_size-1] = selector;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
static
|
static beast::static_initializer <masks_t> masks;
|
||||||
uint256 const&
|
return masks->entry[depth];
|
||||||
Masks (int depth)
|
|
||||||
{
|
|
||||||
static uint256 masks[mask_size];
|
|
||||||
static bool initialized = MasksInit(masks);
|
|
||||||
return masks[depth];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// canonicalize the hash to a node ID for this depth
|
// canonicalize the hash to a node ID for this depth
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ namespace ripple {
|
|||||||
class SHAMapNodeID
|
class SHAMapNodeID
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
uint256 mNodeID;
|
uint256 mNodeID;
|
||||||
int mDepth;
|
int mDepth;
|
||||||
mutable size_t mHash;
|
mutable size_t mHash;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SHAMapNodeID () : mDepth (0), mHash (0)
|
SHAMapNodeID () : mDepth (0), mHash (0)
|
||||||
{
|
{
|
||||||
@@ -125,14 +125,22 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static
|
||||||
|
uint256 const&
|
||||||
|
Masks (int depth);
|
||||||
|
|
||||||
void setMHash () const;
|
void setMHash () const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
inline std::ostream& operator<< (std::ostream& out, SHAMapNodeID const& node)
|
inline std::ostream& operator<< (std::ostream& out, SHAMapNodeID const& node)
|
||||||
{
|
{
|
||||||
return out << node.getString ();
|
return out << node.getString ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
class SHAMapNode_hash
|
class SHAMapNode_hash
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -148,34 +156,4 @@ public:
|
|||||||
|
|
||||||
} // ripple
|
} // 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>
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -70,16 +70,6 @@ int main (int argc, char** argv)
|
|||||||
"GCC version 4.8.1 or later is required to compile rippled.");
|
"GCC version 4.8.1 or later is required to compile rippled.");
|
||||||
#endif
|
#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,
|
static_assert (BOOST_VERSION >= 105500,
|
||||||
"Boost version 1.55 or later is required to compile rippled");
|
"Boost version 1.55 or later is required to compile rippled");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user