diff --git a/kfmmodel.cpp b/kfmmodel.cpp index 59b8459a4..fb73e29f2 100644 --- a/kfmmodel.cpp +++ b/kfmmodel.cpp @@ -163,7 +163,7 @@ void KfmModel::insertType( NifItem * parent, const NifData & data, int at ) return; } - XMLlock.lockForRead(); + QReadLocker lck( &XMLlock ); NifBlock * compound = compounds.value( data.type() ); if ( compound ) { @@ -202,7 +202,6 @@ void KfmModel::insertType( NifItem * parent, const NifData & data, int at ) } else parent->insertChild( data, at ); - XMLlock.unlock(); } diff --git a/kfmmodel.h b/kfmmodel.h index 7c77d9127..33019be20 100644 --- a/kfmmodel.h +++ b/kfmmodel.h @@ -114,18 +114,14 @@ Q_OBJECT inline bool KfmModel::isCompound( const QString & name ) { - XMLlock.lockForRead(); - bool x = compounds.contains( name ); - XMLlock.unlock(); - return x; + QReadLocker lck( &XMLlock ); + return compounds.contains( name ); } inline bool KfmModel::isVersionSupported( quint32 v ) { - XMLlock.lockForRead(); - bool x = supportedVersions.contains( v ); - XMLlock.unlock(); - return x; + QReadLocker lck( &XMLlock ); + return supportedVersions.contains( v ); } #endif diff --git a/kfmxml.cpp b/kfmxml.cpp index 7e9ce50fb..98ed47955 100644 --- a/kfmxml.cpp +++ b/kfmxml.cpp @@ -234,7 +234,7 @@ bool KfmModel::loadXML() QString KfmModel::parseXmlDescription( const QString & filename ) { - XMLlock.lockForWrite(); + QWriteLocker lck( &XMLlock ); qDeleteAll( compounds ); compounds.clear(); supportedVersions.clear(); @@ -244,10 +244,7 @@ QString KfmModel::parseXmlDescription( const QString & filename ) { f.setFileName( ":/res/kfm.xml" ); if ( ! f.open( QIODevice::ReadOnly | QIODevice::Text ) ) - { - XMLlock.unlock(); return QString( "error: couldn't open xml description file: " + filename ); - } } KfmXmlHandler handler; @@ -263,8 +260,6 @@ QString KfmModel::parseXmlDescription( const QString & filename ) supportedVersions.clear(); } - XMLlock.unlock(); - return handler.errorString(); } diff --git a/nifmodel.cpp b/nifmodel.cpp index 29f3c9973..33b0c5fb8 100644 --- a/nifmodel.cpp +++ b/nifmodel.cpp @@ -277,7 +277,7 @@ bool NifModel::updateArrayItem( NifItem * array, bool fast ) QModelIndex NifModel::insertNiBlock( const QString & identifier, int at, bool fast ) { - XMLlock.lockForRead(); + QReadLocker lck( &XMLlock ); NifBlock * block = blocks.value( identifier ); if ( block ) { @@ -310,13 +310,11 @@ QModelIndex NifModel::insertNiBlock( const QString & identifier, int at, bool fa updateFooter(); emit linksChanged(); } - XMLlock.unlock(); return createIndex( branch->row(), 0, branch ); } else { msg( Message() << "unknown block " << identifier ); - XMLlock.unlock(); return QModelIndex(); } } @@ -457,7 +455,7 @@ int NifModel::getBlockCount() const void NifModel::insertAncestor( NifItem * parent, const QString & identifier, int at ) { - XMLlock.lockForRead(); + QReadLocker lck( &XMLlock ); NifBlock * ancestor = blocks.value( identifier ); if ( ancestor ) { @@ -468,20 +466,16 @@ void NifModel::insertAncestor( NifItem * parent, const QString & identifier, int insertType( parent, data ); } else - { msg( Message() << "unknown ancestor " << identifier ); - } - XMLlock.unlock(); } bool NifModel::inherits( const QString & name, const QString & aunty ) { - XMLlock.lockForRead(); + QReadLocker lck( &XMLlock ); if ( name == aunty ) return true; NifBlock * type = blocks.value( name ); if ( type && ( type->ancestor == aunty || inherits( type->ancestor, aunty ) ) ) return true; - XMLlock.unlock(); return false; } @@ -517,7 +511,7 @@ void NifModel::insertType( NifItem * parent, const NifData & data, int at ) return; } - XMLlock.lockForRead(); + QReadLocker lck( &XMLlock ); NifBlock * compound = compounds.value( data.type() ); if ( compound ) { @@ -550,7 +544,6 @@ void NifModel::insertType( NifItem * parent, const NifData & data, int at ) else parent->insertChild( data, at ); } - XMLlock.unlock(); } diff --git a/nifmodel.h b/nifmodel.h index 4278938c7..696268516 100644 --- a/nifmodel.h +++ b/nifmodel.h @@ -206,47 +206,38 @@ Q_OBJECT inline QStringList NifModel::allNiBlocks() { - XMLlock.lockForRead(); + QReadLocker lck( &XMLlock ); QStringList lst; foreach ( NifBlock * blk, blocks ) if ( ! blk->abstract ) lst.append( blk->id ); - XMLlock.unlock(); return lst; } inline bool NifModel::isNiBlock( const QString & name ) { - XMLlock.lockForRead(); + QReadLocker lck( &XMLlock ); NifBlock * blk = blocks.value( name ); - bool x = blk && ! blk->abstract; - XMLlock.unlock(); - return x; + return blk && ! blk->abstract; } inline bool NifModel::isAncestor( const QString & name ) { - XMLlock.lockForRead(); + QReadLocker lck( &XMLlock ); NifBlock * blk = blocks.value( name ); - bool x = blk && blk->abstract; - XMLlock.unlock(); - return x; + return blk && blk->abstract; } inline bool NifModel::isCompound( const QString & name ) { - XMLlock.lockForRead(); - bool x = compounds.contains( name ); - XMLlock.unlock(); - return x; + QReadLocker lck( &XMLlock ); + return compounds.contains( name ); } inline bool NifModel::isVersionSupported( quint32 v ) { - XMLlock.lockForRead(); - bool x = supportedVersions.contains( v ); - XMLlock.unlock(); - return x; + QReadLocker lck( &XMLlock ); + return supportedVersions.contains( v ); } inline QList NifModel::getRootLinks() const diff --git a/nifxml.cpp b/nifxml.cpp index 57f77bd92..fa255354e 100644 --- a/nifxml.cpp +++ b/nifxml.cpp @@ -363,8 +363,7 @@ bool NifModel::loadXML() QString NifModel::parseXmlDescription( const QString & filename ) { - if ( ! XMLlock.tryLockForWrite() ) - return QString( "internal error: xml is locked" ); + QWriteLocker lck( &XMLlock ); qDeleteAll( compounds ); compounds.clear(); qDeleteAll( blocks ); blocks.clear(); @@ -378,10 +377,7 @@ QString NifModel::parseXmlDescription( const QString & filename ) { f.setFileName( ":/res/nif.xml" ); if ( ! f.open( QIODevice::ReadOnly | QIODevice::Text ) ) - { - XMLlock.unlock(); return QString( "error: couldn't open xml description file: " + filename ); - } } NifXmlHandler handler; @@ -399,8 +395,6 @@ QString NifModel::parseXmlDescription( const QString & filename ) supportedVersions.clear(); } - XMLlock.unlock(); - return handler.errorString(); }