Change formatting rules
All checks were successful
Build ISO image / build-and-deploy (push) Successful in 2m7s
Build documentation / build-and-deploy (push) Successful in 39s

This commit is contained in:
2026-04-24 01:54:48 +02:00
parent 34f7809a2d
commit c8fb575bdd
208 changed files with 6310 additions and 6339 deletions

View File

@@ -6,57 +6,57 @@
#include <sync/spin_lock.h>
#include <sys/debug.h>
bool id_alloc_init (struct id_alloc* ida, size_t nbits) {
bool id_alloc_init(struct id_alloc* ida, size_t nbits) {
size_t buffer_size = (nbits + 7) / 8;
uint8_t* buffer = malloc (buffer_size);
uint8_t* buffer = malloc(buffer_size);
if (buffer == NULL)
return false;
bm_init (&ida->bm, buffer, nbits);
bm_init(&ida->bm, buffer, nbits);
ida->lock = SPIN_LOCK_INIT;
return true;
}
void id_alloc_fini (struct id_alloc* ida) {
free (ida->bm.base);
void id_alloc_fini(struct id_alloc* ida) {
free(ida->bm.base);
ida->bm.base = NULL;
ida->bm.nbits = 0;
}
int id_alloc (struct id_alloc* ida) {
int id_alloc(struct id_alloc* ida) {
uint64_t fid;
spin_lock (&ida->lock, &fid);
spin_lock(&ida->lock, &fid);
size_t start = ida->next_id;
size_t current = start;
do {
if (!bm_test (&ida->bm, current)) {
bm_set (&ida->bm, current);
if (!bm_test(&ida->bm, current)) {
bm_set(&ida->bm, current);
ida->next_id = (current + 1) % ida->bm.nbits;
spin_unlock (&ida->lock, fid);
spin_unlock(&ida->lock, fid);
return (int)current;
}
current = (current + 1) % ida->bm.nbits;
} while (current != start);
spin_unlock (&ida->lock, fid);
spin_unlock(&ida->lock, fid);
return -ST_OOM_ERROR;
}
void id_free (struct id_alloc* ida, int id) {
void id_free(struct id_alloc* ida, int id) {
uint64_t fid;
if (id < 0)
return;
spin_lock (&ida->lock, &fid);
bm_clear (&ida->bm, (size_t)id);
spin_unlock (&ida->lock, fid);
spin_lock(&ida->lock, &fid);
bm_clear(&ida->bm, (size_t)id);
spin_unlock(&ida->lock, fid);
}

View File

@@ -11,12 +11,12 @@ struct id_alloc {
int next_id;
};
int id_alloc (struct id_alloc* ida);
int id_alloc(struct id_alloc* ida);
void id_free (struct id_alloc* ida, int id);
void id_free(struct id_alloc* ida, int id);
bool id_alloc_init (struct id_alloc* ida, size_t nbits);
bool id_alloc_init(struct id_alloc* ida, size_t nbits);
void id_alloc_fini (struct id_alloc* ida);
void id_alloc_fini(struct id_alloc* ida);
#endif // _KERNEL_ID_ID_ALLOC_H