Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature cleanup #110

Merged
merged 15 commits into from
Jul 4, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ DerivedData
.idea/
*.hmap

# Intel Parallel Studio 2013 XE
My Amplifier XE Results - RippleD
22 changes: 12 additions & 10 deletions Builds/VisualStudio2012/Ripple.sln
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Express 2012 for Windows Desktop
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RippleD", "RippleD.vcxproj", "{19465545-42EE-42FA-9CC8-F8975F8F1CC7}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "beast", "..\..\Subtrees\beast\Builds\VisualStudio2012\beast.vcxproj", "{73C5A0F0-7629-4DE7-9194-BE7AC6C19535}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RippleD", "RippleD.vcxproj", "{B7F39ECD-473C-484D-BC34-31F8362506A5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Expand All @@ -13,20 +13,22 @@ Global
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{19465545-42EE-42FA-9CC8-F8975F8F1CC7}.Debug|Win32.ActiveCfg = Debug|Win32
{19465545-42EE-42FA-9CC8-F8975F8F1CC7}.Debug|Win32.Build.0 = Debug|Win32
{19465545-42EE-42FA-9CC8-F8975F8F1CC7}.Debug|x64.ActiveCfg = Debug|x64
{19465545-42EE-42FA-9CC8-F8975F8F1CC7}.Debug|x64.Build.0 = Debug|x64
{19465545-42EE-42FA-9CC8-F8975F8F1CC7}.Release|Win32.ActiveCfg = Release|Win32
{19465545-42EE-42FA-9CC8-F8975F8F1CC7}.Release|Win32.Build.0 = Release|Win32
{19465545-42EE-42FA-9CC8-F8975F8F1CC7}.Release|x64.ActiveCfg = Release|x64
{19465545-42EE-42FA-9CC8-F8975F8F1CC7}.Release|x64.Build.0 = Release|x64
{73C5A0F0-7629-4DE7-9194-BE7AC6C19535}.Debug|Win32.ActiveCfg = Debug|Win32
{73C5A0F0-7629-4DE7-9194-BE7AC6C19535}.Debug|Win32.Build.0 = Debug|Win32
{73C5A0F0-7629-4DE7-9194-BE7AC6C19535}.Debug|x64.ActiveCfg = Debug|x64
{73C5A0F0-7629-4DE7-9194-BE7AC6C19535}.Debug|x64.Build.0 = Debug|x64
{73C5A0F0-7629-4DE7-9194-BE7AC6C19535}.Release|Win32.ActiveCfg = Release|Win32
{73C5A0F0-7629-4DE7-9194-BE7AC6C19535}.Release|Win32.Build.0 = Release|Win32
{73C5A0F0-7629-4DE7-9194-BE7AC6C19535}.Release|x64.ActiveCfg = Release|x64
{73C5A0F0-7629-4DE7-9194-BE7AC6C19535}.Release|x64.Build.0 = Release|x64
{B7F39ECD-473C-484D-BC34-31F8362506A5}.Debug|Win32.ActiveCfg = Debug|Win32
{B7F39ECD-473C-484D-BC34-31F8362506A5}.Debug|Win32.Build.0 = Debug|Win32
{B7F39ECD-473C-484D-BC34-31F8362506A5}.Debug|x64.ActiveCfg = Debug|x64
{B7F39ECD-473C-484D-BC34-31F8362506A5}.Debug|x64.Build.0 = Debug|x64
{B7F39ECD-473C-484D-BC34-31F8362506A5}.Release|Win32.ActiveCfg = Release|Win32
{B7F39ECD-473C-484D-BC34-31F8362506A5}.Release|Win32.Build.0 = Release|Win32
{B7F39ECD-473C-484D-BC34-31F8362506A5}.Release|x64.ActiveCfg = Release|x64
{B7F39ECD-473C-484D-BC34-31F8362506A5}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion Builds/VisualStudio2012/RippleD.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions>_CRTDBG_MAP_ALLOC;_VARIADIC_MAX=10;_WIN32_WINNT=0x0600;_SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_VARIADIC_MAX=10;_WIN32_WINNT=0x0600;_SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<WarningLevel>Level3</WarningLevel>
<AdditionalIncludeDirectories>$(RepoDir);$(RepoDir)\src\cpp\protobuf\src;$(RepoDir)\src\cpp\protobuf\vsprojects;$(RepoDir)\build\proto;$(RepoDir)\Subtrees;$(RepoDir)\Subtrees\leveldb;$(RepoDir)\Subtrees\leveldb\include;$(RepoDir)\Subtrees\beast;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
Expand Down
1,363 changes: 531 additions & 832 deletions Builds/VisualStudio2012/RippleD.vcxproj

Large diffs are not rendered by default.

2,154 changes: 950 additions & 1,204 deletions Builds/VisualStudio2012/RippleD.vcxproj.filters

Large diffs are not rendered by default.

34 changes: 0 additions & 34 deletions RippleD.props

This file was deleted.

6 changes: 5 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ COMPILED_FILES = [
'modules/ripple_app/ripple_app_pt1.cpp',
'modules/ripple_app/ripple_app_pt2.cpp',
'modules/ripple_app/ripple_app_pt3.cpp',
'modules/ripple_app/ripple_app_pt4.cpp'
'modules/ripple_app/ripple_app_pt4.cpp',
'modules/ripple_app/ripple_app_pt5.cpp',
'modules/ripple_app/ripple_app_pt6.cpp',
'modules/ripple_app/ripple_app_pt7.cpp',
'modules/ripple_app/ripple_app_pt8.cpp'
]

#-------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions Subtrees/beast/modules/beast_core/containers/beast_Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ class Array

if (isPositiveAndBelow (indexToRemove, numUsed))
{
bassert (data.elements != nullptr);
ElementType removed (data.elements[indexToRemove]);
removeInternal (indexToRemove);
return removed;
Expand Down
70 changes: 14 additions & 56 deletions Subtrees/beast/modules/beast_core/containers/beast_OwnedArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@
#ifndef BEAST_OWNEDARRAY_BEASTHEADER
#define BEAST_OWNEDARRAY_BEASTHEADER

#include "beast_ArrayAllocationBase.h"
#include "beast_ElementComparator.h"
#include "../threads/beast_CriticalSection.h"


//==============================================================================
/** An array designed for holding objects.

Expand All @@ -51,7 +46,9 @@
template <class ObjectClass,
class TypeOfCriticalSectionToUse = DummyCriticalSection>

class OwnedArray : LeakChecked <OwnedArray <ObjectClass, TypeOfCriticalSectionToUse> >, Uncopyable
class OwnedArray
: LeakChecked <OwnedArray <ObjectClass, TypeOfCriticalSectionToUse> >
, Uncopyable
{
public:
//==============================================================================
Expand Down Expand Up @@ -242,23 +239,15 @@ class OwnedArray : LeakChecked <OwnedArray <ObjectClass, TypeOfCriticalSectionTo
as this will obviously cause deletion of dangling pointers.

@param newObject the new object to add to the array
@returns the object that was added

@see set, insert, addIfNotAlreadyThere, addSorted
*/
ObjectClass const& add (ObjectClass const* const newObject) noexcept
ObjectClass* add (ObjectClass* const newObject) noexcept
{
const ScopedLockType lock (getLock());
data.ensureAllocatedSize (numUsed + 1);
bassert (data.elements != nullptr);
data.elements [numUsed++] = const_cast <ObjectClass*> (newObject);
return *newObject;
}

ObjectClass& add (ObjectClass* const newObject) noexcept
{
add (const_cast <ObjectClass const*> (newObject));
return *newObject;
return const_cast <ObjectClass*> (newObject);
}

/** Inserts a new object into the array at the given index.
Expand All @@ -276,12 +265,10 @@ class OwnedArray : LeakChecked <OwnedArray <ObjectClass, TypeOfCriticalSectionTo

@param indexToInsertAt the index at which the new element should be inserted
@param newObject the new object to add to the array
@returns the object that was added

@see add, addSorted, addIfNotAlreadyThere, set
*/
ObjectClass const& insert (int indexToInsertAt,
ObjectClass const* const newObject) noexcept
void insert (int indexToInsertAt,
ObjectClass* const newObject) noexcept
{
if (indexToInsertAt >= 0)
{
Expand All @@ -306,15 +293,6 @@ class OwnedArray : LeakChecked <OwnedArray <ObjectClass, TypeOfCriticalSectionTo
{
add (newObject);
}

return *newObject;
}

ObjectClass& insert (int indexToInsertAt,
ObjectClass* const newObject) noexcept
{
insert (indexToInsertAt, const_cast <ObjectClass const*> (newObject));
return *newObject;
}

/** Inserts an array of values into this array at a given position.
Expand Down Expand Up @@ -363,22 +341,13 @@ class OwnedArray : LeakChecked <OwnedArray <ObjectClass, TypeOfCriticalSectionTo
If the array already contains a matching object, nothing will be done.

@param newObject the new object to add to the array
@returns the object
*/
ObjectClass const& addIfNotAlreadyThere (ObjectClass const* const newObject) noexcept
void addIfNotAlreadyThere (ObjectClass* const newObject) noexcept
{
const ScopedLockType lock (getLock());

if (! contains (newObject))
add (newObject);

return *newObject;
}

ObjectClass& addIfNotAlreadyThere (ObjectClass* const newObject) noexcept
{
addIfNotAlreadyThere (const_cast <ObjectClass const*> (newObject));
return *newObject;
}

/** Replaces an object in the array with a different one.
Expand All @@ -392,13 +361,11 @@ class OwnedArray : LeakChecked <OwnedArray <ObjectClass, TypeOfCriticalSectionTo
@param indexToChange the index whose value you want to change
@param newObject the new value to set for this index.
@param deleteOldElement whether to delete the object that's being replaced with the new one
@returns the object that was set

@see add, insert, remove
*/
ObjectClass const& set (int const indexToChange,
ObjectClass const* const newObject,
bool const deleteOldElement = true)
void set (const int indexToChange,
const ObjectClass* const newObject,
const bool deleteOldElement = true)
{
if (indexToChange >= 0)
{
Expand Down Expand Up @@ -435,16 +402,6 @@ class OwnedArray : LeakChecked <OwnedArray <ObjectClass, TypeOfCriticalSectionTo
bassertfalse; // you're trying to set an object at a negative index, which doesn't have
// any effect - but since the object is not being added, it may be leaking..
}

return *newObject;
}

ObjectClass& set (int const indexToChange,
ObjectClass* const newObject,
bool const deleteOldElement = true)
{
set (indexToChange, const_cast <ObjectClass const*> (newObject), deleteOldElement);
return *newObject;
}

/** Adds elements from another array to the end of this array.
Expand Down Expand Up @@ -515,7 +472,7 @@ class OwnedArray : LeakChecked <OwnedArray <ObjectClass, TypeOfCriticalSectionTo
numElementsToAdd = arrayToAddFrom.size() - startIndex;

data.ensureAllocatedSize (numUsed + numElementsToAdd);
bassert (numElementsToAdd <= 0 || data.elements != nullptr);
bassert (numElementsToAdd <= 0 || data.elements != nullptr);

while (--numElementsToAdd >= 0)
{
Expand Down Expand Up @@ -909,4 +866,5 @@ class OwnedArray : LeakChecked <OwnedArray <ObjectClass, TypeOfCriticalSectionTo
}
};

#endif // BEAST_OWNEDARRAY_BEASTHEADER

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class ReferenceCountedArray
@param newObject the new object to add to the array
@see set, insert, addIfNotAlreadyThere, addSorted, addArray
*/
void add (ObjectClass* const newObject) noexcept
ObjectClass* add (ObjectClass* const newObject) noexcept
{
const ScopedLockType lock (getLock());
data.ensureAllocatedSize (numUsed + 1);
Expand All @@ -297,6 +297,8 @@ class ReferenceCountedArray

if (newObject != nullptr)
newObject->incReferenceCount();

return newObject;
}

/** Inserts a new object into the array at the given index.
Expand All @@ -312,8 +314,8 @@ class ReferenceCountedArray
@param newObject the new object to add to the array
@see add, addSorted, addIfNotAlreadyThere, set
*/
void insert (int indexToInsertAt,
ObjectClass* const newObject) noexcept
ObjectClass* insert (int indexToInsertAt,
ObjectClass* const newObject) noexcept
{
if (indexToInsertAt >= 0)
{
Expand All @@ -337,10 +339,12 @@ class ReferenceCountedArray
newObject->incReferenceCount();

++numUsed;

return newObject;
}
else
{
add (newObject);
return add (newObject);
}
}

Expand Down Expand Up @@ -847,11 +851,11 @@ class ReferenceCountedArray
/** Returns the type of scoped lock to use for locking this array */
typedef typename TypeOfCriticalSectionToUse::ScopedLockType ScopedLockType;


private:
//==============================================================================
ArrayAllocationBase <ObjectClass*, TypeOfCriticalSectionToUse> data;
int numUsed;
};

#endif // BEAST_REFERENCECOUNTEDARRAY_BEASTHEADER

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void findMinAndMax (const Type* values, int numValues, Type& lowest, Type& highe
@param valueToConstrain the value to try to return
@returns the closest value to valueToConstrain which lies between lowerLimit
and upperLimit (inclusive)
@see jlimit0To, bmin, bmax
@see blimit0To, bmin, bmax
*/
template <typename Type>
inline Type blimit (const Type lowerLimit,
Expand Down
12 changes: 8 additions & 4 deletions Subtrees/beast/modules/beast_core/memory/beast_Atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,14 @@ class Atomic
volatile Type value;

private:
static inline Type castFrom32Bit (int32 value) noexcept { return *(Type*) &value; }
static inline Type castFrom64Bit (int64 value) noexcept { return *(Type*) &value; }
static inline int32 castTo32Bit (Type value) noexcept { return *(int32*) &value; }
static inline int64 castTo64Bit (Type value) noexcept { return *(int64*) &value; }
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
16 changes: 14 additions & 2 deletions Subtrees/beast/modules/beast_core/memory/beast_SharedSingleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ class BEAST_API SingletonLifetime

/** The singleton is created on first use and persists until program exit.
*/
persistAfterCreation
persistAfterCreation,

/** The singleton is created when needed and never destroyed.

This is useful for applications which do not have a clean exit.
*/
neverDestroyed
};
};

Expand All @@ -82,7 +88,8 @@ class SharedSingleton
{
bassert (s_instance == nullptr);

if (m_lifetime == persistAfterCreation)
if (m_lifetime == persistAfterCreation ||
m_lifetime == neverDestroyed)
{
incReferenceCount ();
}
Expand Down Expand Up @@ -155,6 +162,9 @@ class SharedSingleton
{
bool destroy;

// Handle the condition where one thread is releasing the last
// reference just as another thread is trying to acquire it.
//
{
LockType::ScopedLockType lock (*s_mutex);

Expand All @@ -171,6 +181,8 @@ class SharedSingleton

if (destroy)
{
bassert (m_lifetime != neverDestroyed);

delete this;
}
}
Expand Down
Loading