From 76821551f312dd447a03748a01670f3718cd8345 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 26 Sep 2024 14:43:22 -0700 Subject: Basic update to new API for existing components. This may not all work yet, but it all compiles! --- src/stable/myriad.cpp | 21 +++++++++++++++++++-- src/stable/myriad.h | 24 +++++++++++++++++++++++- src/stable/myriadstream.cpp | 6 ++++++ src/stable/myriadstream.h | 1 + 4 files changed, 49 insertions(+), 3 deletions(-) (limited to 'src/stable') diff --git a/src/stable/myriad.cpp b/src/stable/myriad.cpp index 1bf2301..0bd2ff2 100644 --- a/src/stable/myriad.cpp +++ b/src/stable/myriad.cpp @@ -74,7 +74,7 @@ Bu::MyriadStream Bu::Myriad::create( Bu::Myriad::Mode eMode, mhStream.unlock(); bStructureChanged = true; - return Bu::MyriadStream( *this, pStream, (Mode)(eMode&ReadWrite) ); + return Bu::MyriadStream( *this, pStream, eMode&ReadWrite ); } Bu::MyriadStream Bu::Myriad::open( Bu::Myriad::StreamId iStream, @@ -144,6 +144,18 @@ void Bu::Myriad::setSize( Bu::Myriad::StreamId iStream, pStream->setSize( iNewSize ); } +int32_t Bu::Myriad::getSize( StreamId iStream ) const +{ + Bu::MutexLocker l( mhStream ); + return hStream.get( iStream )->getSize(); +} + +bool Bu::Myriad::exists( StreamId iStream ) const +{ + Bu::MutexLocker l( mhStream ); + return hStream.has( iStream ); +} + Bu::String Bu::Myriad::getLocation() const { Bu::MutexLocker l( mAccess ); @@ -218,6 +230,11 @@ int32_t Bu::Myriad::getTotalUnusedBytes(int32_t iAssumeBlockSize ) const return iTotal; } +void Bu::Myriad::sync() +{ + writeHeader(); +} + bool Bu::Myriad::loadMyriad() { Bu::println("Load myriad!"); @@ -417,12 +434,12 @@ void Bu::Myriad::createMyriad( int32_t iBlockSize, int32_t iPreallocateBlocks ) void Bu::Myriad::writeHeader() { + Bu::MutexLocker l( mAccess ); if( !rBacking.isWritable() ) return; Bu::println("Writing stream breakdown:"); Bu::MemBuf mbHeader; { - Bu::MutexLocker l( mAccess ); Bu::MutexLocker l2( mhStream ); int32_t iHdrStreamSize = __calcHeaderSize(); diff --git a/src/stable/myriad.h b/src/stable/myriad.h index 58f700a..c3f682d 100644 --- a/src/stable/myriad.h +++ b/src/stable/myriad.h @@ -32,7 +32,7 @@ namespace Bu { public: typedef int32_t StreamId; - enum Mode { + enum Mode : int32_t { None = 0x00, // Flags @@ -75,6 +75,8 @@ namespace Bu MyriadStream open( StreamId iStream, Mode eMode ); void erase( StreamId iStream ); void setSize( StreamId iStream, int32_t iNewSize ); + int32_t getSize( StreamId iStream ) const; + bool exists( StreamId iStream ) const; Bu::String getLocation() const; int32_t getBlockSize() const; int32_t getTotalBlocks() const; @@ -84,6 +86,12 @@ namespace Bu int32_t getTotalUsedBytes() const; int32_t getTotalUnusedBytes( int32_t iAssumeBlockSize=-1 ) const; + /** + * Flush all caches to the backing stream, write all structural and + * header changes. + */ + void sync(); + private: bool loadMyriad(); void createMyriad( int32_t iBlockSize, int32_t iPreallocateBlocks ); @@ -175,6 +183,20 @@ namespace Bu IndexList lFreeBlocks; StreamId iLastUsedIndex; }; + constexpr Myriad::Mode operator&( Myriad::Mode a, Myriad::Mode b ) + { + return static_cast( + static_cast::type>(a) & + static_cast::type>(b) + ); + } + constexpr Myriad::Mode operator|( Myriad::Mode a, Myriad::Mode b ) + { + return static_cast( + static_cast::type>(a) | + static_cast::type>(b) + ); + } }; #endif diff --git a/src/stable/myriadstream.cpp b/src/stable/myriadstream.cpp index 9ea2e17..eaf91a5 100644 --- a/src/stable/myriadstream.cpp +++ b/src/stable/myriadstream.cpp @@ -166,3 +166,9 @@ Bu::String Bu::MyriadStream::getLocation() const return pStream->getLocation(); } +Bu::Myriad::StreamId Bu::MyriadStream::getId() const +{ + Bu::MutexLocker l( mAccess ); + return pStream->getStreamId(); +} + diff --git a/src/stable/myriadstream.h b/src/stable/myriadstream.h index b86dbd7..27a15d5 100644 --- a/src/stable/myriadstream.h +++ b/src/stable/myriadstream.h @@ -39,6 +39,7 @@ namespace Bu virtual size getSize() const; virtual size getBlockSize() const; virtual Bu::String getLocation() const; + Myriad::StreamId getId() const; private: mutable Bu::Mutex mAccess; -- cgit v1.2.3