Skip to content

Commit

Permalink
* Prevent race condition.
Browse files Browse the repository at this point in the history
(cherry picked from commit ebbedb2)
  • Loading branch information
muesli authored and lfranchi committed Mar 30, 2012
1 parent 95f1162 commit ace18df
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/libtomahawk/database/databasecommand_resolve.cpp
Expand Up @@ -143,8 +143,9 @@ DatabaseCommand_Resolve::resolve( DatabaseImpl* lib )
url = QString( "servent://%1\t%2" ).arg( s->userName() ).arg( url );
}

bool cached = Tomahawk::Result::isCached( url );
Tomahawk::result_ptr result = Tomahawk::Result::get( url );
if ( result->isValid() )
if ( cached )
{
qDebug() << "Result already cached:" << result->toString();
res << result;
Expand Down Expand Up @@ -281,8 +282,9 @@ DatabaseCommand_Resolve::fullTextResolve( DatabaseImpl* lib )
url = QString( "servent://%1\t%2" ).arg( s->userName() ).arg( url );
}

bool cached = Tomahawk::Result::isCached( url );
Tomahawk::result_ptr result = Tomahawk::Result::get( url );
if ( result->isValid() )
if ( cached )
{
qDebug() << "Result already cached:" << result->toString();
res << result;
Expand Down
15 changes: 8 additions & 7 deletions src/libtomahawk/result.cpp
Expand Up @@ -50,6 +50,14 @@ Result::get( const QString& url )
}


bool
Result::isCached( const QString& url )
{
QMutexLocker lock( &s_mutex );
return ( s_results.contains( url ) );
}


Result::Result( const QString& url )
: QObject()
, m_url( url )
Expand Down Expand Up @@ -86,13 +94,6 @@ Result::deleteLater()
}


bool
Result::isValid() const
{
return !m_rid.isEmpty();
}


artist_ptr
Result::artist() const
{
Expand Down
2 changes: 1 addition & 1 deletion src/libtomahawk/result.h
Expand Up @@ -56,9 +56,9 @@ friend class ::DatabaseCommand_LoadFile;

public:
static Tomahawk::result_ptr get( const QString& url );
static bool isCached( const QString& url );
virtual ~Result();

bool isValid() const;
QVariant toVariant() const;
QString toString() const;
Tomahawk::query_ptr toQuery();
Expand Down

0 comments on commit ace18df

Please sign in to comment.