From 700d4bbcbf59c4447becbab21a6aa7204a8da2f4 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 6 Nov 2024 16:01:36 -0800 Subject: I believe MyriadFs is now threadsafe. It could probably be more optimized, but it does work. --- src/unstable/myriadfs.cpp | 11 +++++++++++ src/unstable/myriadfs.h | 12 +++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) (limited to 'src/unstable') 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() void Bu::MyriadFs::stat( const Bu::String &sPath, Bu::MyriadFs::Stat &rBuf ) { + Bu::MutexLocker lLock( mAccess ); int32_t iParent; int32_t iNode = lookupInode( sPath, iParent ); 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 ) Bu::MyriadStream Bu::MyriadFs::open( const Bu::String &sPath, int iMode, uint16_t uPerms ) { + Bu::MutexLocker lLock( mAccess ); int32_t iParent = -1; int32_t iNode; try @@ -165,6 +167,7 @@ void Bu::MyriadFs::create( const Bu::String &sPath, uint16_t iPerms, void Bu::MyriadFs::create( const Bu::String &sPath, uint16_t iPerms, uint32_t uSpecial ) { + Bu::MutexLocker lLock( mAccess ); int32_t iParent = -1; // int32_t iNode; try @@ -201,6 +204,7 @@ void Bu::MyriadFs::mkDir( const Bu::String &sPath, uint16_t iPerms ) void Bu::MyriadFs::mkSymLink( const Bu::String &sTarget, const Bu::String &sPath ) { + Bu::MutexLocker lLock( mAccess ); int32_t iParent = -1; int32_t iNode; try @@ -233,6 +237,7 @@ void Bu::MyriadFs::mkSymLink( const Bu::String &sTarget, void Bu::MyriadFs::mkHardLink( const Bu::String &sTarget, const Bu::String &sPath ) { + Bu::MutexLocker lLock( mAccess ); int32_t iParent = -1; int32_t iNode; @@ -268,6 +273,7 @@ void Bu::MyriadFs::mkHardLink( const Bu::String &sTarget, Bu::String Bu::MyriadFs::readSymLink( const Bu::String &sPath ) { + Bu::MutexLocker lLock( mAccess ); int32_t iParent = -1; int32_t iNode; iNode = lookupInode( sPath, iParent ); @@ -280,6 +286,7 @@ Bu::String Bu::MyriadFs::readSymLink( const Bu::String &sPath ) Bu::MyriadFs::Dir Bu::MyriadFs::readDir( const Bu::String &sPath ) { + Bu::MutexLocker lLock( mAccess ); int32_t iParent = -1; int32_t iNode = lookupInode( sPath, iParent ); return readDir( iNode ); @@ -288,6 +295,7 @@ Bu::MyriadFs::Dir Bu::MyriadFs::readDir( const Bu::String &sPath ) void Bu::MyriadFs::setTimes( const Bu::String &sPath, int64_t iATime, int64_t iMTime ) { + Bu::MutexLocker lLock( mAccess ); int32_t iParent = -1; int32_t iNode; @@ -298,6 +306,7 @@ void Bu::MyriadFs::setTimes( const Bu::String &sPath, int64_t iATime, void Bu::MyriadFs::unlink( const Bu::String &sPath ) { + Bu::MutexLocker lLock( mAccess ); int32_t iParent = -1; // int32_t iNode; @@ -353,6 +362,7 @@ void Bu::MyriadFs::unlink( const Bu::String &sPath ) void Bu::MyriadFs::setFileSize( const Bu::String &sPath, int32_t iSize ) { + Bu::MutexLocker lLock( mAccess ); int32_t iParent = -1; int32_t iNode; iNode = lookupInode( sPath, iParent ); @@ -362,6 +372,7 @@ void Bu::MyriadFs::setFileSize( const Bu::String &sPath, int32_t iSize ) void Bu::MyriadFs::rename( const Bu::String &sFrom, const Bu::String &sTo ) { + Bu::MutexLocker lLock( mAccess ); mkHardLink( sFrom, sTo ); unlink( sFrom ); } 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 @@ #include #include "bu/myriad.h" -#include "bu/mutex.h" +#include "bu/debugmutex.h" namespace Bu { @@ -172,7 +172,13 @@ namespace Bu typedef Bu::Hash NodeIndex; private: + /** + * Lookup inode. + */ int32_t lookupInode( const Bu::String &sPath, int32_t &iParent ); + /** + * Lookup inode. + */ int32_t lookupInode( Bu::String::const_iterator iStart, int32_t iNode, int32_t &iParent ); void readInode( int32_t iNode, RawStat &rs, MyriadStream &rIs ); @@ -190,12 +196,12 @@ namespace Bu void setTimes( int32_t iNode, int64_t iATime, int64_t iMTime ); void destroyNode( int32_t iNode ); - Bu::String filePart( const Bu::String &sPath ); + static Bu::String filePart( const Bu::String &sPath ); private: Bu::Stream &rStore; Bu::Myriad mStore; - Bu::Mutex mAccess; + Bu::DebugMutex mAccess; NodeIndex hNodeIndex; int32_t iUser; int32_t iGroup; -- cgit v1.2.3