HaikuDepot: More fine grained locking in Model::PopulatePackage()

This commit is contained in:
Stephan Aßmus
2014-09-04 10:13:22 +02:00
parent 08e98ffde1
commit 48045f5a08
+19 -15
View File
@@ -521,40 +521,44 @@ Model::SetShowDevelopPackages(bool show)
void void
Model::PopulatePackage(const PackageInfoRef& package, uint32 flags) Model::PopulatePackage(const PackageInfoRef& package, uint32 flags)
{ {
if (fPopulatedPackages.Contains(package))
return;
BAutolock _(&fLock);
// TODO: Replace with actual backend that retrieves package extra
// information and user-contributed package information.
// TODO: There should probably also be a way to "unpopulate" the // TODO: There should probably also be a way to "unpopulate" the
// package information. Maybe a cache of populated packages, so that // package information. Maybe a cache of populated packages, so that
// packages loose their extra information after a certain amount of // packages loose their extra information after a certain amount of
// time when they have not been accessed/displayed in the UI. Otherwise // time when they have not been accessed/displayed in the UI. Otherwise
// HaikuDepot will consume more and more resources in the packages. // HaikuDepot will consume more and more resources in the packages.
// Especially screen-shots will be a problem eventually. // Especially screen-shots will be a problem eventually.
{
// TODO: Simulate a delay in retrieving this info, and do that on BAutolock locker(&fLock);
// a separate thread. if (fPopulatedPackages.Contains(package))
return;
fPopulatedPackages.Add(package); fPopulatedPackages.Add(package);
}
if ((flags & POPULATE_USER_RATINGS) != 0) { if ((flags & POPULATE_USER_RATINGS) != 0) {
// Retrieve info from web-app // Retrieve info from web-app
WebAppInterface interface; WebAppInterface interface;
interface.SetPreferredLanguage(fPreferredLanguage); interface.SetPreferredLanguage(fPreferredLanguage);
BMessage info; BMessage info;
BString packageName;
BString architecture;
{
BAutolock locker(&fLock);
packageName = package->Title();
architecture = package->Architecture();
}
status_t status = interface.RetrieveUserRatings(package->Title(), status_t status = interface.RetrieveUserRatings(packageName,
package->Architecture(), 0, 50, info); architecture, 0, 50, info);
if (status == B_OK) { if (status == B_OK) {
// Parse message // Parse message
BMessage result; BMessage result;
BMessage items; BMessage items;
if (info.FindMessage("result", &result) == B_OK if (info.FindMessage("result", &result) == B_OK
&& result.FindMessage("items", &items) == B_OK) { && result.FindMessage("items", &items) == B_OK) {
BAutolock locker(&fLock);
int index = 0; int index = 0;
while (true) { while (true) {
BString name; BString name;