62 lines
1.4 KiB
C
62 lines
1.4 KiB
C
|
/************************************************************//**
|
||
|
*
|
||
|
* @file: platform_io_internal.c
|
||
|
* @author: Martin Fouilleul
|
||
|
* @date: 11/06/2023
|
||
|
*
|
||
|
*****************************************************************/
|
||
|
|
||
|
#include"platform_io_internal.h"
|
||
|
|
||
|
file_table __globalFileTable = {0};
|
||
|
|
||
|
file_slot* file_slot_alloc(file_table* table)
|
||
|
{
|
||
|
file_slot* slot = list_pop_entry(&table->freeList, file_slot, freeListElt);
|
||
|
if(!slot && table->nextSlot < ORCA_MAX_FILE_SLOTS)
|
||
|
{
|
||
|
slot = &table->slots[table->nextSlot];
|
||
|
slot->generation = 1;
|
||
|
slot->fd = -1;
|
||
|
table->nextSlot++;
|
||
|
}
|
||
|
return(slot);
|
||
|
}
|
||
|
|
||
|
void file_slot_recycle(file_table* table, file_slot* slot)
|
||
|
{
|
||
|
slot->generation++;
|
||
|
list_push(&table->freeList, &slot->freeListElt);
|
||
|
}
|
||
|
|
||
|
file_handle file_handle_from_slot(file_table* table, file_slot* slot)
|
||
|
{
|
||
|
u64 index = slot - table->slots;
|
||
|
u64 generation = slot->generation;
|
||
|
file_handle handle = {.h = (generation<<32) | index };
|
||
|
return(handle);
|
||
|
}
|
||
|
|
||
|
file_slot* file_slot_from_handle(file_table* table, file_handle handle)
|
||
|
{
|
||
|
file_slot* slot = 0;
|
||
|
|
||
|
u64 index = handle.h & 0xffffffff;
|
||
|
u64 generation = handle.h>>32;
|
||
|
|
||
|
if(index < table->nextSlot)
|
||
|
{
|
||
|
file_slot* candidate = &table->slots[index];
|
||
|
if(candidate->generation == generation)
|
||
|
{
|
||
|
slot = candidate;
|
||
|
}
|
||
|
}
|
||
|
return(slot);
|
||
|
}
|
||
|
|
||
|
io_cmp io_wait_single_req(io_req* req)
|
||
|
{
|
||
|
return(io_wait_single_req_with_table(req, &__globalFileTable));
|
||
|
}
|