HaikuDepot: Pull package info for selected package in worker thread.
Selecting packages in the list view is instant again. Fixes #11198.
This commit is contained in:
@@ -138,6 +138,14 @@ MainWindow::MainWindow(BRect frame, const BMessage& settings)
|
|||||||
if (fPendingActionsWorker >= 0)
|
if (fPendingActionsWorker >= 0)
|
||||||
resume_thread(fPendingActionsWorker);
|
resume_thread(fPendingActionsWorker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fPackageToPopulateSem = create_sem(0, "PopulatePackage");
|
||||||
|
if (fPackageToPopulateSem >= 0) {
|
||||||
|
fPopulatePackageWorker = spawn_thread(&_PopulatePackageWorker,
|
||||||
|
"Package Populator", B_NORMAL_PRIORITY, this);
|
||||||
|
if (fPopulatePackageWorker >= 0)
|
||||||
|
resume_thread(fPopulatePackageWorker);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -151,6 +159,9 @@ MainWindow::~MainWindow()
|
|||||||
|
|
||||||
delete_sem(fPendingActionsSem);
|
delete_sem(fPendingActionsSem);
|
||||||
wait_for_thread(fPendingActionsWorker, NULL);
|
wait_for_thread(fPendingActionsWorker, NULL);
|
||||||
|
|
||||||
|
delete_sem(fPackageToPopulateSem);
|
||||||
|
wait_for_thread(fPopulatePackageWorker, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -381,9 +392,13 @@ void
|
|||||||
MainWindow::_AdoptPackage(const PackageInfoRef& package)
|
MainWindow::_AdoptPackage(const PackageInfoRef& package)
|
||||||
{
|
{
|
||||||
fPackageInfoView->SetPackage(package);
|
fPackageInfoView->SetPackage(package);
|
||||||
fModel.PopulatePackage(package,
|
|
||||||
Model::POPULATE_USER_RATINGS | Model::POPULATE_SCREEN_SHOTS
|
// Trigger asynchronous package population from the web-app
|
||||||
| Model::POPULATE_CHANGELOG | Model::POPULATE_CATEGORIES);
|
{
|
||||||
|
AutoLocker<BLocker> lock(&fPackageToPopulateLock);
|
||||||
|
fPackageToPopulate = package;
|
||||||
|
}
|
||||||
|
release_sem_etc(fPackageToPopulateSem, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -751,6 +766,29 @@ MainWindow::_PackageActionWorker(void* arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
MainWindow::_PopulatePackageWorker(void* arg)
|
||||||
|
{
|
||||||
|
MainWindow* window = reinterpret_cast<MainWindow*>(arg);
|
||||||
|
|
||||||
|
while (acquire_sem(window->fPackageToPopulateSem) == B_OK) {
|
||||||
|
PackageInfoRef package;
|
||||||
|
{
|
||||||
|
AutoLocker<BLocker> lock(&window->fPackageToPopulateLock);
|
||||||
|
package = window->fPackageToPopulate;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (package.Get() != NULL) {
|
||||||
|
window->fModel.PopulatePackage(package,
|
||||||
|
Model::POPULATE_USER_RATINGS | Model::POPULATE_SCREEN_SHOTS
|
||||||
|
| Model::POPULATE_CHANGELOG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MainWindow::_NotifyUser(const char* title, const char* message)
|
MainWindow::_NotifyUser(const char* title, const char* message)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ private:
|
|||||||
|
|
||||||
static status_t _PackageActionWorker(void* arg);
|
static status_t _PackageActionWorker(void* arg);
|
||||||
|
|
||||||
|
static status_t _PopulatePackageWorker(void* arg);
|
||||||
|
|
||||||
void _NotifyUser(const char* title,
|
void _NotifyUser(const char* title,
|
||||||
const char* message);
|
const char* message);
|
||||||
@@ -88,6 +89,11 @@ private:
|
|||||||
PackageActionList fPendingActions;
|
PackageActionList fPendingActions;
|
||||||
BLocker fPendingActionsLock;
|
BLocker fPendingActionsLock;
|
||||||
sem_id fPendingActionsSem;
|
sem_id fPendingActionsSem;
|
||||||
|
|
||||||
|
thread_id fPopulatePackageWorker;
|
||||||
|
PackageInfoRef fPackageToPopulate;
|
||||||
|
BLocker fPackageToPopulateLock;
|
||||||
|
sem_id fPackageToPopulateSem;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAIN_WINDOW_H
|
#endif // MAIN_WINDOW_H
|
||||||
|
|||||||
Reference in New Issue
Block a user