]> code.delx.au - pulseaudio/blob - src/packet.c
086e4b2a80dc184658f1bebdd417b5d0c00d5b14
[pulseaudio] / src / packet.c
1 #include <assert.h>
2 #include <stdlib.h>
3
4 #include "packet.h"
5
6 struct packet* packet_new(uint32_t length) {
7 struct packet *p;
8 assert(length);
9 p = malloc(sizeof(struct packet)+length);
10 assert(p);
11
12 p->ref = 1;
13 p->length = length;
14 return p;
15 }
16
17 struct packet* packet_ref(struct packet *p) {
18 assert(p && p->ref >= 1);
19 p->ref++;
20 return p;
21 }
22
23 void packet_unref(struct packet *p) {
24 assert(p && p->ref >= 1);
25 p->ref--;
26
27 if (p->ref == 0)
28 free(p);
29 }