LF OS
Hobby operating system for amd64 with high ambitions
Loading...
Searching...
No Matches
tpa.h File Reference

(99b1219 userspace/term: compile-in klsh, remove htop dump)

#include <allocator.h>
#include <stdint.h>
+ Include dependency graph for tpa.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct tpa tpa_t
 

Functions

tpa_ttpa_new (allocator_t *alloc, uint64_t entry_size, uint64_t page_size, tpa_t *tpa)
 
void tpa_delete (tpa_t *tpa)
 
void * tpa_get (tpa_t *tpa, size_t idx)
 
void tpa_set (tpa_t *tpa, size_t idx, void *data)
 
size_t tpa_size (tpa_t *tpa)
 
ssize_t tpa_length (tpa_t *tpa)
 
size_t tpa_entries (tpa_t *tpa)
 
size_t tpa_next (tpa_t *tpa, size_t cur)
 

Typedef Documentation

◆ tpa_t

typedef struct tpa tpa_t

Definition at line 7 of file tpa.h.

Function Documentation

◆ tpa_delete()

void tpa_delete ( tpa_t tpa)

Deallocate every data in use by the given TPA And the TPA itself

Parameters
tpaThe TPA to destroy

Definition at line 61 of file tpa.c.

References tpa::allocator, allocator::dealloc, tpa::first, and tpa_page_header::next.

+ Here is the caller graph for this function:

◆ tpa_entries()

size_t tpa_entries ( tpa_t tpa)

Counts the number of existing entries in the TPA

Remarks
Has to search through the TPA and might be slow
Parameters
tpaThe TPA
Returns
The number of entries currently set in the TPA

Definition at line 110 of file tpa.c.

References tpa::first, tpa_page_header::next, tpa_entries_per_page(), and tpa_entry_exists_in_page().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tpa_get()

void * tpa_get ( tpa_t tpa,
size_t  idx 
)

Retrieve a given element from the TPA or NULL if the element is not present

Parameters
tpaThe TPA
idxThe index of the element to retrieve
Returns
pointer to the first byte of the entry

Definition at line 144 of file tpa.c.

References tpa_page_header::start_idx, tpa_entry_exists_in_page(), tpa_get_page_for_idx(), and tpa_offset_in_page().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tpa_length()

ssize_t tpa_length ( tpa_t tpa)

Retrieve the highest index currently possible without new allocation

Remarks
Has to search through the TPA and might be slow
Parameters
tpaThe TPA
Returns
The index after the last entry in the last allocated page or -1

Definition at line 87 of file tpa.c.

References tpa::first, tpa_page_header::next, tpa_page_header::start_idx, and tpa_entries_per_page().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tpa_new()

tpa_t * tpa_new ( allocator_t alloc,
uint64_t  entry_size,
uint64_t  page_size,
tpa_t tpa 
)

Allocate and initialize a new Thin Provisioned Array

Parameters
allocAllocator function to use
deallocDeallocator function to use
entry_sizeSize of each entry
page_sizeSize of each data page
tpaPointer to a memory region to use as tpa, 0 to alloc internally
Returns
A new TPA to use

Definition at line 48 of file tpa.c.

References allocator::alloc, alloc, tpa::allocator, tpa::entry_size, tpa::first, and tpa::page_size.

+ Here is the caller graph for this function:

◆ tpa_next()

size_t tpa_next ( tpa_t tpa,
size_t  cur 
)

Returns the next non-empty element after cur

Remarks
Has to iterate through the pages to get the page to the cur idx
Parameters
tpaThe TPA
curThe current index
Returns
The next non-empty element index after cur. Special case: returns 0 when nothing found, you are expected to check if the returned value is larger than cur to check if something was found.

Definition at line 223 of file tpa.c.

References tpa::first, tpa_page_header::next, tpa_page_header::start_idx, tpa_entries_per_page(), and tpa_get_marker().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tpa_set()

void tpa_set ( tpa_t tpa,
size_t  idx,
void *  data 
)

Set new data at the given index

Remarks
This function might have to allocate a new page and could take some time to complete
Parameters
tpaThe TPA
idxWhere to place the new entry
dataPointer to the first byte of the data to store

Definition at line 174 of file tpa.c.

References allocator::alloc, tpa::allocator, tpa::entry_size, tpa::first, memcpy(), memset(), tpa_page_header::next, tpa::page_size, tpa_page_header::prev, tpa_page_header::start_idx, tpa_clean_page(), tpa_entries_per_page(), tpa_get_marker(), tpa_get_page_for_idx(), and tpa_offset_in_page().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tpa_size()

size_t tpa_size ( tpa_t tpa)

Returns the allocated size of the TPA in bytes

Remarks
Has to search through the TPA and might be slow
Returns
The size of all pages combined of this TPA in bytes

Definition at line 72 of file tpa.c.

References tpa::first, tpa_page_header::next, and tpa::page_size.

+ Here is the caller graph for this function: