diff options
| author | Mike Buland <mike@xagasoft.com> | 2024-11-06 16:01:36 -0800 |
|---|---|---|
| committer | Mike Buland <mike@xagasoft.com> | 2024-11-06 16:01:36 -0800 |
| commit | 700d4bbcbf59c4447becbab21a6aa7204a8da2f4 (patch) | |
| tree | ae68c40a5af2d5bc84ac4bbb192fbbda893d64cc /src/unstable | |
| parent | 6403224b6fe50dfc28d3c25725b6d0910b7eb6c3 (diff) | |
| download | libbu++-700d4bbcbf59c4447becbab21a6aa7204a8da2f4.tar.gz libbu++-700d4bbcbf59c4447becbab21a6aa7204a8da2f4.tar.bz2 libbu++-700d4bbcbf59c4447becbab21a6aa7204a8da2f4.tar.xz libbu++-700d4bbcbf59c4447becbab21a6aa7204a8da2f4.zip | |
I believe MyriadFs is now threadsafe.myriad
It could probably be more optimized, but it does work.
Diffstat (limited to 'src/unstable')
| -rw-r--r-- | src/unstable/myriadfs.cpp | 11 | ||||
| -rw-r--r-- | src/unstable/myriadfs.h | 12 |
2 files changed, 20 insertions, 3 deletions
diff --git a/src/unstable/myriadfs.cpp b/src/unstable/myriadfs.cpp index a2386c2..f748a53 100644 --- a/src/unstable/myriadfs.cpp +++ b/src/unstable/myriadfs.cpp | |||
| @@ -108,6 +108,7 @@ Bu::MyriadFs::~MyriadFs() | |||
| 108 | 108 | ||
| 109 | void Bu::MyriadFs::stat( const Bu::String &sPath, Bu::MyriadFs::Stat &rBuf ) | 109 | void Bu::MyriadFs::stat( const Bu::String &sPath, Bu::MyriadFs::Stat &rBuf ) |
| 110 | { | 110 | { |
| 111 | Bu::MutexLocker lLock( mAccess ); | ||
| 111 | int32_t iParent; | 112 | int32_t iParent; |
| 112 | int32_t iNode = lookupInode( sPath, iParent ); | 113 | int32_t iNode = lookupInode( sPath, iParent ); |
| 113 | Bu::MyriadStream is = mStore.open( 2, Bu::Myriad::Read ); | 114 | Bu::MyriadStream is = mStore.open( 2, Bu::Myriad::Read ); |
| @@ -117,6 +118,7 @@ void Bu::MyriadFs::stat( const Bu::String &sPath, Bu::MyriadFs::Stat &rBuf ) | |||
| 117 | Bu::MyriadStream Bu::MyriadFs::open( const Bu::String &sPath, int iMode, | 118 | Bu::MyriadStream Bu::MyriadFs::open( const Bu::String &sPath, int iMode, |
| 118 | uint16_t uPerms ) | 119 | uint16_t uPerms ) |
| 119 | { | 120 | { |
| 121 | Bu::MutexLocker lLock( mAccess ); | ||
| 120 | int32_t iParent = -1; | 122 | int32_t iParent = -1; |
| 121 | int32_t iNode; | 123 | int32_t iNode; |
| 122 | try | 124 | try |
| @@ -165,6 +167,7 @@ void Bu::MyriadFs::create( const Bu::String &sPath, uint16_t iPerms, | |||
| 165 | void Bu::MyriadFs::create( const Bu::String &sPath, uint16_t iPerms, | 167 | void Bu::MyriadFs::create( const Bu::String &sPath, uint16_t iPerms, |
| 166 | uint32_t uSpecial ) | 168 | uint32_t uSpecial ) |
| 167 | { | 169 | { |
| 170 | Bu::MutexLocker lLock( mAccess ); | ||
| 168 | int32_t iParent = -1; | 171 | int32_t iParent = -1; |
| 169 | // int32_t iNode; | 172 | // int32_t iNode; |
| 170 | try | 173 | try |
| @@ -201,6 +204,7 @@ void Bu::MyriadFs::mkDir( const Bu::String &sPath, uint16_t iPerms ) | |||
| 201 | void Bu::MyriadFs::mkSymLink( const Bu::String &sTarget, | 204 | void Bu::MyriadFs::mkSymLink( const Bu::String &sTarget, |
| 202 | const Bu::String &sPath ) | 205 | const Bu::String &sPath ) |
| 203 | { | 206 | { |
| 207 | Bu::MutexLocker lLock( mAccess ); | ||
| 204 | int32_t iParent = -1; | 208 | int32_t iParent = -1; |
| 205 | int32_t iNode; | 209 | int32_t iNode; |
| 206 | try | 210 | try |
| @@ -233,6 +237,7 @@ void Bu::MyriadFs::mkSymLink( const Bu::String &sTarget, | |||
| 233 | void Bu::MyriadFs::mkHardLink( const Bu::String &sTarget, | 237 | void Bu::MyriadFs::mkHardLink( const Bu::String &sTarget, |
| 234 | const Bu::String &sPath ) | 238 | const Bu::String &sPath ) |
| 235 | { | 239 | { |
| 240 | Bu::MutexLocker lLock( mAccess ); | ||
| 236 | int32_t iParent = -1; | 241 | int32_t iParent = -1; |
| 237 | int32_t iNode; | 242 | int32_t iNode; |
| 238 | 243 | ||
| @@ -268,6 +273,7 @@ void Bu::MyriadFs::mkHardLink( const Bu::String &sTarget, | |||
| 268 | 273 | ||
| 269 | Bu::String Bu::MyriadFs::readSymLink( const Bu::String &sPath ) | 274 | Bu::String Bu::MyriadFs::readSymLink( const Bu::String &sPath ) |
| 270 | { | 275 | { |
| 276 | Bu::MutexLocker lLock( mAccess ); | ||
| 271 | int32_t iParent = -1; | 277 | int32_t iParent = -1; |
| 272 | int32_t iNode; | 278 | int32_t iNode; |
| 273 | iNode = lookupInode( sPath, iParent ); | 279 | iNode = lookupInode( sPath, iParent ); |
| @@ -280,6 +286,7 @@ Bu::String Bu::MyriadFs::readSymLink( const Bu::String &sPath ) | |||
| 280 | 286 | ||
| 281 | Bu::MyriadFs::Dir Bu::MyriadFs::readDir( const Bu::String &sPath ) | 287 | Bu::MyriadFs::Dir Bu::MyriadFs::readDir( const Bu::String &sPath ) |
| 282 | { | 288 | { |
| 289 | Bu::MutexLocker lLock( mAccess ); | ||
| 283 | int32_t iParent = -1; | 290 | int32_t iParent = -1; |
| 284 | int32_t iNode = lookupInode( sPath, iParent ); | 291 | int32_t iNode = lookupInode( sPath, iParent ); |
| 285 | return readDir( iNode ); | 292 | return readDir( iNode ); |
| @@ -288,6 +295,7 @@ Bu::MyriadFs::Dir Bu::MyriadFs::readDir( const Bu::String &sPath ) | |||
| 288 | void Bu::MyriadFs::setTimes( const Bu::String &sPath, int64_t iATime, | 295 | void Bu::MyriadFs::setTimes( const Bu::String &sPath, int64_t iATime, |
| 289 | int64_t iMTime ) | 296 | int64_t iMTime ) |
| 290 | { | 297 | { |
| 298 | Bu::MutexLocker lLock( mAccess ); | ||
| 291 | int32_t iParent = -1; | 299 | int32_t iParent = -1; |
| 292 | int32_t iNode; | 300 | int32_t iNode; |
| 293 | 301 | ||
| @@ -298,6 +306,7 @@ void Bu::MyriadFs::setTimes( const Bu::String &sPath, int64_t iATime, | |||
| 298 | 306 | ||
| 299 | void Bu::MyriadFs::unlink( const Bu::String &sPath ) | 307 | void Bu::MyriadFs::unlink( const Bu::String &sPath ) |
| 300 | { | 308 | { |
| 309 | Bu::MutexLocker lLock( mAccess ); | ||
| 301 | int32_t iParent = -1; | 310 | int32_t iParent = -1; |
| 302 | // int32_t iNode; | 311 | // int32_t iNode; |
| 303 | 312 | ||
| @@ -353,6 +362,7 @@ void Bu::MyriadFs::unlink( const Bu::String &sPath ) | |||
| 353 | 362 | ||
| 354 | void Bu::MyriadFs::setFileSize( const Bu::String &sPath, int32_t iSize ) | 363 | void Bu::MyriadFs::setFileSize( const Bu::String &sPath, int32_t iSize ) |
| 355 | { | 364 | { |
| 365 | Bu::MutexLocker lLock( mAccess ); | ||
| 356 | int32_t iParent = -1; | 366 | int32_t iParent = -1; |
| 357 | int32_t iNode; | 367 | int32_t iNode; |
| 358 | iNode = lookupInode( sPath, iParent ); | 368 | iNode = lookupInode( sPath, iParent ); |
| @@ -362,6 +372,7 @@ void Bu::MyriadFs::setFileSize( const Bu::String &sPath, int32_t iSize ) | |||
| 362 | 372 | ||
| 363 | void Bu::MyriadFs::rename( const Bu::String &sFrom, const Bu::String &sTo ) | 373 | void Bu::MyriadFs::rename( const Bu::String &sFrom, const Bu::String &sTo ) |
| 364 | { | 374 | { |
| 375 | Bu::MutexLocker lLock( mAccess ); | ||
| 365 | mkHardLink( sFrom, sTo ); | 376 | mkHardLink( sFrom, sTo ); |
| 366 | unlink( sFrom ); | 377 | unlink( sFrom ); |
| 367 | } | 378 | } |
diff --git a/src/unstable/myriadfs.h b/src/unstable/myriadfs.h index 4e1749e..e3008bc 100644 --- a/src/unstable/myriadfs.h +++ b/src/unstable/myriadfs.h | |||
| @@ -11,7 +11,7 @@ | |||
| 11 | #include <sys/types.h> | 11 | #include <sys/types.h> |
| 12 | 12 | ||
| 13 | #include "bu/myriad.h" | 13 | #include "bu/myriad.h" |
| 14 | #include "bu/mutex.h" | 14 | #include "bu/debugmutex.h" |
| 15 | 15 | ||
| 16 | namespace Bu | 16 | namespace Bu |
| 17 | { | 17 | { |
| @@ -172,7 +172,13 @@ namespace Bu | |||
| 172 | typedef Bu::Hash<int32_t, int32_t> NodeIndex; | 172 | typedef Bu::Hash<int32_t, int32_t> NodeIndex; |
| 173 | 173 | ||
| 174 | private: | 174 | private: |
| 175 | /** | ||
| 176 | * Lookup inode. | ||
| 177 | */ | ||
| 175 | int32_t lookupInode( const Bu::String &sPath, int32_t &iParent ); | 178 | int32_t lookupInode( const Bu::String &sPath, int32_t &iParent ); |
| 179 | /** | ||
| 180 | * Lookup inode. | ||
| 181 | */ | ||
| 176 | int32_t lookupInode( Bu::String::const_iterator iStart, | 182 | int32_t lookupInode( Bu::String::const_iterator iStart, |
| 177 | int32_t iNode, int32_t &iParent ); | 183 | int32_t iNode, int32_t &iParent ); |
| 178 | void readInode( int32_t iNode, RawStat &rs, MyriadStream &rIs ); | 184 | void readInode( int32_t iNode, RawStat &rs, MyriadStream &rIs ); |
| @@ -190,12 +196,12 @@ namespace Bu | |||
| 190 | void setTimes( int32_t iNode, int64_t iATime, int64_t iMTime ); | 196 | void setTimes( int32_t iNode, int64_t iATime, int64_t iMTime ); |
| 191 | void destroyNode( int32_t iNode ); | 197 | void destroyNode( int32_t iNode ); |
| 192 | 198 | ||
| 193 | Bu::String filePart( const Bu::String &sPath ); | 199 | static Bu::String filePart( const Bu::String &sPath ); |
| 194 | 200 | ||
| 195 | private: | 201 | private: |
| 196 | Bu::Stream &rStore; | 202 | Bu::Stream &rStore; |
| 197 | Bu::Myriad mStore; | 203 | Bu::Myriad mStore; |
| 198 | Bu::Mutex mAccess; | 204 | Bu::DebugMutex mAccess; |
| 199 | NodeIndex hNodeIndex; | 205 | NodeIndex hNodeIndex; |
| 200 | int32_t iUser; | 206 | int32_t iUser; |
| 201 | int32_t iGroup; | 207 | int32_t iGroup; |
