mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
Set future on artist/album immediately after creating promise
This commit is contained in:
@@ -151,9 +151,17 @@ void
|
|||||||
Album::loadId( bool autoCreate )
|
Album::loadId( bool autoCreate )
|
||||||
{
|
{
|
||||||
Q_ASSERT( m_waitingForId );
|
Q_ASSERT( m_waitingForId );
|
||||||
m_idFuture = IdThreadWorker::getAlbumId( m_ownRef.toStrongRef(), autoCreate );
|
IdThreadWorker::getAlbumId( m_ownRef.toStrongRef(), autoCreate );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Album::setIdFuture( boost::unique_future< unsigned int > future )
|
||||||
|
{
|
||||||
|
m_idFuture = boost::move( future );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
Album::id() const
|
Album::id() const
|
||||||
{
|
{
|
||||||
|
@@ -36,6 +36,8 @@
|
|||||||
#include "Collection.h"
|
#include "Collection.h"
|
||||||
#include "infosystem/InfoSystem.h"
|
#include "infosystem/InfoSystem.h"
|
||||||
|
|
||||||
|
class IdThreadWorker;
|
||||||
|
|
||||||
namespace Tomahawk
|
namespace Tomahawk
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -82,6 +84,7 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY( Album )
|
Q_DISABLE_COPY( Album )
|
||||||
QString infoid() const;
|
QString infoid() const;
|
||||||
|
void setIdFuture( boost::unique_future< unsigned int > future );
|
||||||
|
|
||||||
mutable bool m_waitingForId;
|
mutable bool m_waitingForId;
|
||||||
mutable boost::unique_future< unsigned int > m_idFuture;
|
mutable boost::unique_future< unsigned int > m_idFuture;
|
||||||
@@ -107,6 +110,8 @@ private:
|
|||||||
|
|
||||||
static QHash< QString, album_ptr > s_albumsByName;
|
static QHash< QString, album_ptr > s_albumsByName;
|
||||||
static QHash< unsigned int, album_ptr > s_albumsById;
|
static QHash< unsigned int, album_ptr > s_albumsById;
|
||||||
|
|
||||||
|
friend class ::IdThreadWorker;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // ns
|
} // ns
|
||||||
|
@@ -230,7 +230,15 @@ void
|
|||||||
Artist::loadId( bool autoCreate )
|
Artist::loadId( bool autoCreate )
|
||||||
{
|
{
|
||||||
Q_ASSERT( m_waitingForFuture );
|
Q_ASSERT( m_waitingForFuture );
|
||||||
m_idFuture = IdThreadWorker::getArtistId( m_ownRef.toStrongRef(), autoCreate );
|
|
||||||
|
IdThreadWorker::getArtistId( m_ownRef.toStrongRef(), autoCreate );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Artist::setIdFuture( boost::unique_future< unsigned int > future )
|
||||||
|
{
|
||||||
|
m_idFuture = boost::move(future);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -33,6 +33,8 @@
|
|||||||
|
|
||||||
#include <boost/thread.hpp>
|
#include <boost/thread.hpp>
|
||||||
|
|
||||||
|
class IdThreadWorker;
|
||||||
|
|
||||||
namespace Tomahawk
|
namespace Tomahawk
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -97,6 +99,8 @@ private:
|
|||||||
Artist();
|
Artist();
|
||||||
QString infoid() const;
|
QString infoid() const;
|
||||||
|
|
||||||
|
void setIdFuture( boost::unique_future< unsigned int > future );
|
||||||
|
|
||||||
mutable bool m_waitingForFuture;
|
mutable bool m_waitingForFuture;
|
||||||
mutable boost::unique_future< unsigned int > m_idFuture;
|
mutable boost::unique_future< unsigned int > m_idFuture;
|
||||||
mutable unsigned int m_id;
|
mutable unsigned int m_id;
|
||||||
@@ -133,6 +137,8 @@ private:
|
|||||||
|
|
||||||
static QHash< QString, artist_ptr > s_artistsByName;
|
static QHash< QString, artist_ptr > s_artistsByName;
|
||||||
static QHash< unsigned int, artist_ptr > s_artistsById;
|
static QHash< unsigned int, artist_ptr > s_artistsById;
|
||||||
|
|
||||||
|
friend class ::IdThreadWorker;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // ns
|
} // ns
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
#include "Album.h"
|
#include "Album.h"
|
||||||
#include "Database.h"
|
#include "Database.h"
|
||||||
#include "DatabaseImpl.h"
|
#include "DatabaseImpl.h"
|
||||||
|
#include "Source.h"
|
||||||
|
|
||||||
#define ID_THREAD_DEBUG 0
|
#define ID_THREAD_DEBUG 0
|
||||||
|
|
||||||
@@ -90,10 +91,11 @@ internalGet( const artist_ptr& artist, const album_ptr& album, bool autoCreate,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
boost::unique_future< unsigned int >
|
void
|
||||||
IdThreadWorker::getArtistId( const artist_ptr& artist, bool autoCreate )
|
IdThreadWorker::getArtistId( const artist_ptr& artist, bool autoCreate )
|
||||||
{
|
{
|
||||||
QueueItem* item = internalGet( artist, album_ptr(), autoCreate, ArtistType );
|
QueueItem* item = internalGet( artist, album_ptr(), autoCreate, ArtistType );
|
||||||
|
artist->setIdFuture( item->promise.get_future() );
|
||||||
|
|
||||||
#if ID_THREAD_DEBUG
|
#if ID_THREAD_DEBUG
|
||||||
qDebug() << "QUEUEING ARTIST:" << artist->name();
|
qDebug() << "QUEUEING ARTIST:" << artist->name();
|
||||||
@@ -106,15 +108,14 @@ IdThreadWorker::getArtistId( const artist_ptr& artist, bool autoCreate )
|
|||||||
#if ID_THREAD_DEBUG
|
#if ID_THREAD_DEBUG
|
||||||
qDebug() << "DONE WOKE UP THREAD:" << artist->name();
|
qDebug() << "DONE WOKE UP THREAD:" << artist->name();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return item->promise.get_future();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
boost::unique_future< unsigned int >
|
void
|
||||||
IdThreadWorker::getAlbumId( const album_ptr& album, bool autoCreate )
|
IdThreadWorker::getAlbumId( const album_ptr& album, bool autoCreate )
|
||||||
{
|
{
|
||||||
QueueItem* item = internalGet( artist_ptr(), album, autoCreate, AlbumType );
|
QueueItem* item = internalGet( artist_ptr(), album, autoCreate, AlbumType );
|
||||||
|
album->setIdFuture( item->promise.get_future() );
|
||||||
|
|
||||||
#if ID_THREAD_DEBUG
|
#if ID_THREAD_DEBUG
|
||||||
qDebug() << "QUEUEING ALUBM:" << album->artist()->name() << album->name();
|
qDebug() << "QUEUEING ALUBM:" << album->artist()->name() << album->name();
|
||||||
@@ -126,8 +127,6 @@ IdThreadWorker::getAlbumId( const album_ptr& album, bool autoCreate )
|
|||||||
#if ID_THREAD_DEBUG
|
#if ID_THREAD_DEBUG
|
||||||
qDebug() << "DONE WOKE UP THREAD:" << album->artist()->name() << album->name();
|
qDebug() << "DONE WOKE UP THREAD:" << album->artist()->name() << album->name();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return item->promise.get_future();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -42,8 +42,8 @@ public:
|
|||||||
void run();
|
void run();
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
static boost::unique_future< unsigned int > getArtistId( const Tomahawk::artist_ptr& artist, bool autoCreate = false );
|
static void getArtistId( const Tomahawk::artist_ptr& artist, bool autoCreate = false );
|
||||||
static boost::unique_future< unsigned int > getAlbumId( const Tomahawk::album_ptr& album, bool autoCreate = false );
|
static void getAlbumId( const Tomahawk::album_ptr& album, bool autoCreate = false );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Database* m_db;
|
Database* m_db;
|
||||||
|
Reference in New Issue
Block a user