HaikuDepot: Remove Custom List

Further removal of the use of custom list class;
this time with the package action lists.

Also resolve an error created by a last minute
change in the last pull request for this ticket.

Relates To #15534

Change-Id: I85dd40b7ef664f93b24ca5041fa58cca17d72299
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3735
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
Andrew Lindesay 2021-02-07 13:42:52 +13:00
parent d75b4d610d
commit 6f07fead0c
5 changed files with 17 additions and 23 deletions

View File

@ -1,6 +1,7 @@
/*
* Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
* Copyright 2013, Rene Gollent, <rene@gollent.com>
* Copyright 2021, Andrew Lindesay <apl@lindesay.co.nz>
*
* All rights reserved. Distributed under the terms of the MIT License.
*/
@ -64,7 +65,6 @@ private:
typedef BReference<PackageAction> PackageActionRef;
typedef List<PackageActionRef, false> PackageActionList;
#endif // PACKAGE_ACTION_H

View File

@ -1,5 +1,6 @@
/*
* Copyright 2013, Rene Gollent <rene@gollent.com>.
* Copyright 2021, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
@ -19,8 +20,8 @@ class PackageActionHandler {
public:
virtual ~PackageActionHandler();
virtual status_t SchedulePackageActions(
PackageActionList& list) = 0;
virtual status_t SchedulePackageAction(
PackageActionRef action) = 0;
virtual Model* GetModel() = 0;
};

View File

@ -429,7 +429,7 @@ MainWindow::MessageReceived(BMessage* message)
BAutolock locker(fModel.Lock());
package = fModel.PackageForName(name);
}
if (package.IsSet() || name != package->Name())
if (!package.IsSet() || name != package->Name())
debugger("unable to find the named package");
else
_AdoptPackage(package);
@ -605,15 +605,11 @@ MainWindow::PackageChanged(const PackageInfoEvent& event)
status_t
MainWindow::SchedulePackageActions(PackageActionList& list)
MainWindow::SchedulePackageAction(PackageActionRef action)
{
AutoLocker<BLocker> lock(&fPendingActionsLock);
for (int32 i = 0; i < list.CountItems(); i++) {
if (!fPendingActions.Add(list.ItemAtFast(i)))
return B_NO_MEMORY;
}
return release_sem_etc(fPendingActionsSem, list.CountItems(), 0);
fPendingActions.push(action);
return release_sem_etc(fPendingActionsSem, 1, 0);
}
@ -989,7 +985,7 @@ MainWindow::_HandleWorkStatusChangeMessageReceived(const BMessage* message)
}
status_t
/*static*/ status_t
MainWindow::_PackageActionWorker(void* arg)
{
MainWindow* window = reinterpret_cast<MainWindow*>(arg);
@ -998,10 +994,10 @@ MainWindow::_PackageActionWorker(void* arg)
PackageActionRef ref;
{
AutoLocker<BLocker> lock(&window->fPendingActionsLock);
ref = window->fPendingActions.ItemAt(0);
ref = window->fPendingActions.front();
window->fPendingActions.pop();
if (!ref.IsSet())
break;
window->fPendingActions.Remove(0);
}
BMessenger messenger(window);

View File

@ -2,7 +2,7 @@
* Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
* Copyright 2013, Rene Gollent <rene@gollent.com>.
* Copyright 2017, Julian Harnath <julian.harnath@rwth-aachen.de>.
* Copyright 2017-2020, Andrew Lindesay <apl@lindesay.co.nz>.
* Copyright 2017-2021, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef MAIN_WINDOW_H
@ -66,8 +66,7 @@ private:
private:
// PackageActionHandler
virtual status_t SchedulePackageActions(
PackageActionList& list);
virtual status_t SchedulePackageAction(PackageActionRef action);
virtual Model* GetModel();
private:
@ -168,7 +167,8 @@ private:
bool fSinglePackageMode;
thread_id fPendingActionsWorker;
PackageActionList fPendingActions;
std::queue<PackageActionRef>
fPendingActions;
BLocker fPendingActionsLock;
sem_id fPendingActionsSem;

View File

@ -1,6 +1,6 @@
/*
* Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
* Copyright 2018-2020, Andrew Lindesay <apl@lindesay.co.nz>.
* Copyright 2018-2021, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
@ -638,10 +638,7 @@ private:
if (!action.IsSet())
return;
PackageActionList actions;
actions.Add(action);
status_t result
= fPackageActionHandler->SchedulePackageActions(actions);
status_t result = fPackageActionHandler->SchedulePackageAction(action);
if (result != B_OK) {
HDERROR("Failed to schedule action: %s '%s': %s",