Multi-ApplicationOnlineProfiling  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Buffered_FIFO.h
Go to the documentation of this file.
1 /* ############################ MALP License ############################## */
2 /* # Fri Jan 18 14:00:00 CET 2013 # */
3 /* # Copyright or (C) or Copr. Commissariat a l'Energie Atomique # */
4 /* # # */
5 /* # This software is governed by the CeCILL-C license under French law # */
6 /* # and abiding by the rules of distribution of free software. You can # */
7 /* # use, modify and/ or redistribute the software under the terms of # */
8 /* # the CeCILL-C license as circulated by CEA, CNRS and INRIA at the # */
9 /* # following URL http://www.cecill.info. # */
10 /* # # */
11 /* # The fact that you are presently reading this means that you have # */
12 /* # had knowledge of the CeCILL-C license and that you accept its # */
13 /* # terms. # */
14 /* # # */
15 /* # Authors: # */
16 /* # - BESNARD Jean-Baptiste jean-baptiste.besnard@cea.fr # */
17 /* # # */
18 /* ######################################################################## */
19 
25 #ifndef BUFFERED_FIFO_H
26 #define BUFFERED_FIFO_H
27 
28 
29 #ifdef __cplusplus
30  extern "C"
31  {
32 #endif
33 
34 
35 
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <stdint.h>
39 
40 #include "Spinlock.h"
41 
50  char *payload;
51  uint64_t chunk_size;
52  size_t elem_size;
53  uint64_t start_offset;
54  uint64_t end_offset;
57 };
58 
66  uint64_t chunk_size, size_t elem_size );
67 
75 
81 
88 void * Buffered_FIFO_chunk_push( struct Buffered_FIFO_chunk *ch, void *elem );
89 
96 void * Buffered_FIFO_chunk_pop( struct Buffered_FIFO_chunk *ch, void *dest );
97 
104 {
105  MALP_Spinlock_lock( &ch->lock );
106  ch->prev = prev;
107  MALP_Spinlock_unlock( &ch->lock );
108 }
109 
116 {
117  struct Buffered_FIFO_chunk *ret;
118  MALP_Spinlock_lock( &ch->lock );
119  ret =ch->prev;
120  MALP_Spinlock_unlock( &ch->lock );
121 
122  return ret;
123 }
124 
144  uint64_t chunk_size;
145  size_t elem_size;
148  uint64_t elem_count;
149 };
150 
157 void Buffered_FIFO_init(struct Buffered_FIFO *fifo, uint64_t chunk_size, size_t elem_size);
158 
166 void Buffered_FIFO_release(struct Buffered_FIFO *fifo, void (*free_func) (void *));
167 
174 void *Buffered_FIFO_push(struct Buffered_FIFO *fifo, void *elem);
175 
182 void *Buffered_FIFO_pop(struct Buffered_FIFO *fifo, void *dest);
183 
189 uint64_t Buffered_FIFO_count(struct Buffered_FIFO *fifo);
190 
191 #ifdef __cplusplus
192  }
193 #endif
194 
195 
196 #endif /* BUFFERED_FIFO_H */
197 
void * Buffered_FIFO_chunk_pop(struct Buffered_FIFO_chunk *ch, void *dest)
pops en element from a chunk
Definition: Buffered_FIFO.c:97
MALP_Spinlock head_lock
a lock for concurent access to the head
MALP_Spinlock tail_lock
a lock for concurent access to the tail
uint64_t chunk_size
the size of the composing chunks
size_t elem_size
the size of each stored element
void Buffered_FIFO_release(struct Buffered_FIFO *fifo, void(*free_func)(void *))
releases a FIFO
This is a struct defining a FIFO It is composed of several Buffered_FIFO_chunk.
void * Buffered_FIFO_push(struct Buffered_FIFO *fifo, void *elem)
Pushes an element into a FIFO.
char * payload
the actual data
Definition: Buffered_FIFO.h:50
void * Buffered_FIFO_pop(struct Buffered_FIFO *fifo, void *dest)
Pops an element from a FIFO.
void * Buffered_FIFO_chunk_push(struct Buffered_FIFO_chunk *ch, void *elem)
Pushes an element into a chunk.
Definition: Buffered_FIFO.c:76
MALP_Spinlock lock
a lock for concurrent access to element_count
int MALP_Spinlock_unlock(MALP_Spinlock *mutex)
Unlocks the given MALP_Spinlock.
Definition: Spinlock.c:41
struct Buffered_FIFO_chunk * tail
the tail chunk (from where elements are popped
size_t elem_size
the size of stored elements
Definition: Buffered_FIFO.h:52
uint64_t start_offset
the start offset (position of oldest element in payload
Definition: Buffered_FIFO.h:53
struct Buffered_FIFO_chunk * Buffered_FIFO_chunk_new(uint64_t chunk_size, uint64_t elem_size)
Allocates a new Buffered_FIFO_chunk.
Definition: Buffered_FIFO.c:54
uint64_t Buffered_FIFO_count(struct Buffered_FIFO *fifo)
Thread-safely gets the number of elements stored in the FIFO.
Definition: Buffered_FIFO.c:23
void Buffered_FIFO_chunk_release(struct Buffered_FIFO_chunk *ch)
Deallocates a new Buffered_FIFO_chunk.
Definition: Buffered_FIFO.c:70
static struct Buffered_FIFO_chunk * Buffered_FIFO_chunk_prev(struct Buffered_FIFO_chunk *ch)
Thread-safely gets the previous chunk (ch->prev)
int MALP_Spinlock_lock(MALP_Spinlock *mutex)
Locks the given MALP_Spinlock.
Definition: Spinlock.c:29
MALP_Spinlock lock
a lock for concurrent internal manipulations
Definition: Buffered_FIFO.h:49
volatile unsigned int MALP_Spinlock
The type of spinlocks in MALP.
Definition: Spinlock.h:63
struct Buffered_FIFO_chunk * prev
previous chunk of the FIFO (newer elements)
Definition: Buffered_FIFO.h:56
struct Buffered_FIFO_chunk * head
the head chunk (chere elements are pushed
void Buffered_FIFO_init(struct Buffered_FIFO *fifo, uint64_t chunk_size, size_t elem_size)
Initializes a Buffered_FIFO.
static void Buffered_FIFO_chunk_ctx_prev(struct Buffered_FIFO_chunk *ch, struct Buffered_FIFO_chunk *prev)
Thread-safely sets the previous chunk (ch->prev)
void Buffered_FIFO_chunk_init(struct Buffered_FIFO_chunk *ch, uint64_t chunk_size, size_t elem_size)
Initializes a Buffered_FIFO_chunk.
uint64_t end_offset
the end offset (position of the end of newest element in payload
Definition: Buffered_FIFO.h:54
uint64_t chunk_size
the size of the current chunk
Definition: Buffered_FIFO.h:51
Structure defining a chunk of FIFO. The Buffered_FIFO is made of several Buffered_FIFO_chunk containi...
Definition: Buffered_FIFO.h:48
uint64_t elem_count
the number of elements currently stored in the FIFO