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

No functional change intended.
This commit is contained in:
Augustin Cavalier
2025-01-14 17:30:36 -05:00
parent 9792c51694
commit 7d232f0cf8
5 changed files with 27 additions and 38 deletions
+3 -3
View File
@@ -5,6 +5,7 @@
#ifndef _KERNEL_IMAGE_H #ifndef _KERNEL_IMAGE_H
#define _KERNEL_IMAGE_H #define _KERNEL_IMAGE_H
#include <image.h> #include <image.h>
#include <image_defs.h> #include <image_defs.h>
@@ -21,11 +22,10 @@ using BKernel::Team;
#ifdef __cplusplus #ifdef __cplusplus
#include <util/DoublyLinkedList.h>
#include <util/OpenHashTable.h> #include <util/OpenHashTable.h>
struct image { struct image : public DoublyLinkedListLinkImpl<struct image> {
struct image* next;
struct image* prev;
struct image* hash_link; struct image* hash_link;
extended_image_info info; extended_image_info info;
team_id team; team_id team;
+1 -1
View File
@@ -260,7 +260,7 @@ struct Team : TeamThreadIteratorEntry<team_id>, KernelReferenceable,
Thread *thread_list; // protected by fLock, signal_lock and Thread *thread_list; // protected by fLock, signal_lock and
// gThreadCreationLock // gThreadCreationLock
struct team_loading_info *loading_info; // protected by fLock 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 watcher_list;
struct list sem_list; // protected by sSemsSpinlock struct list sem_list; // protected by sSemsSpinlock
struct list port_list; // protected by sPortsLock struct list port_list; // protected by sPortsLock
+2 -3
View File
@@ -1495,9 +1495,8 @@ public:
status_t _FindImageAtAddress(addr_t address, struct image*& _image) status_t _FindImageAtAddress(addr_t address, struct image*& _image)
{ {
struct image* image = NULL; for (struct image* image = fTeam->image_list.First();
while ((image = (struct image*)list_get_next_item(&fTeam->image_list, image != NULL; image = fTeam->image_list.GetNext(image)) {
image)) != NULL) {
image_info *info = &image->info.basic_info; image_info *info = &image->info.basic_info;
if ((address < (addr_t)info->text if ((address < (addr_t)info->text
+21 -30
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 // 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(). // the first image to be returned by get_next_image_info().
if (image->info.basic_info.type == B_APP_IMAGE) 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 else
list_add_item(&team->image_list, image); team->image_list.Add(image);
sImageTable->Insert(image); sImageTable->Insert(image);
// notify listeners // notify listeners
@@ -139,7 +139,7 @@ unregister_image(Team *team, image_id id)
struct image *image = sImageTable->Lookup(id); struct image *image = sImageTable->Lookup(id);
if (image != NULL && image->team == team->id) { if (image != NULL && image->team == team->id) {
list_remove_link(image); team->image_list.Remove(image);
sImageTable->Remove(image); sImageTable->Remove(image);
status = B_OK; status = B_OK;
} }
@@ -171,9 +171,8 @@ copy_images(team_id fromTeamId, Team *toTeam)
MutexLocker locker(sImageMutex); MutexLocker locker(sImageMutex);
struct image *image = NULL; for (struct image* image = fromTeam->image_list.First();
while ((image = (struct image*)list_get_next_item(&fromTeam->image_list, image != NULL; image = fromTeam->image_list.GetNext(image)) {
image)) != NULL) {
image_id id = register_image(toTeam, &image->info, sizeof(image->info), image_id id = register_image(toTeam, &image->info, sizeof(image->info),
true); true);
if (id < 0) if (id < 0)
@@ -190,13 +189,11 @@ copy_images(team_id fromTeamId, Team *toTeam)
int32 int32
count_images(Team *team) count_images(Team *team)
{ {
struct image *image = NULL;
int32 count = 0;
MutexLocker locker(sImageMutex); MutexLocker locker(sImageMutex);
while ((image = (struct image*)list_get_next_item(&team->image_list, image)) int32 count = 0;
!= NULL) { for (struct image* image = team->image_list.First();
image != NULL; image = team->image_list.GetNext(image)) {
count++; count++;
} }
@@ -210,25 +207,22 @@ count_images(Team *team)
status_t status_t
remove_images(Team *team) remove_images(Team *team)
{ {
struct image *image = NULL;
ASSERT(team != NULL); ASSERT(team != NULL);
mutex_lock(&sImageMutex); mutex_lock(&sImageMutex);
struct list images = {}; DoublyLinkedList<struct image> images;
list_move_to_list(&team->image_list, &images); images.TakeFrom(&team->image_list);
while ((image = (struct image*)list_get_next_item(&images,
image)) != NULL) { for (struct image* image = images.First();
image != NULL; image = images.GetNext(image)) {
sImageTable->Remove(image); sImageTable->Remove(image);
} }
mutex_unlock(&sImageMutex); mutex_unlock(&sImageMutex);
while ((image = (struct image*)list_remove_head_item(&images)) while (struct image* image = images.RemoveHead())
!= NULL) {
free(image); free(image);
}
return B_OK; 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 // iterate through the team's images
MutexLocker imageLocker(sImageMutex); MutexLocker imageLocker(sImageMutex);
struct image* image = NULL;
int32 count = 0; int32 count = 0;
while ((image = (struct image*)list_get_next_item(&team->image_list, for (struct image* image = team->image_list.First();
image)) != NULL) { image != NULL; image = team->image_list.GetNext(image)) {
if (count == *cookie) { if (count == *cookie) {
memcpy(info, &image->info.basic_info, size); memcpy(info, &image->info.basic_info, size);
(*cookie)++; (*cookie)++;
@@ -293,7 +286,6 @@ _get_next_image_info(team_id teamID, int32 *cookie, image_info *info,
static int static int
dump_images_list(int argc, char **argv) dump_images_list(int argc, char **argv)
{ {
struct image *image = NULL;
Team *team; Team *team;
if (argc > 1) { if (argc > 1) {
@@ -310,8 +302,8 @@ dump_images_list(int argc, char **argv)
kprintf(" ID %-*s size %-*s size name\n", kprintf(" ID %-*s size %-*s size name\n",
B_PRINTF_POINTER_WIDTH, "text", B_PRINTF_POINTER_WIDTH, "data"); B_PRINTF_POINTER_WIDTH, "text", B_PRINTF_POINTER_WIDTH, "data");
while ((image = (struct image*)list_get_next_item(&team->image_list, image)) for (struct image* image = team->image_list.First();
!= NULL) { image != NULL; image = team->image_list.GetNext(image)) {
image_info *info = &image->info.basic_info; image_info *info = &image->info.basic_info;
kprintf("%6" B_PRId32 " %p %-7" B_PRId32 " %p %-7" B_PRId32 " %s\n", 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 // iterate through the team's images
MutexLocker imageLocker(sImageMutex); MutexLocker imageLocker(sImageMutex);
struct image* image = NULL; struct image *image = NULL;
for (image = team->image_list.First();
while ((image = (struct image*)list_get_next_item(&team->image_list, image != NULL; image = team->image_list.GetNext(image)) {
image)) != NULL) {
if (callback(image, cookie)) if (callback(image, cookie))
break; break;
} }
-1
View File
@@ -464,7 +464,6 @@ Team::Team(team_id id, bool kernel)
thread_list = NULL; thread_list = NULL;
loading_info = NULL; loading_info = NULL;
list_init(&image_list);
list_init(&watcher_list); list_init(&watcher_list);
list_init(&sem_list); list_init(&sem_list);
list_init_etc(&port_list, port_team_link_offset()); list_init_etc(&port_list, port_team_link_offset());