Skip to content

Commit

Permalink
proper xml rw locking
Browse files Browse the repository at this point in the history
  • Loading branch information
m4444x committed May 23, 2006
1 parent 97c6a67 commit 34a73a1
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 52 deletions.
3 changes: 1 addition & 2 deletions kfmmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -202,7 +202,6 @@ void KfmModel::insertType( NifItem * parent, const NifData & data, int at )
}
else
parent->insertChild( data, at );
XMLlock.unlock();
}


Expand Down
12 changes: 4 additions & 8 deletions kfmmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 1 addition & 6 deletions kfmxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ bool KfmModel::loadXML()

QString KfmModel::parseXmlDescription( const QString & filename )
{
XMLlock.lockForWrite();
QWriteLocker lck( &XMLlock );

qDeleteAll( compounds ); compounds.clear();
supportedVersions.clear();
Expand All @@ -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;
Expand All @@ -263,8 +260,6 @@ QString KfmModel::parseXmlDescription( const QString & filename )
supportedVersions.clear();
}

XMLlock.unlock();

return handler.errorString();
}

15 changes: 4 additions & 11 deletions nifmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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 )
{
Expand All @@ -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;
}

Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -550,7 +544,6 @@ void NifModel::insertType( NifItem * parent, const NifData & data, int at )
else
parent->insertChild( data, at );
}
XMLlock.unlock();
}


Expand Down
27 changes: 9 additions & 18 deletions nifmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> NifModel::getRootLinks() const
Expand Down
8 changes: 1 addition & 7 deletions nifxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -399,8 +395,6 @@ QString NifModel::parseXmlDescription( const QString & filename )
supportedVersions.clear();
}

XMLlock.unlock();

return handler.errorString();
}

0 comments on commit 34a73a1

Please sign in to comment.