diff options
author | Mike Buland <mike@xagasoft.com> | 2024-10-03 11:28:44 -0700 |
---|---|---|
committer | Mike Buland <mike@xagasoft.com> | 2024-10-03 11:28:44 -0700 |
commit | 6403224b6fe50dfc28d3c25725b6d0910b7eb6c3 (patch) | |
tree | 015d35db7a0a3cbcc72487a1df0d59e5c4e685bf /src/stable | |
parent | 7487eea1b802bf0f45afcef5807251049b034dd8 (diff) | |
download | libbu++-6403224b6fe50dfc28d3c25725b6d0910b7eb6c3.tar.gz libbu++-6403224b6fe50dfc28d3c25725b6d0910b7eb6c3.tar.bz2 libbu++-6403224b6fe50dfc28d3c25725b6d0910b7eb6c3.tar.xz libbu++-6403224b6fe50dfc28d3c25725b6d0910b7eb6c3.zip |
Minor tweaks/additions.
Now to fix MyriadFs
Diffstat (limited to '')
-rw-r--r-- | src/stable/myriad.cpp | 30 | ||||
-rw-r--r-- | src/stable/myriad.h | 49 |
2 files changed, 74 insertions, 5 deletions
diff --git a/src/stable/myriad.cpp b/src/stable/myriad.cpp index 5e511fd..492676e 100644 --- a/src/stable/myriad.cpp +++ b/src/stable/myriad.cpp | |||
@@ -129,6 +129,19 @@ Bu::MyriadStream Bu::Myriad::open( Bu::Myriad::StreamId iStream, | |||
129 | return Bu::MyriadStream( *this, pStream, eMode ); | 129 | return Bu::MyriadStream( *this, pStream, eMode ); |
130 | } | 130 | } |
131 | 131 | ||
132 | Bu::Myriad::StreamId Bu::Myriad::allocate() | ||
133 | { | ||
134 | Bu::MutexLocker l( mAccess ); | ||
135 | |||
136 | Stream *pStream = new Stream( *this, ++iLastUsedIndex, 0 ); | ||
137 | mhStream.lock(); | ||
138 | hStream.insert( pStream->iStream, pStream ); | ||
139 | mhStream.unlock(); | ||
140 | bStructureChanged = true; | ||
141 | |||
142 | return pStream->iStream; | ||
143 | } | ||
144 | |||
132 | void Bu::Myriad::erase( Bu::Myriad::StreamId iStream ) | 145 | void Bu::Myriad::erase( Bu::Myriad::StreamId iStream ) |
133 | { | 146 | { |
134 | // For now, let's prevent you from erasing a stream if it's open. | 147 | // For now, let's prevent you from erasing a stream if it's open. |
@@ -252,6 +265,19 @@ int32_t Bu::Myriad::getTotalUnusedBytes(int32_t iAssumeBlockSize ) const | |||
252 | return iTotal; | 265 | return iTotal; |
253 | } | 266 | } |
254 | 267 | ||
268 | Bu::Myriad::StreamIdList Bu::Myriad::getStreamList() const | ||
269 | { | ||
270 | mhStream.lock(); | ||
271 | StreamIdList lIds = hStream.getKeys(); | ||
272 | mhStream.unlock(); | ||
273 | lIds.sort(); | ||
274 | if( lIds.first() == 0 ) | ||
275 | { | ||
276 | lIds.eraseFirst(); | ||
277 | } | ||
278 | return lIds; | ||
279 | } | ||
280 | |||
255 | Bu::BitString Bu::Myriad::buildBlockUseMap() const | 281 | Bu::BitString Bu::Myriad::buildBlockUseMap() const |
256 | { | 282 | { |
257 | Bu::MutexLocker l( mAccess ); | 283 | Bu::MutexLocker l( mAccess ); |
@@ -264,10 +290,10 @@ Bu::BitString Bu::Myriad::buildBlockUseMap() const | |||
264 | return bsMap; | 290 | return bsMap; |
265 | } | 291 | } |
266 | 292 | ||
267 | Bu::Array<int32_t> Bu::Myriad::buildBlockMap() const | 293 | Bu::Myriad::StreamIdArray Bu::Myriad::buildBlockMap() const |
268 | { | 294 | { |
269 | Bu::MutexLocker l( mAccess ); | 295 | Bu::MutexLocker l( mAccess ); |
270 | Bu::Array<int32_t> bm( iBlockCount ); | 296 | StreamIdArray bm( iBlockCount ); |
271 | for( int j = 0; j < iBlockCount; j++ ) | 297 | for( int j = 0; j < iBlockCount; j++ ) |
272 | { | 298 | { |
273 | bm.append( -1 ); | 299 | bm.append( -1 ); |
diff --git a/src/stable/myriad.h b/src/stable/myriad.h index 6168aa2..5accd1e 100644 --- a/src/stable/myriad.h +++ b/src/stable/myriad.h | |||
@@ -31,10 +31,20 @@ namespace Bu | |||
31 | }; | 31 | }; |
32 | subExceptionDeclEnd(); | 32 | subExceptionDeclEnd(); |
33 | 33 | ||
34 | /** | ||
35 | * Myriad Stream Multiplexer. This is a system that allows you to store | ||
36 | * many streams within a single backing stream. This is great for databases, | ||
37 | * caching, etc. It's fairly lightweight, and allows all streams to grow | ||
38 | * dynamically using a block-allocation scheme. This is used extensively | ||
39 | * by the caching system and MyriadFs as well as other systems within | ||
40 | * libbu++. | ||
41 | */ | ||
34 | class Myriad | 42 | class Myriad |
35 | { | 43 | { |
36 | public: | 44 | public: |
37 | typedef int32_t StreamId; | 45 | typedef int32_t StreamId; |
46 | typedef Bu::Array<StreamId> StreamIdArray; | ||
47 | typedef Bu::List<StreamId> StreamIdList; | ||
38 | enum Mode : int32_t { | 48 | enum Mode : int32_t { |
39 | None = 0x00, | 49 | None = 0x00, |
40 | 50 | ||
@@ -55,8 +65,9 @@ namespace Bu | |||
55 | 65 | ||
56 | public: | 66 | public: |
57 | /** | 67 | /** |
58 | * Open existing Myriad stream, or initialize a new one if it doesn't | 68 | * Open existing Myriad container, or initialize a new one if the |
59 | * exist. | 69 | * backing stream is empty. If other data is already in the provided |
70 | * backing stream an error is thrown. | ||
60 | * | 71 | * |
61 | * Myriad format V0 | 72 | * Myriad format V0 |
62 | * 0 - 3: Myriad_MAGIC_CODE (0ad3fa84) | 73 | * 0 - 3: Myriad_MAGIC_CODE (0ad3fa84) |
@@ -75,8 +86,32 @@ namespace Bu | |||
75 | int32_t iPreallocateBlocks=-1 ); | 86 | int32_t iPreallocateBlocks=-1 ); |
76 | virtual ~Myriad(); | 87 | virtual ~Myriad(); |
77 | 88 | ||
89 | /** | ||
90 | * Creates a new stream open in the specified eMode and, optionally, | ||
91 | * preallocates the specificed amount of space. The stream is zero | ||
92 | * bytes even if space is preallocated. The open stream is returned, | ||
93 | * ready for use. Use this if you don't care what the id is of the | ||
94 | * newly created stream. | ||
95 | */ | ||
78 | MyriadStream create( Mode eMode, int32_t iPreallocateBytes=-1 ); | 96 | MyriadStream create( Mode eMode, int32_t iPreallocateBytes=-1 ); |
97 | |||
98 | /** | ||
99 | * Open an existing stream or create a new stream with the specified | ||
100 | * id (iStream) with the specified eMode. This respects the normal file | ||
101 | * modes, see Bu::Myriad::Mode for details. | ||
102 | */ | ||
79 | MyriadStream open( StreamId iStream, Mode eMode ); | 103 | MyriadStream open( StreamId iStream, Mode eMode ); |
104 | |||
105 | /** | ||
106 | * Allocate a new stream but do not open it, just ensure it exists and | ||
107 | * return the id of the newly allocated stream. | ||
108 | */ | ||
109 | StreamId allocate(); | ||
110 | |||
111 | /** | ||
112 | * Erase the stream specified by iStream. This only can work when the | ||
113 | * stream is not open at the moment. | ||
114 | */ | ||
80 | void erase( StreamId iStream ); | 115 | void erase( StreamId iStream ); |
81 | void setSize( StreamId iStream, int32_t iNewSize ); | 116 | void setSize( StreamId iStream, int32_t iNewSize ); |
82 | int32_t getSize( StreamId iStream ) const; | 117 | int32_t getSize( StreamId iStream ) const; |
@@ -90,7 +125,15 @@ namespace Bu | |||
90 | int32_t getTotalUsedBytes() const; | 125 | int32_t getTotalUsedBytes() const; |
91 | int32_t getTotalUnusedBytes( int32_t iAssumeBlockSize=-1 ) const; | 126 | int32_t getTotalUnusedBytes( int32_t iAssumeBlockSize=-1 ) const; |
92 | Bu::BitString buildBlockUseMap() const; | 127 | Bu::BitString buildBlockUseMap() const; |
93 | Bu::Array<int32_t> buildBlockMap() const; | 128 | StreamIdArray buildBlockMap() const; |
129 | |||
130 | /** | ||
131 | * Lists all stream ids that you are allowed to open. Technically there | ||
132 | * is always a zero stream, but it is used by Myriad for stream/block | ||
133 | * accounting. It works like a normal stream but you should not open | ||
134 | * it. | ||
135 | */ | ||
136 | StreamIdList getStreamList() const; | ||
94 | 137 | ||
95 | /** | 138 | /** |
96 | * Flush all caches to the backing stream, write all structural and | 139 | * Flush all caches to the backing stream, write all structural and |