remold the buffer metadata into a PImple used by BufferProvider
This commit is contained in:
parent
8a2c94014c
commit
1ea3cba2f5
5 changed files with 89 additions and 48 deletions
|
|
@ -55,16 +55,27 @@
|
|||
|
||||
|
||||
#include "lib/error.hpp"
|
||||
#include "lib/symbol.hpp"
|
||||
|
||||
//#include <boost/noncopyable.hpp>
|
||||
|
||||
|
||||
namespace engine {
|
||||
|
||||
using lib::Literal;
|
||||
|
||||
|
||||
typedef uint64_t LocalKey;
|
||||
typedef size_t HashVal;
|
||||
|
||||
enum BufferState
|
||||
{ NIL,
|
||||
FREE,
|
||||
LOCKED,
|
||||
EMITTED,
|
||||
BLOCKED
|
||||
};
|
||||
|
||||
const LocalKey UNSPECIFIC = 0;
|
||||
|
||||
struct TypeHandler
|
||||
|
|
@ -93,7 +104,17 @@ namespace engine {
|
|||
class Metadata
|
||||
{
|
||||
public:
|
||||
static HashVal
|
||||
struct Entry
|
||||
{
|
||||
BufferState state () const;
|
||||
Entry& mark (BufferState newState);
|
||||
};
|
||||
|
||||
|
||||
Metadata (Literal implementationID)
|
||||
{ }
|
||||
|
||||
HashVal
|
||||
key ( size_t storageSize
|
||||
, TypeHandler instanceFunc =RAW_BUFFER
|
||||
, LocalKey specifics =UNSPECIFIC)
|
||||
|
|
@ -101,24 +122,14 @@ namespace engine {
|
|||
UNIMPLEMENTED ("combine the distinguishing properties into a single hash");
|
||||
}
|
||||
|
||||
static Metadata&
|
||||
Entry&
|
||||
get (HashVal key)
|
||||
{
|
||||
UNIMPLEMENTED ("access, possibly create metadata records");
|
||||
}
|
||||
|
||||
BufferState
|
||||
state () const
|
||||
{
|
||||
UNIMPLEMENTED ("buffer state accounting");
|
||||
}
|
||||
|
||||
Metadata&
|
||||
mark (BufferState newState)
|
||||
{
|
||||
UNIMPLEMENTED ("buffer state transitions");
|
||||
return *this;
|
||||
}
|
||||
#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #834
|
||||
#endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #834
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -127,6 +138,18 @@ namespace engine {
|
|||
/* === Implementation === */
|
||||
|
||||
/** */
|
||||
BufferState
|
||||
Metadata::Entry::state () const
|
||||
{
|
||||
UNIMPLEMENTED ("buffer state accounting");
|
||||
}
|
||||
|
||||
Metadata::Entry&
|
||||
Metadata::Entry::mark (BufferState newState)
|
||||
{
|
||||
UNIMPLEMENTED ("buffer state transitions");
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,11 @@ namespace engine {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
BufferProvider::BufferProvider (Literal implementationID)
|
||||
: meta_(new Metadata (implementationID))
|
||||
{ }
|
||||
|
||||
BufferProvider::~BufferProvider() { }
|
||||
|
||||
|
||||
|
|
@ -52,7 +56,7 @@ namespace engine {
|
|||
BufferDescriptor
|
||||
BufferProvider::getDescriptorFor (size_t storageSize)
|
||||
{
|
||||
return BufferDescriptor (*this, Metadata::key (storageSize));
|
||||
return BufferDescriptor (*this, meta_->key (storageSize));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -43,21 +43,20 @@
|
|||
|
||||
|
||||
#include "lib/error.hpp"
|
||||
#include "lib/symbol.hpp"
|
||||
#include "proc/engine/buffhandle.hpp"
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
|
||||
namespace engine {
|
||||
|
||||
using boost::scoped_ptr;
|
||||
using lib::Literal;
|
||||
|
||||
enum BufferState
|
||||
{ NIL,
|
||||
FREE,
|
||||
LOCKED,
|
||||
EMITTED,
|
||||
BLOCKED
|
||||
};
|
||||
|
||||
class Metadata;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -72,6 +71,10 @@ namespace engine {
|
|||
class BufferProvider
|
||||
: boost::noncopyable
|
||||
{
|
||||
scoped_ptr<Metadata> meta_;
|
||||
|
||||
protected:
|
||||
BufferProvider (Literal implementationID);
|
||||
|
||||
public:
|
||||
virtual ~BufferProvider(); ///< this is an interface
|
||||
|
|
|
|||
|
|
@ -111,8 +111,8 @@ namespace engine {
|
|||
|
||||
public:
|
||||
HeapMemProvider()
|
||||
{
|
||||
}
|
||||
: BufferProvider ("Diagnostic_HeapAllocated")
|
||||
{ }
|
||||
|
||||
virtual ~HeapMemProvider()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@
|
|||
//#include "proc/engine/bufftable.hpp"
|
||||
|
||||
//#include <boost/format.hpp>
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include <cstdlib>
|
||||
//#include <iostream>
|
||||
|
||||
|
|
@ -41,6 +42,7 @@
|
|||
//using std::string;
|
||||
//using std::cout;
|
||||
//using util::for_each;
|
||||
using boost::scoped_ptr;
|
||||
using util::isnil;
|
||||
using util::isSameObject;
|
||||
|
||||
|
|
@ -48,6 +50,7 @@ using util::isSameObject;
|
|||
namespace engine{
|
||||
namespace test {
|
||||
|
||||
|
||||
// using lib::AllocationCluster;
|
||||
// using mobject::session::PEffect;
|
||||
// using ::engine::BuffHandle;
|
||||
|
|
@ -59,21 +62,13 @@ namespace test {
|
|||
|
||||
const size_t TEST_MAX_SIZE = 1024 * 1024;
|
||||
|
||||
const size_t SIZE_A = 1 + rand() % TEST_MAX_SIZE
|
||||
const size_t SIZE_B = 1 + rand() % TEST_MAX_SIZE
|
||||
const size_t SIZE_A = 1 + rand() % TEST_MAX_SIZE;
|
||||
const size_t SIZE_B = 1 + rand() % TEST_MAX_SIZE;
|
||||
|
||||
const HashVal JUST_SOMETHING = 123;
|
||||
// const uint TEST_SIZE = 1024*1024;
|
||||
// const uint TEST_ELMS = 20;
|
||||
|
||||
bool
|
||||
ensure_proper_fixture()
|
||||
{
|
||||
return (SIZE_A != SIZE_B)
|
||||
&& (JUST_SOMETHING != Metadata::key(SIZE_A))
|
||||
&& (JUST_SOMETHING != Metadata::key(SIZE_B))
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -85,6 +80,9 @@ namespace test {
|
|||
*/
|
||||
class BufferMetadata_test : public Test
|
||||
{
|
||||
/** common Metadata table to be tested */
|
||||
scoped_ptr<Metadata> meta_;
|
||||
|
||||
virtual void
|
||||
run (Arg)
|
||||
{
|
||||
|
|
@ -95,37 +93,50 @@ namespace test {
|
|||
}
|
||||
|
||||
|
||||
bool
|
||||
ensure_proper_fixture()
|
||||
{
|
||||
if (!meta_)
|
||||
meta_.reset(new Metadata("BufferMetadata_test"));
|
||||
|
||||
return (SIZE_A != SIZE_B)
|
||||
&& (JUST_SOMETHING != meta_->key(SIZE_A))
|
||||
&& (JUST_SOMETHING != meta_->key(SIZE_B))
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
verifyBasicProperties()
|
||||
{
|
||||
HashVal key = Metadata::key(SIZE_A);
|
||||
HashVal key = meta_->key(SIZE_A);
|
||||
CHECK (key);
|
||||
|
||||
HashVal key1 = Metadata::key(SIZE_A);
|
||||
HashVal key2 = Metadata::key(SIZE_B);
|
||||
HashVal key1 = meta_->key(SIZE_A);
|
||||
HashVal key2 = meta_->key(SIZE_B);
|
||||
CHECK (key1);
|
||||
CHECK (key2);
|
||||
CHECK (key == key1);
|
||||
CHECK (key != key2);
|
||||
|
||||
VERIFY_ERROR (INVALID, Metadata::get(0))
|
||||
VERIFY_ERROR (INVALID, Metadata::get(JUST_SOMETHING));
|
||||
CHECK ( & Metadata::get(key));
|
||||
CHECK ( & Metadata::get(key1));
|
||||
CHECK ( & Metadata::get(key2));
|
||||
VERIFY_ERROR (INVALID, meta_->get(0))
|
||||
VERIFY_ERROR (INVALID, meta_->get(JUST_SOMETHING));
|
||||
CHECK ( & meta_->get(key));
|
||||
CHECK ( & meta_->get(key1));
|
||||
CHECK ( & meta_->get(key2));
|
||||
|
||||
CHECK ( isSameObject (Metadata::get(key), Metadata::get(key)));
|
||||
CHECK ( isSameObject (Metadata::get(key), Metadata::get(key1)));
|
||||
CHECK (!isSameObject (Metadata::get(key), Metadata::get(key2)));
|
||||
CHECK ( isSameObject (meta_->get(key), meta_->get(key)));
|
||||
CHECK ( isSameObject (meta_->get(key), meta_->get(key1)));
|
||||
CHECK (!isSameObject (meta_->get(key), meta_->get(key2)));
|
||||
|
||||
Metadata& m1 = Metadata::get(key);
|
||||
Metadata::Entry& m1 = meta_->get(key);
|
||||
CHECK (NIL == m1.state());
|
||||
|
||||
VERIFY_ERROR (LIFECYCLE, m1.mark(EMITTED) );
|
||||
|
||||
m1.mark (LOCKED);
|
||||
CHECK (LOCKED == m1.state());
|
||||
CHECK (LOCKED == Metadata::get(key1).state());
|
||||
CHECK (LOCKED == meta_->get(key1).state());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue