Multi-ApplicationOnlineProfiling  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data_Entry.c
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 #include "Data_Entry.h"
20 #include "Key_Entry.h"
21 
22 #include <stdlib.h>
23 #include <string.h>
24 
25 struct Data_entry * Data_entry_init( uint64_t key, void *payload, size_t size )
26 {
27  struct Data_entry *ret = malloc( sizeof( struct Data_entry) + size );
28 
29  if( !ret )
30  {
31  perror("malloc");
32  return NULL;
33  }
34 
35  ret->lock = 0;
36  ret->key = key;
37  ret->ref_count = 0;
38  ret->size = size;
39  ret->been_resubmitted = 0;
40 
41  if( payload )
42  memcpy((void *)ret->payload, payload, size);
43 
44  return ret;
45 
46 }
47 
48 struct Data_entry * Data_entry_clone( struct Data_entry *de )
49 {
50  struct Data_entry *ret = malloc( sizeof( struct Data_entry) + de->size );
51 
52  if( !ret )
53  {
54  perror("malloc");
55  return NULL;
56  }
57 
58  memcpy((void *)ret, de, sizeof( struct Data_entry) + de->size);
59 
60  return ret;
61 }
62 
63 
64 void Data_entry_release( struct Data_entry *de )
65 {
66  de->lock = 1;
67  de->key = 0;
68  de->size = 0;
69 
70  free( de );
71 }
uint64_t ref_count
the number of users of this piece of data
Definition: Data_Entry.h:41
short been_resubmitted
1 if it has been re-submitted
Definition: Data_Entry.h:43
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
struct Data_entry * Data_entry_init(uint64_t key, void *payload, size_t size)
Creates a new Data_entry.
Definition: Data_Entry.c:25
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
char payload[0]
the actual data
Definition: Data_Entry.h:46