Multi-ApplicationOnlineProfiling  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Buffered LIFO

This is an implementation of a Buffered LIFO data storage. More...

Modules

 Internals
 Not to be used directly.
 

Data Structures

struct  Buffered_LIFO
 Structure defining buffered LIFO. More...
 

Functions

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. More...
 
void Buffered_LIFO_release (struct Buffered_LIFO *lifo, void(*free_func)(void *))
 Releases a Buffered_LIFO and all its chunks. More...
 
void Buffered_LIFO_push (struct Buffered_LIFO *lifo, void *elem)
 Push an element of size sizeof_payload in the Buffered_LIFO. More...
 
void * Buffered_LIFO_pop (struct Buffered_LIFO *lifo, void *elem)
 Push an element of size sizeof_payload in the Buffered_LIFO. More...
 
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 can be invalidated by another thread. In such context you can use Buffered_LIFO_head_locked instead. More...
 
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 thread safe manipulation of the head. Note that Buffered_LIFO_head_unlock must be called to unlock the LIFO after ! More...
 
void Buffered_LIFO_head_unlock (struct Buffered_LIFO *lifo)
 Unlocks the Buffered_LIFO after a call to Buffered_LIFO_head. More...
 

Detailed Description

This is an implementation of a Buffered LIFO data storage.

It is implemented using several Buffered_LIFO_chunk.

dot_LIFO.png
Buffered LIFO Illustration

Sample usage :

struct Buffered_LIFO lifo;
Buffered_LIFO_init( &lifo, sizeof(int), 1024 );
int i;
#define LIFO_PP_SIZE 3
for( i = 0 ; i < LIFO_PP_SIZE ; i++ )
{
Buffered_LIFO_push( &lifo, (void *)&i );
}
int out = -1;
while( Buffered_LIFO_pop( &lifo, (void *)&out ) )
{
printf("%d\n", out );
}
Buffered_LIFO_release( &lifo, NULL );
dot_inline_dotgraph_3.png

Consequently in this configuration, we pop elems in the reverse order by definition of the LIFO (2,1,0).

Function Documentation

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 can be invalidated by another thread. In such context you can use Buffered_LIFO_head_locked instead.

Parameters
lifopointer to an initialized Buffered_LIFO
Returns
a pointer to the head element of the LIFO, NULL if none

Definition at line 188 of file Buffered_LIFO.c.

Here is the call graph for this function:

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 thread safe manipulation of the head. Note that Buffered_LIFO_head_unlock must be called to unlock the LIFO after !

Parameters
lifopointer to an initialized Buffered_LIFO
Returns
a pointer to the head element of the LIFO, NULL if none

Definition at line 198 of file Buffered_LIFO.c.

Here is the call graph for this function:

void Buffered_LIFO_head_unlock ( struct Buffered_LIFO lifo)

Unlocks the Buffered_LIFO after a call to Buffered_LIFO_head.

Parameters
lifopointer to an initialized Buffered_LIFO

Definition at line 204 of file Buffered_LIFO.c.

Here is the call graph for this function:

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.

Parameters
sizeof_payloadsize of a payload element
chunk_sizethe number of elements the chunk can contain

Definition at line 132 of file Buffered_LIFO.c.

void* Buffered_LIFO_pop ( struct Buffered_LIFO lifo,
void *  elem 
)

Push an element of size sizeof_payload in the Buffered_LIFO.

Parameters
lifopointer to an initialized Buffered_LIFO
elempointer to an elem of sizeof_payload to which we want data to be copied
Returns
elem if an element was popped, NULL otherwise

Definition at line 171 of file Buffered_LIFO.c.

Here is the call graph for this function:

void Buffered_LIFO_push ( struct Buffered_LIFO lifo,
void *  elem 
)

Push an element of size sizeof_payload in the Buffered_LIFO.

Parameters
lifopointer to an initialized Buffered_LIFO
elempointer to an elem of sizeof_payload

Definition at line 164 of file Buffered_LIFO.c.

Here is the call graph for this function:

void Buffered_LIFO_release ( struct Buffered_LIFO lifo,
void(*)(void *)  free_func 
)

Releases a Buffered_LIFO and all its chunks.

Parameters
sizeof_payloadsize of a payload element
chunk_sizethe number of elements the chunk can contain
free_funca function to be called over each elem still present in the FIFO (NULL if node)

Definition at line 141 of file Buffered_LIFO.c.

Here is the call graph for this function: