1
0
forked from Alepha/Alepha

Bring in the mockination work and Truss from old.

It's all a mess -- not in the new unified form and namespace.
I need to do a big cleanup pass.
This commit is contained in:
2023-02-09 21:30:38 -08:00
parent 306d2145a3
commit fd6060be17
21 changed files with 1898 additions and 0 deletions

View File

@ -0,0 +1,20 @@
CPPFLAGS+= -I ../../../
CXXFLAGS+= -std=c++1z
CXXFLAGS+= -g -O0
#CXXFLAGS+= -O3
CXX=clang++
#LDLIBS+= -lboost_thread -lboost_system
CC=clang++
TESTS=test0 test1
all: $(TESTS)
HEADERS= ../memory.h ../../Mockination/MockFunction.h Makefile
test0.o: $(HEADERS)
test1.o: $(HEADERS)
clean:
rm -f *.o $(TESTS)

View File

@ -0,0 +1,51 @@
#include <Alepha/Atomic/Turnstile.h>
using Alepha::Atomic::Turnstile;
int
main()
{
}
namespace
{
namespace example1
{
//! [TurnstileExamples example1]
// Assume that the below code will run multithreaded
Turnstile myArena{ 8 };
void
mainLoop()
{
Turnstile::ScopedUsage active( myArena );
printf( "I am running in the arena, not everyone can." );
sleep( 100 );
}
//! [TurnstileExamples example1]
} // namespace example1
namespace example2
{
//! [TurnstileExamples example2]
Turnstile myArena{ 8 };
class Worker
{
public:
Worker()
{
myArena.enter();
}
// Assume some useful functionality
// The worker will destroy his access upon leaving
~Worker()
{
myArena.egress();
}
};
//! [TurnstileExamples example2]
} // namespace example2
} // namespace

View File

@ -0,0 +1,63 @@
#include <Alepha/Truss/memory.h>
#include <Alepha/assert.h>
#include <Alepha/Mockination/MockFunction.h>
namespace
{
inline namespace Test0
{
static void runTests();
}
}
int
main()
{
runTests();
}
namespace
{
static void
simple_unique_ptr_test()
{
auto p= Alepha::Truss::make_unique< std::string >( "Hello" );
Alepha::Truss::unique_ptr< std::string > p2= std::move( p );
p= Alepha::Truss::make_unique< std::string >( "Hello" );
using std::swap;
swap( p, p2 );
}
static void
unique_ptr_usage_test()
{
auto p= Alepha::Truss::make_unique< std::string >( "Hello" );
std::string &s= *p;
std::size_t len= p->size();
}
static void
unique_ptr_capture_test()
{
auto p= Alepha::Truss::make_unique< std::string >( "Hello" );
Alepha::single_ptr< std::string > s= p.get_raw();
Alepha::Truss::ref_ptr< std::string > sp= p.get();
}
static void
Test0::runTests()
{
simple_unique_ptr_test();
unique_ptr_usage_test();
unique_ptr_capture_test();
}
}

View File

@ -0,0 +1,39 @@
#include <Alepha/Truss/memory.h>
#include <Alepha/assert.h>
#include <Alepha/Mockination/MockFunction.h>
namespace
{
inline namespace Test1
{
static void runTests();
}
}
int
main()
{
runTests();
}
namespace
{
static void
unique_ptr_to_ref_ptr()
{
auto p= Alepha::Truss::make_unique< std::string >( "Hello" );
Alepha::Truss::ref_ptr< std::string > r= p.get();
Alepha::Truss::ref_ptr< std::string > r2= r;
}
static void
Test1::runTests()
{
unique_ptr_to_ref_ptr();
}
}

View File

@ -0,0 +1,39 @@
#include <Alepha/Truss/memory.h>
#include <Alepha/assert.h>
#include <Alepha/Mockination/MockFunction.h>
namespace
{
inline namespace Test1
{
static void runTests();
}
}
int
main()
{
runTests();
}
namespace
{
static void
unique_ptr_to_ref_ptr()
{
auto p= Alepha::Truss::make_unique< std::string >( "Hello" );
Alepha::Truss::ref_ptr< std::string > r= p.get();
Alepha::Truss::ref_ptr< std::string > r2= r;
}
static void
Test1::runTests()
{
unique_ptr_to_ref_ptr();
}
}