Multi-ApplicationOnlineProfiling  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data_Entry.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 #ifndef DATA_ENTRY_H
20 #define DATA_ENTRY_H
21 
22 
23 #ifdef __cplusplus
24  extern "C"
25  {
26 #endif
27 
28 #include <stddef.h>
29 #include "CRC64.h"
30 #include "Chained_List.h"
31 #include "Spinlock.h"
32 
37 struct Data_entry
38 {
39  uint64_t key;
41  uint64_t ref_count;
45  size_t size;
46  char payload[0];
47 };
48 
57 struct Data_entry * Data_entry_init( uint64_t key, void *payload, size_t size );
58 
65 struct Data_entry * Data_entry_clone( struct Data_entry *de );
66 
72 void Data_entry_release( struct Data_entry *de );
73 
79 static inline void Data_entry_reset_ref_count( struct Data_entry *de )
80 {
81  MALP_Spinlock_lock( &de->lock );
82  {
83  de->ref_count = 0;
84  }
85  MALP_Spinlock_unlock( &de->lock );
86 }
87 
94 static inline uint64_t Data_entry_get_ref_count( struct Data_entry *de )
95 {
96  uint64_t ret;
97  MALP_Spinlock_lock( &de->lock );
98  {
99  ret = de->ref_count;
100  }
101  MALP_Spinlock_unlock( &de->lock );
102 
103  return ret;
104 }
105 
112 static inline void Data_entry_inc_ref_count( struct Data_entry *de, uint64_t val)
113 {
114  MALP_Spinlock_lock( &de->lock );
115  {
116  de->ref_count+= val;
117  }
118  MALP_Spinlock_unlock( &de->lock );
119 }
120 
127 static inline uint64_t Data_entry_dec_ref_count( struct Data_entry *de)
128 {
129  uint64_t ret = 0;
130  MALP_Spinlock_lock( &de->lock );
131  {
132  ret = --de->ref_count;
133  }
134  MALP_Spinlock_unlock( &de->lock );
135  return ret;
136 }
137 
144 static inline uint64_t Data_entry_get_key(struct Data_entry *de)
145 {
146  return de->key;
147 }
148 
155 static inline size_t Data_entry_get_payload_size( struct Data_entry *de )
156 {
157  return de->size;
158 }
159 
166 static inline void *Data_entry_get_payload( struct Data_entry *de )
167 {
168  return (void *)de->payload;
169 }
170 
171 
172 #ifdef __cplusplus
173  }
174 #endif
175 
176 #endif
uint64_t ref_count
the number of users of this piece of data
Definition: Data_Entry.h:41
static uint64_t Data_entry_get_key(struct Data_entry *de)
Getter on the Data_entry key.
Definition: Data_Entry.h:144
short been_resubmitted
1 if it has been re-submitted
Definition: Data_Entry.h:43
int MALP_Spinlock_unlock(MALP_Spinlock *mutex)
Unlocks the given MALP_Spinlock.
Definition: Spinlock.c:41
static void Data_entry_reset_ref_count(struct Data_entry *de)
Resets the ref_count of a Data_entry.
Definition: Data_Entry.h:79
static size_t Data_entry_get_payload_size(struct Data_entry *de)
Getter on the Data_entry payload size.
Definition: Data_Entry.h:155
static void * Data_entry_get_payload(struct Data_entry *de)
Getter on the actual data of a Data_entry.
Definition: Data_Entry.h:166
uint64_t key
the key, identifying the type of data
Definition: Data_Entry.h:39
void Data_entry_release(struct Data_entry *de)
Clears a Data_entry.
Definition: Data_Entry.c:64
static uint64_t Data_entry_get_ref_count(struct Data_entry *de)
Getter on the ref_count of a Data_entry.
Definition: Data_Entry.h:94
int MALP_Spinlock_lock(MALP_Spinlock *mutex)
Locks the given MALP_Spinlock.
Definition: Spinlock.c:29
struct Data_entry * Data_entry_init(uint64_t key, void *payload, size_t size)
Creates a new Data_entry.
Definition: Data_Entry.c:25
volatile unsigned int MALP_Spinlock
The type of spinlocks in MALP.
Definition: Spinlock.h:63
static uint64_t Data_entry_dec_ref_count(struct Data_entry *de)
Decrements the ref_count of a Data_entry.
Definition: Data_Entry.h:127
size_t size
the size of the data available in payload
Definition: Data_Entry.h:45
MALP_Spinlock lock
a lock for concurrent access
Definition: Data_Entry.h:42
Struct defining a piece of data that can exist on the blackboard.
Definition: Data_Entry.h:37
struct Data_entry * Data_entry_clone(struct Data_entry *de)
Clones a Data_entry.
Definition: Data_Entry.c:48
static void Data_entry_inc_ref_count(struct Data_entry *de, uint64_t val)
Increments the ref_count of a Data_entry by a given value.
Definition: Data_Entry.h:112
char payload[0]
the actual data
Definition: Data_Entry.h:46