Changeset 4522:c335603c6371 in roaraudio


Ignore:
Timestamp:
10/16/10 17:33:36 (8 years ago)
Author:
phi
Branch:
default
Message:

added refing and unrefing of buffers

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • include/libroar/buffer.h

    r4516 r4522  
    5959#define roar_buffer_new(a,len) roar_buffer_new_data((a), (len), NULL) 
    6060 
     61#define roar_buffer_free(x)    roar_buffer_unref(x) 
     62 
    6163int roar_buffer_new_no_ma(struct roar_buffer ** buf, size_t len, void * data); // no internal malloc 
    62 int roar_buffer_free     (struct roar_buffer *  buf); 
    6364int roar_buffer_delete   (struct roar_buffer *  buf, struct roar_buffer ** next); 
    6465int roar_buffer_add      (struct roar_buffer *  buf, struct roar_buffer *  next); 
     66 
     67int roar_buffer_ref      (struct roar_buffer *  buf); 
     68int roar_buffer_unref    (struct roar_buffer *  buf); 
    6569 
    6670int roar_buffer_new_data (struct roar_buffer ** buf, size_t len, void ** data); 
  • libroar/buffer.c

    r4516 r4522  
    9393 } 
    9494 
     95 new->refc      = 1; 
     96 
    9597 new->data      = data; 
    9698 
     
    110112} 
    111113 
    112 int roar_buffer_free     (struct roar_buffer * buf) { 
     114int roar_buffer_ref      (struct roar_buffer *  buf) { 
     115 if ( buf == NULL ) 
     116  return -1; 
     117 
     118 buf->refc++; 
     119 
     120 return 0; 
     121} 
     122 
     123int roar_buffer_unref     (struct roar_buffer * buf) { 
    113124 struct roar_buffer * next; 
    114125 
    115126 if ( buf == NULL ) 
    116127  return -1; 
     128 
     129 if ( buf->refc == 0 ) { 
     130  ROAR_WARN("roar_buffer_unref(buf=%p): Ref counter is wrong. assuming one."); 
     131  buf->refc = 1; 
     132 } 
     133 
     134 buf->refc--; 
     135 
     136 if ( buf->refc ) 
     137  return 0; 
    117138 
    118139 while ((next = buf->next)) { 
Note: See TracChangeset for help on using the changeset viewer.