Skip to content

Commit

Permalink
Various beast cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
vinniefalco committed Jul 3, 2013
1 parent 69d1771 commit 48cd904
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 24 deletions.
17 changes: 8 additions & 9 deletions Subtrees/beast/modules/beast_core/memory/beast_Atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,14 @@ class Atomic
volatile Type value;

private:
#if BEAST_CLANG || __GNUC__ >= 4
#define BEAST_ATTRIBUTE_MAY_ALIAS __attribute__((__may_alias__))
#else
#define BEAST_ATTRIBUTE_MAY_ALIAS
#endif
static inline Type castFrom32Bit (int32 value) noexcept { Type * BEAST_ATTRIBUTE_MAY_ALIAS tmp = (Type*)&value; return *tmp; }
static inline Type castFrom64Bit (int64 value) noexcept { Type * BEAST_ATTRIBUTE_MAY_ALIAS tmp = (Type*)&value; return *tmp; }
static inline int32 castTo32Bit (Type value) noexcept { int32 * BEAST_ATTRIBUTE_MAY_ALIAS tmp = (int32*)&value; return *tmp; }
static inline int64 castTo64Bit (Type value) noexcept { int64 * BEAST_ATTRIBUTE_MAY_ALIAS tmp = (int64*)&value; return *tmp; }
template <typename Dest, typename Source>
static inline Dest castTo (Source value) noexcept { union { Dest d; Source s; } u; u.s = value; return u.d; }

static inline Type castFrom32Bit (int32 value) noexcept { return castTo <Type, int32> (value); }
static inline Type castFrom64Bit (int64 value) noexcept { return castTo <Type, int64> (value); }
static inline int32 castTo32Bit (Type value) noexcept { return castTo <int32, Type> (value); }
static inline int64 castTo64Bit (Type value) noexcept { return castTo <int64, Type> (value); }


Type operator++ (int); // better to just use pre-increment with atomics..
Type operator-- (int);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ void Process::terminate()

BEAST_API bool BEAST_CALLTYPE beast_isRunningUnderDebugger()
{
bassertfalse; // XXX not implemented for FreeBSD!
// XXX not implemented for FreeBSD!
bassertfalse;
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ int SystemStats::getMemorySizeInMegabytes()
struct sysinfo sysi;

if (sysinfo (&sysi) == 0)
return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
return sysi.totalram * sysi.mem_unit / (1024 * 1024);

return 0;
}
Expand All @@ -94,11 +94,8 @@ String SystemStats::getLogonName()
const char* user = getenv ("USER");

if (user == nullptr)
{
struct passwd* const pw = getpwuid (getuid());
if (pw != nullptr)
if (passwd* const pw = getpwuid (getuid()))
user = pw->pw_name;
}

return CharPointer_UTF8 (user);
}
Expand All @@ -117,11 +114,12 @@ String SystemStats::getComputerName()
return String::empty;
}

String getLocaleValue (nl_item key)
static String getLocaleValue (nl_item key)
{
const char* oldLocale = ::setlocale (LC_ALL, "");
return String (const_cast <const char*> (nl_langinfo (key)));
String result (String::fromUTF8 (nl_langinfo (key)));
::setlocale (LC_ALL, oldLocale);
return result;
}

String SystemStats::getUserLanguage() { return getLocaleValue (_NL_IDENTIFICATION_LANGUAGE); }
Expand All @@ -141,7 +139,7 @@ SystemStats::CPUFlags::CPUFlags()
}

//==============================================================================
uint32 beast_millisecondsSinceStartup() noexcept
uint32 BEAST_millisecondsSinceStartup() noexcept
{
timespec t;
clock_gettime (CLOCK_MONOTONIC, &t);
Expand Down
7 changes: 4 additions & 3 deletions Subtrees/beast/modules/beast_core/text/beast_String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1200,8 +1200,8 @@ class StringCreationHelper
dest = result.getCharPointer();
}

StringCreationHelper (const String::CharPointerType& source_)
: source (source_), dest (nullptr), allocatedBytes (StringHolder::getAllocatedNumBytes (source)), bytesWritten (0)
StringCreationHelper (const String::CharPointerType s)
: source (s), dest (nullptr), allocatedBytes (StringHolder::getAllocatedNumBytes (s)), bytesWritten (0)
{
result.preallocateBytes (allocatedBytes);
dest = result.getCharPointer();
Expand Down Expand Up @@ -1531,7 +1531,8 @@ String String::quoted (const beast_wchar quoteCharacter) const
}

//==============================================================================
static String::CharPointerType findTrimmedEnd (const String::CharPointerType& start, String::CharPointerType end)
static String::CharPointerType findTrimmedEnd (const String::CharPointerType start,
String::CharPointerType end)
{
while (end > start)
{
Expand Down
6 changes: 3 additions & 3 deletions Subtrees/beast/modules/beast_core/text/beast_TextDiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ struct TextDiffHelpers
StringRegion (const String& s) noexcept
: text (s.getCharPointer()), start (0), length (s.length()) {}

StringRegion (const String::CharPointerType& t, int s, int len) noexcept
StringRegion (const String::CharPointerType t, int s, int len) noexcept
: text (t), start (s), length (len) {}

String::CharPointerType text;
int start, length;
};

static void addInsertion (TextDiff& td, const String::CharPointerType& text, int index, int length)
static void addInsertion (TextDiff& td, const String::CharPointerType text, int index, int length)
{
TextDiff::Change c;
c.insertedText = String (text, (size_t) length);
Expand Down Expand Up @@ -99,7 +99,7 @@ struct TextDiffHelpers
}

static int findLongestCommonSubstring (String::CharPointerType a, const int lenA,
const String::CharPointerType& b, const int lenB,
const String::CharPointerType b, const int lenB,
int& indexInA, int& indexInB)
{
if (lenA == 0 || lenB == 0)
Expand Down
20 changes: 20 additions & 0 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,23 @@ boost::recursive_mutex

Replace recursive_mutex with beast::Mutex to remove boost dependency

--------------------------------------------------------------------------------
Davidisms
--------------------------------------------------------------------------------

(Figure out a good place to record information like this permanently)

Regarding a defect where a failing transaction was being submitted over and over
again on the network (July 3, 2013)

The core problem was an interaction between two bits of logic.
1) Normally, we won't relay a transaction again if we already recently relayed
it. But this is bypassed if the transaction failed in a way that could
allow it to succeed later. This way, if one server discovers a transaction
can now work, it can get all servers to retry it.
2) Normally, we won't relay a transaction if we think it can't claim a fee.
But if we're not sure it can't claim a fee because we're in an unhealthy
state, we propagate the transaction to let other servers decide if they
think it can claim a fee.
With these two bits of logic, two unhealthy servers could infinitely propagate
a transaction back and forth between each other.

0 comments on commit 48cd904

Please sign in to comment.