PULSAR  0.1
Parallel Unified Linear Algebra with Systolic Arrays
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
prt_packet.c
Go to the documentation of this file.
1 
11 #include "prt_packet.h"
12 
14 
22 prt_packet_t *prt_packet_new(size_t data_size)
23 {
24  prt_packet_t *packet = (prt_packet_t*)malloc(sizeof(prt_packet_t));
25  prt_assert(packet != NULL, "malloc failed");
26 
27  packet->data = malloc(data_size);
28  prt_assert(packet->data != NULL, "malloc failed");
29 
30  packet->num_refs = 1;
31  return packet;
32 }
33 
35 
43 {
44  int num_refs = __sync_sub_and_fetch(&packet->num_refs, 1);
45  prt_assert(num_refs >= 0, "negative number of data references");
46  if (num_refs == 0) {
47  free(packet->data);
48  free(packet);
49  }
50 }
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 data packet.
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:42
prt_packet_t * prt_packet_new(size_t data_size)
packet constructor Sets the number of references to one.
Definition: prt_packet.c:22