50 for( i = 0 ; i < chunk->
offset ; i++ )
52 free_func(chunk->
elems + i * sizeof_payload);
63 void * elem,
size_t sizeof_payload, uint64_t chunk_size )
74 if( ret->
offset == chunk_size )
82 memcpy( ret->
elems + ret->
offset * sizeof_payload , elem, sizeof_payload );
89 size_t sizeof_payload, uint64_t chunk_size,
90 void * elem,
int *did_ret )
110 memcpy( elem, chunk->
elems + (chunk->
offset - 1) * sizeof_payload , sizeof_payload );
129 return chunk->
elems + sizeof_payload * (chunk->
offset - 1 );
uint64_t offset
offset in current chunk
struct Buffered_LIFO_chunk * Buffered_LIFO_chunk_pop(struct Buffered_LIFO_chunk *chunk, size_t sizeof_payload, uint64_t chunk_size, void *elem, int *did_ret)
Get an element from the Buffered_LIFO_chunk.
size_t sizeof_payload
Sizeof a payload element.
Structure defining a chunk of LIFO. A buffered lifo consists in several chunks which are stacked in a...
struct Buffered_LIFO_chunk * next
A pointer to the next chunk (NULL if none)
void Buffered_LIFO_head_unlock(struct Buffered_LIFO *lifo)
Unlocks the Buffered_LIFO after a call to Buffered_LIFO_head.
int MALP_Spinlock_unlock(MALP_Spinlock *mutex)
Unlocks the given MALP_Spinlock.
void * Buffered_LIFO_head(struct Buffered_LIFO *lifo)
Get a reference to the head element of the Buffered_LIFO note that as no lock is held this reference ...
void Buffered_LIFO_push(struct Buffered_LIFO *lifo, void *elem)
Push an element of size sizeof_payload in the Buffered_LIFO.
struct Buffered_LIFO_chunk * Buffered_LIFO_chunk_new(size_t sizeof_payload, uint64_t chunk_size, struct Buffered_LIFO_chunk *prev)
Allocates an empty Buffered_LIFO_chunk pointing to prev.
char elems[0]
A dummy pointer to the data which is piggybacked.
void Buffered_LIFO_chunk_release(struct Buffered_LIFO_chunk *chunk, size_t sizeof_payload, void(*free_func)(void *))
Releases a Buffered_LIFO_chunk note that it does not recurses over previous chunks.
int MALP_Spinlock_lock(MALP_Spinlock *mutex)
Locks the given MALP_Spinlock.
void * Buffered_LIFO_pop(struct Buffered_LIFO *lifo, void *elem)
Push an element of size sizeof_payload in the Buffered_LIFO.
void Buffered_LIFO_release(struct Buffered_LIFO *lifo, void(*free_func)(void *))
Releases a Buffered_LIFO and all its chunks.
uint64_t chunk_size
Maximum number of elems in a chunk.
void Buffered_LIFO_init(struct Buffered_LIFO *lifo, size_t sizeof_payload, uint64_t chunk_size)
Initializes a Buffered_LIFO ready to contains elems of size sizeof_payload with chunk_size chunks...
void * Buffered_LIFO_chunk_head(struct Buffered_LIFO_chunk *chunk, size_t sizeof_payload)
Get a pointer to the Buffered_LIFO_chunk head eleme (NULL if none)
MALP_Spinlock lock
A spinlock to protect the LIFO.
struct Buffered_LIFO_chunk * Buffered_LIFO_chunk_push(struct Buffered_LIFO_chunk *chunk, void *elem, size_t sizeof_payload, uint64_t chunk_size)
Push a new elem in the Buffered_LIFO_chunk.
void * Buffered_LIFO_head_locked(struct Buffered_LIFO *lifo)
Get a reference to the head element of the Buffered_LIFO but keeps the LIFO locked in order to allow ...
Structure defining buffered LIFO.
struct Buffered_LIFO_chunk * head
A pointer to the first chunk.