2004-01-29 01:02:12 +00:00
|
|
|
/* Icecast
|
|
|
|
*
|
|
|
|
* This program is distributed under the GNU General Public License, version 2.
|
|
|
|
* A copy of this license is included with this source.
|
|
|
|
*
|
|
|
|
* Copyright 2000-2004, Jack Moffitt <jack@xiph.org,
|
|
|
|
* Michael Smith <msmith@xiph.org>,
|
|
|
|
* oddsock <oddsock@xiph.org>,
|
|
|
|
* Karl Heyes <karl@xiph.org>
|
|
|
|
* and others (see AUTHORS for details).
|
|
|
|
*/
|
|
|
|
|
2001-09-10 02:21:46 +00:00
|
|
|
/* refbuf.c
|
|
|
|
**
|
|
|
|
** reference counting buffer implementation
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2003-07-21 01:58:54 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2001-09-10 02:21:46 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "refbuf.h"
|
|
|
|
|
|
|
|
void refbuf_initialize(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void refbuf_shutdown(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
refbuf_t *refbuf_new(unsigned long size)
|
|
|
|
{
|
2003-03-15 02:10:19 +00:00
|
|
|
refbuf_t *refbuf;
|
2001-09-10 02:21:46 +00:00
|
|
|
|
2003-03-15 02:10:19 +00:00
|
|
|
refbuf = (refbuf_t *)malloc(sizeof(refbuf_t));
|
2004-08-20 15:13:59 +00:00
|
|
|
if (refbuf == NULL)
|
|
|
|
return NULL;
|
|
|
|
refbuf->data = NULL;
|
|
|
|
if (size)
|
|
|
|
{
|
|
|
|
refbuf->data = malloc (size);
|
|
|
|
if (refbuf->data == NULL)
|
|
|
|
{
|
|
|
|
free (refbuf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2003-03-15 02:10:19 +00:00
|
|
|
refbuf->len = size;
|
|
|
|
refbuf->_count = 1;
|
2004-08-20 15:13:59 +00:00
|
|
|
refbuf->next = NULL;
|
|
|
|
refbuf->associated = NULL;
|
2001-09-10 02:21:46 +00:00
|
|
|
|
2003-03-15 02:10:19 +00:00
|
|
|
return refbuf;
|
2001-09-10 02:21:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void refbuf_addref(refbuf_t *self)
|
|
|
|
{
|
2003-03-15 02:10:19 +00:00
|
|
|
self->_count++;
|
2001-09-10 02:21:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void refbuf_release(refbuf_t *self)
|
|
|
|
{
|
2003-03-15 02:10:19 +00:00
|
|
|
self->_count--;
|
|
|
|
if (self->_count == 0) {
|
2004-08-20 15:13:59 +00:00
|
|
|
while (self->associated)
|
|
|
|
{
|
|
|
|
refbuf_t *ref = self->associated;
|
|
|
|
self->associated = ref->next;
|
|
|
|
refbuf_release (ref);
|
|
|
|
}
|
2003-03-15 02:10:19 +00:00
|
|
|
free(self->data);
|
|
|
|
free(self);
|
2003-03-30 13:52:27 +00:00
|
|
|
return;
|
2003-03-15 02:10:19 +00:00
|
|
|
}
|
2001-09-10 02:21:46 +00:00
|
|
|
}
|
|
|
|
|