PULSAR  1.0.0
Parallel Ultra Light Systolic Array Runtime
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
prt_packet.c
Go to the documentation of this file.
1 
11 #include "prt_packet.h"
12 
14 
23 prt_packet_t *prt_packet_new(size_t data_size)
24 {
25  prt_packet_t *packet = (prt_packet_t*)malloc(sizeof(prt_packet_t));
26  prt_assert(packet != NULL, "malloc failed");
27 
28  packet->data = malloc(data_size);
29  prt_assert(packet->data != NULL, "malloc failed");
30 
31  packet->num_refs = 1;
32  return packet;
33 }
34 
36 
45 {
46  int num_refs = __sync_sub_and_fetch(&packet->num_refs, 1);
47  prt_assert(num_refs >= 0, "negative number of data references");
48  if (num_refs == 0) {
49  free(packet->data);
50  free(packet);
51  }
52 }
void prt_packet_release(prt_packet_t *packet)
Release a packet. Decrements the number of active references. Destroys the packet when the last refer...
Definition: prt_packet.c:44
VDP's data packet A packet of data transferred through VDP's channels.
Definition: prt_packet.h:24
void * data
Definition: prt_packet.h:25
#define prt_assert(cond, msg)
Definition: prt_assert.h:30
prt_packet_t * prt_packet_new(size_t data_size)
packet constructor Sets the number of references to one.
Definition: prt_packet.c:23
PRT data packet.