kernel/image: Switch to using DoublyLinkedList<> for struct image.

No functional change intended.
This commit is contained in:
Augustin Cavalier 2025-01-14 17:09:09 -05:00
parent 9792c51694
commit 7d232f0cf8
5 changed files with 27 additions and 38 deletions

View File

@ -5,6 +5,7 @@
#ifndef _KERNEL_IMAGE_H
#define _KERNEL_IMAGE_H
#include <image.h>
#include <image_defs.h>
@ -21,11 +22,10 @@ using BKernel::Team;
#ifdef __cplusplus
#include <util/DoublyLinkedList.h>
#include <util/OpenHashTable.h>
struct image {
struct image* next;
struct image* prev;
struct image : public DoublyLinkedListLinkImpl<struct image> {
struct image* hash_link;
extended_image_info info;
team_id team;

View File

@ -260,7 +260,7 @@ struct Team : TeamThreadIteratorEntry<team_id>, KernelReferenceable,
Thread *thread_list; // protected by fLock, signal_lock and
// gThreadCreationLock
struct team_loading_info *loading_info; // protected by fLock
struct list image_list; // protected by sImageMutex
DoublyLinkedList<image> image_list; // protected by sImageMutex
struct list watcher_list;
struct list sem_list; // protected by sSemsSpinlock
struct list port_list; // protected by sPortsLock

View File

@ -1495,9 +1495,8 @@ public:
status_t _FindImageAtAddress(addr_t address, struct image*& _image)
{
struct image* image = NULL;
while ((image = (struct image*)list_get_next_item(&fTeam->image_list,
image)) != NULL) {
for (struct image* image = fTeam->image_list.First();
image != NULL; image = fTeam->image_list.GetNext(image)) {
image_info *info = &image->info.basic_info;
if ((address < (addr_t)info->text

View File

@ -103,9 +103,9 @@ register_image(Team *team, extended_image_info *info, size_t size, bool locked)
// Add the app image to the head of the list. Some code relies on it being
// the first image to be returned by get_next_image_info().
if (image->info.basic_info.type == B_APP_IMAGE)
list_add_link_to_head(&team->image_list, image);
team->image_list.Add(image, false);
else
list_add_item(&team->image_list, image);
team->image_list.Add(image);
sImageTable->Insert(image);
// notify listeners
@ -139,7 +139,7 @@ unregister_image(Team *team, image_id id)
struct image *image = sImageTable->Lookup(id);
if (image != NULL && image->team == team->id) {
list_remove_link(image);
team->image_list.Remove(image);
sImageTable->Remove(image);
status = B_OK;
}
@ -171,9 +171,8 @@ copy_images(team_id fromTeamId, Team *toTeam)
MutexLocker locker(sImageMutex);
struct image *image = NULL;
while ((image = (struct image*)list_get_next_item(&fromTeam->image_list,
image)) != NULL) {
for (struct image* image = fromTeam->image_list.First();
image != NULL; image = fromTeam->image_list.GetNext(image)) {
image_id id = register_image(toTeam, &image->info, sizeof(image->info),
true);
if (id < 0)
@ -190,13 +189,11 @@ copy_images(team_id fromTeamId, Team *toTeam)
int32
count_images(Team *team)
{
struct image *image = NULL;
int32 count = 0;
MutexLocker locker(sImageMutex);
while ((image = (struct image*)list_get_next_item(&team->image_list, image))
!= NULL) {
int32 count = 0;
for (struct image* image = team->image_list.First();
image != NULL; image = team->image_list.GetNext(image)) {
count++;
}
@ -210,25 +207,22 @@ count_images(Team *team)
status_t
remove_images(Team *team)
{
struct image *image = NULL;
ASSERT(team != NULL);
mutex_lock(&sImageMutex);
struct list images = {};
list_move_to_list(&team->image_list, &images);
while ((image = (struct image*)list_get_next_item(&images,
image)) != NULL) {
DoublyLinkedList<struct image> images;
images.TakeFrom(&team->image_list);
for (struct image* image = images.First();
image != NULL; image = images.GetNext(image)) {
sImageTable->Remove(image);
}
mutex_unlock(&sImageMutex);
while ((image = (struct image*)list_remove_head_item(&images))
!= NULL) {
while (struct image* image = images.RemoveHead())
free(image);
}
return B_OK;
}
@ -272,11 +266,10 @@ _get_next_image_info(team_id teamID, int32 *cookie, image_info *info,
// iterate through the team's images
MutexLocker imageLocker(sImageMutex);
struct image* image = NULL;
int32 count = 0;
while ((image = (struct image*)list_get_next_item(&team->image_list,
image)) != NULL) {
for (struct image* image = team->image_list.First();
image != NULL; image = team->image_list.GetNext(image)) {
if (count == *cookie) {
memcpy(info, &image->info.basic_info, size);
(*cookie)++;
@ -293,7 +286,6 @@ _get_next_image_info(team_id teamID, int32 *cookie, image_info *info,
static int
dump_images_list(int argc, char **argv)
{
struct image *image = NULL;
Team *team;
if (argc > 1) {
@ -310,8 +302,8 @@ dump_images_list(int argc, char **argv)
kprintf(" ID %-*s size %-*s size name\n",
B_PRINTF_POINTER_WIDTH, "text", B_PRINTF_POINTER_WIDTH, "data");
while ((image = (struct image*)list_get_next_item(&team->image_list, image))
!= NULL) {
for (struct image* image = team->image_list.First();
image != NULL; image = team->image_list.GetNext(image)) {
image_info *info = &image->info.basic_info;
kprintf("%6" B_PRId32 " %p %-7" B_PRId32 " %p %-7" B_PRId32 " %s\n",
@ -353,10 +345,9 @@ image_iterate_through_team_images(team_id teamID,
// iterate through the team's images
MutexLocker imageLocker(sImageMutex);
struct image* image = NULL;
while ((image = (struct image*)list_get_next_item(&team->image_list,
image)) != NULL) {
struct image *image = NULL;
for (image = team->image_list.First();
image != NULL; image = team->image_list.GetNext(image)) {
if (callback(image, cookie))
break;
}

View File

@ -464,7 +464,6 @@ Team::Team(team_id id, bool kernel)
thread_list = NULL;
loading_info = NULL;
list_init(&image_list);
list_init(&watcher_list);
list_init(&sem_list);
list_init_etc(&port_list, port_team_link_offset());