diff options
author | Mike Buland <mike@xagasoft.com> | 2024-09-26 14:43:22 -0700 |
---|---|---|
committer | Mike Buland <mike@xagasoft.com> | 2024-09-26 14:43:22 -0700 |
commit | 76821551f312dd447a03748a01670f3718cd8345 (patch) | |
tree | aca702a69c9eb3f7dd8080dcd20d7f238bbbaa81 /src/stable | |
parent | d5e966a0563e3f01c02c3cfb1f3a83fec852168b (diff) | |
download | libbu++-76821551f312dd447a03748a01670f3718cd8345.tar.gz libbu++-76821551f312dd447a03748a01670f3718cd8345.tar.bz2 libbu++-76821551f312dd447a03748a01670f3718cd8345.tar.xz libbu++-76821551f312dd447a03748a01670f3718cd8345.zip |
Basic update to new API for existing components.
This may not all work yet, but it all compiles!
Diffstat (limited to 'src/stable')
-rw-r--r-- | src/stable/myriad.cpp | 21 | ||||
-rw-r--r-- | src/stable/myriad.h | 24 | ||||
-rw-r--r-- | src/stable/myriadstream.cpp | 6 | ||||
-rw-r--r-- | src/stable/myriadstream.h | 1 |
4 files changed, 49 insertions, 3 deletions
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, | |||
74 | mhStream.unlock(); | 74 | mhStream.unlock(); |
75 | bStructureChanged = true; | 75 | bStructureChanged = true; |
76 | 76 | ||
77 | return Bu::MyriadStream( *this, pStream, (Mode)(eMode&ReadWrite) ); | 77 | return Bu::MyriadStream( *this, pStream, eMode&ReadWrite ); |
78 | } | 78 | } |
79 | 79 | ||
80 | Bu::MyriadStream Bu::Myriad::open( Bu::Myriad::StreamId iStream, | 80 | Bu::MyriadStream Bu::Myriad::open( Bu::Myriad::StreamId iStream, |
@@ -144,6 +144,18 @@ void Bu::Myriad::setSize( Bu::Myriad::StreamId iStream, | |||
144 | pStream->setSize( iNewSize ); | 144 | pStream->setSize( iNewSize ); |
145 | } | 145 | } |
146 | 146 | ||
147 | int32_t Bu::Myriad::getSize( StreamId iStream ) const | ||
148 | { | ||
149 | Bu::MutexLocker l( mhStream ); | ||
150 | return hStream.get( iStream )->getSize(); | ||
151 | } | ||
152 | |||
153 | bool Bu::Myriad::exists( StreamId iStream ) const | ||
154 | { | ||
155 | Bu::MutexLocker l( mhStream ); | ||
156 | return hStream.has( iStream ); | ||
157 | } | ||
158 | |||
147 | Bu::String Bu::Myriad::getLocation() const | 159 | Bu::String Bu::Myriad::getLocation() const |
148 | { | 160 | { |
149 | Bu::MutexLocker l( mAccess ); | 161 | Bu::MutexLocker l( mAccess ); |
@@ -218,6 +230,11 @@ int32_t Bu::Myriad::getTotalUnusedBytes(int32_t iAssumeBlockSize ) const | |||
218 | return iTotal; | 230 | return iTotal; |
219 | } | 231 | } |
220 | 232 | ||
233 | void Bu::Myriad::sync() | ||
234 | { | ||
235 | writeHeader(); | ||
236 | } | ||
237 | |||
221 | bool Bu::Myriad::loadMyriad() | 238 | bool Bu::Myriad::loadMyriad() |
222 | { | 239 | { |
223 | Bu::println("Load myriad!"); | 240 | Bu::println("Load myriad!"); |
@@ -417,12 +434,12 @@ void Bu::Myriad::createMyriad( int32_t iBlockSize, int32_t iPreallocateBlocks ) | |||
417 | 434 | ||
418 | void Bu::Myriad::writeHeader() | 435 | void Bu::Myriad::writeHeader() |
419 | { | 436 | { |
437 | Bu::MutexLocker l( mAccess ); | ||
420 | if( !rBacking.isWritable() ) | 438 | if( !rBacking.isWritable() ) |
421 | return; | 439 | return; |
422 | Bu::println("Writing stream breakdown:"); | 440 | Bu::println("Writing stream breakdown:"); |
423 | Bu::MemBuf mbHeader; | 441 | Bu::MemBuf mbHeader; |
424 | { | 442 | { |
425 | Bu::MutexLocker l( mAccess ); | ||
426 | Bu::MutexLocker l2( mhStream ); | 443 | Bu::MutexLocker l2( mhStream ); |
427 | 444 | ||
428 | int32_t iHdrStreamSize = __calcHeaderSize(); | 445 | 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 | |||
32 | { | 32 | { |
33 | public: | 33 | public: |
34 | typedef int32_t StreamId; | 34 | typedef int32_t StreamId; |
35 | enum Mode { | 35 | enum Mode : int32_t { |
36 | None = 0x00, | 36 | None = 0x00, |
37 | 37 | ||
38 | // Flags | 38 | // Flags |
@@ -75,6 +75,8 @@ namespace Bu | |||
75 | MyriadStream open( StreamId iStream, Mode eMode ); | 75 | MyriadStream open( StreamId iStream, Mode eMode ); |
76 | void erase( StreamId iStream ); | 76 | void erase( StreamId iStream ); |
77 | void setSize( StreamId iStream, int32_t iNewSize ); | 77 | void setSize( StreamId iStream, int32_t iNewSize ); |
78 | int32_t getSize( StreamId iStream ) const; | ||
79 | bool exists( StreamId iStream ) const; | ||
78 | Bu::String getLocation() const; | 80 | Bu::String getLocation() const; |
79 | int32_t getBlockSize() const; | 81 | int32_t getBlockSize() const; |
80 | int32_t getTotalBlocks() const; | 82 | int32_t getTotalBlocks() const; |
@@ -84,6 +86,12 @@ namespace Bu | |||
84 | int32_t getTotalUsedBytes() const; | 86 | int32_t getTotalUsedBytes() const; |
85 | int32_t getTotalUnusedBytes( int32_t iAssumeBlockSize=-1 ) const; | 87 | int32_t getTotalUnusedBytes( int32_t iAssumeBlockSize=-1 ) const; |
86 | 88 | ||
89 | /** | ||
90 | * Flush all caches to the backing stream, write all structural and | ||
91 | * header changes. | ||
92 | */ | ||
93 | void sync(); | ||
94 | |||
87 | private: | 95 | private: |
88 | bool loadMyriad(); | 96 | bool loadMyriad(); |
89 | void createMyriad( int32_t iBlockSize, int32_t iPreallocateBlocks ); | 97 | void createMyriad( int32_t iBlockSize, int32_t iPreallocateBlocks ); |
@@ -175,6 +183,20 @@ namespace Bu | |||
175 | IndexList lFreeBlocks; | 183 | IndexList lFreeBlocks; |
176 | StreamId iLastUsedIndex; | 184 | StreamId iLastUsedIndex; |
177 | }; | 185 | }; |
186 | constexpr Myriad::Mode operator&( Myriad::Mode a, Myriad::Mode b ) | ||
187 | { | ||
188 | return static_cast<Myriad::Mode>( | ||
189 | static_cast<std::underlying_type<Myriad::Mode>::type>(a) & | ||
190 | static_cast<std::underlying_type<Myriad::Mode>::type>(b) | ||
191 | ); | ||
192 | } | ||
193 | constexpr Myriad::Mode operator|( Myriad::Mode a, Myriad::Mode b ) | ||
194 | { | ||
195 | return static_cast<Myriad::Mode>( | ||
196 | static_cast<std::underlying_type<Myriad::Mode>::type>(a) | | ||
197 | static_cast<std::underlying_type<Myriad::Mode>::type>(b) | ||
198 | ); | ||
199 | } | ||
178 | }; | 200 | }; |
179 | 201 | ||
180 | #endif | 202 | #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 | |||
166 | return pStream->getLocation(); | 166 | return pStream->getLocation(); |
167 | } | 167 | } |
168 | 168 | ||
169 | Bu::Myriad::StreamId Bu::MyriadStream::getId() const | ||
170 | { | ||
171 | Bu::MutexLocker l( mAccess ); | ||
172 | return pStream->getStreamId(); | ||
173 | } | ||
174 | |||
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 | |||
39 | virtual size getSize() const; | 39 | virtual size getSize() const; |
40 | virtual size getBlockSize() const; | 40 | virtual size getBlockSize() const; |
41 | virtual Bu::String getLocation() const; | 41 | virtual Bu::String getLocation() const; |
42 | Myriad::StreamId getId() const; | ||
42 | 43 | ||
43 | private: | 44 | private: |
44 | mutable Bu::Mutex mAccess; | 45 | mutable Bu::Mutex mAccess; |