Changeset 5388:e5cc8e03a3e1 in roaraudio for libroar/vio.c


Ignore:
Timestamp:
01/17/12 11:27:07 (12 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

Added support for refcount based VIOs as well as dynamically allocated VIOs (non-stack or global VIOs) (Closes: #127)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroar/vio.c

    r5381 r5388  
    5353 memset((void*)calls, 0, sizeof(struct roar_vio_calls)); 
    5454 calls->flags = ROAR_VIO_FLAGS_NONE; 
    55  calls->refc  = 0; 
     55 calls->refc  = 1; 
    5656 
    5757 return 0; 
     
    202202} 
    203203 
    204 int     roar_vio_close    (struct roar_vio_calls * vio) { 
     204 
     205int     roar_vio_ref      (struct roar_vio_calls * vio) { 
     206 if ( vio == NULL ) { 
     207  roar_err_set(ROAR_ERROR_FAULT); 
     208  return -1; 
     209 } 
     210 
     211 vio->refc++; 
     212 
     213 return 0; 
     214} 
     215 
     216int     roar_vio_unref    (struct roar_vio_calls * vio) { 
    205217 int ret; 
    206218 
    207  ROAR_DBG("roar_vio_close(vio=%p) = ?", vio); 
    208  
    209  if ( vio == NULL ) { 
    210   roar_err_set(ROAR_ERROR_FAULT); 
    211   return -1; 
    212  } 
    213  
    214  if ( vio->close == NULL ) { 
     219 ROAR_DBG("roar_vio_unref(vio=%p) = ?", vio); 
     220 
     221 if ( vio == NULL ) { 
     222  roar_err_set(ROAR_ERROR_FAULT); 
     223  return -1; 
     224 } 
     225 
     226 if ( vio->refc == 1 && vio->close == NULL ) { 
    215227  roar_err_set(ROAR_ERROR_NOSYS); 
    216228  return -1; 
    217229 } 
     230 
     231 vio->refc--; 
     232 
     233 if ( vio->refc ) 
     234  return 0; 
    218235 
    219236 roar_err_clear_all(); 
     
    221238 roar_err_update(); 
    222239 
     240 if ( vio->flags & ROAR_VIO_FLAGS_FREESELF ) 
     241  roar_mm_free(vio); 
     242 
    223243 return ret; 
    224244} 
     
    257277 
    258278 memset((void*)calls, 0, sizeof(struct roar_vio_calls)); 
     279 calls->flags    = ROAR_VIO_FLAGS_NONE; 
     280 calls->refc     = 1; 
    259281 
    260282 calls->read     = roar_vio_basic_read; 
     
    642664 
    643665 memset((void*)calls, 0, sizeof(struct roar_vio_calls)); 
     666 calls->flags    = ROAR_VIO_FLAGS_NONE; 
     667 calls->refc     = 1; 
    644668 
    645669 calls->read     = roar_vio_pass_read; 
Note: See TracChangeset for help on using the changeset viewer.