From 7d232f0cf8c3de889570712f8ced1250f5850b91 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Tue, 14 Jan 2025 17:09:09 -0500 Subject: [PATCH] kernel/image: Switch to using DoublyLinkedList<> for struct image. No functional change intended. --- headers/private/kernel/kimage.h | 6 ++-- headers/private/kernel/thread_types.h | 2 +- src/system/kernel/elf.cpp | 5 ++- src/system/kernel/image.cpp | 51 +++++++++++---------------- src/system/kernel/team.cpp | 1 - 5 files changed, 27 insertions(+), 38 deletions(-) diff --git a/headers/private/kernel/kimage.h b/headers/private/kernel/kimage.h index b0abb32ee0..eaeab63354 100644 --- a/headers/private/kernel/kimage.h +++ b/headers/private/kernel/kimage.h @@ -5,6 +5,7 @@ #ifndef _KERNEL_IMAGE_H #define _KERNEL_IMAGE_H + #include #include @@ -21,11 +22,10 @@ using BKernel::Team; #ifdef __cplusplus +#include #include -struct image { - struct image* next; - struct image* prev; +struct image : public DoublyLinkedListLinkImpl { struct image* hash_link; extended_image_info info; team_id team; diff --git a/headers/private/kernel/thread_types.h b/headers/private/kernel/thread_types.h index 508cd5d498..c095b5a853 100644 --- a/headers/private/kernel/thread_types.h +++ b/headers/private/kernel/thread_types.h @@ -260,7 +260,7 @@ struct Team : TeamThreadIteratorEntry, 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_list; // protected by sImageMutex struct list watcher_list; struct list sem_list; // protected by sSemsSpinlock struct list port_list; // protected by sPortsLock diff --git a/src/system/kernel/elf.cpp b/src/system/kernel/elf.cpp index 2af5a98a2b..354c64a68f 100644 --- a/src/system/kernel/elf.cpp +++ b/src/system/kernel/elf.cpp @@ -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 diff --git a/src/system/kernel/image.cpp b/src/system/kernel/image.cpp index 8deaa42981..c167863fa8 100644 --- a/src/system/kernel/image.cpp +++ b/src/system/kernel/image.cpp @@ -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 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; } diff --git a/src/system/kernel/team.cpp b/src/system/kernel/team.cpp index 93c0f26499..26cb6cb9d2 100644 --- a/src/system/kernel/team.cpp +++ b/src/system/kernel/team.cpp @@ -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());