Changeset 4625:b38e2e191e5b in roaraudio


Ignore:
Timestamp:
11/27/10 03:42:03 (11 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

Updated ring buffer code (Closes: #91)

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r4620 r4625  
    1111        * Corrected error codes in VS API (Closes: #90) 
    1212        * Updated reassigned commands (GET_ACL->AUTHCTL, SET_ACL->ACLCTL) 
     13        * Updated ring buffer code (Closes: #91) 
    1314 
    1415v. 0.4beta1 - Mon Nov 01 2010 16:14 CET 
  • include/libroar/buffer.h

    r4522 r4625  
    9999int roar_buffer_ring_write (struct roar_buffer *  buf, void * data, size_t * len); 
    100100 
     101int roar_buffer_ring_avail(struct roar_buffer *  buf, size_t * readlen, size_t * writelen); 
     102 
    101103#endif 
    102104 
  • libroar/buffer.c

    r4624 r4625  
    577577 size_t tmp; 
    578578 
     579 ROAR_DBG("roar_buffer_ring_write(buf=%p, data=%p, len=%p) = ?", buf, data, len); 
     580 
    579581 if ( buf == NULL || len == NULL ) 
    580582  return -1; 
     
    618620 
    619621  if ( ring->write_pos >= ring->read_pos ) { 
     622   ROAR_DBG("roar_buffer_ring_write(buf=%p, data=%p, len=%p) = ?", buf, data, len); 
     623 
    620624   havelen = buf->user_len - ring->write_pos; 
    621625 
     
    642646 
    643647   *len = done; 
     648   ROAR_DBG("roar_buffer_ring_write(buf=%p, data=%p, len=%p) = 0", buf, data, len); 
    644649   return 0; 
    645650  } else { 
     651   ROAR_DBG("roar_buffer_ring_write(buf=%p, data=%p, len=%p) = ?", buf, data, len); 
     652 
    646653   // test for buffer-is-full: 
    647654   if ( (ring->write_pos + 1) == ring->read_pos ) { 
    648655    *len = 0; 
     656    ROAR_DBG("roar_buffer_ring_write(buf=%p, data=%p, len=%p) = 0", buf, data, len); 
    649657    return 0; 
    650658   } 
    651659 
     660   ROAR_DBG("roar_buffer_ring_write(buf=%p, data=%p, len=%p) = ?", buf, data, len); 
     661 
    652662   havelen = ring->read_pos - ring->write_pos - 1; 
    653663 
     
    657667   memcpy(buf->user_data+ring->write_pos, data, havelen); 
    658668 
     669   ring->write_pos += havelen; 
    659670   *len = havelen; 
     671 
     672   ROAR_DBG("roar_buffer_ring_write(buf=%p, data=%p, len=%p) = 0", buf, data, len); 
    660673   return 0; 
    661674  } 
     
    667680} 
    668681 
     682int roar_buffer_ring_avail(struct roar_buffer *  buf, size_t * readlen, size_t * writelen) { 
     683 struct roar_buffer_ring * ring; 
     684 size_t have; 
     685 
     686 if ( buf == NULL ) 
     687  return -1; 
     688 
     689 if ( !(buf->flags & ROAR_BUFFER_FLAG_RING) ) 
     690  return -1; 
     691 
     692 ring = &(buf->meta.ring); 
     693 
     694 ROAR_DBG("roar_buffer_ring_avail(buf=%p, readlen=%p, writelen=%p) = ?", buf, readlen, writelen); 
     695 
     696 if ( readlen != NULL ) { 
     697  have = 0; 
     698 
     699  if ( ring->write_pos >= ring->read_pos ) { 
     700   have  = ring->write_pos - ring->read_pos; 
     701  } else { 
     702   have  = buf->user_len - ring->read_pos; 
     703   have += ring->write_pos; 
     704   have -= 1; 
     705  } 
     706 
     707  *readlen = have; 
     708  ROAR_DBG("roar_buffer_ring_avail(buf=%p, readlen=%p, writelen=%p): readlen=%llu", buf, readlen, writelen, (unsigned long long int)have); 
     709 } 
     710 
     711 if ( writelen != NULL ) { 
     712  have = 0; 
     713 
     714  if ( ring->read_pos > ring->write_pos ) { 
     715   have  = ring->read_pos - ring->write_pos - 1; 
     716  } else { 
     717   have  = buf->user_len - ring->write_pos; 
     718   have += ring->read_pos; 
     719   have -= 1; 
     720  } 
     721 
     722  *writelen = have; 
     723  ROAR_DBG("roar_buffer_ring_avail(buf=%p, readlen=%p, writelen=%p): readlen=%llu", buf, readlen, writelen, (unsigned long long int)have); 
     724 } 
     725 
     726 ROAR_DBG("roar_buffer_ring_avail(buf=%p, readlen=%p, writelen=%p) = 0", buf, readlen, writelen); 
     727 
     728 return 0; 
     729} 
     730 
    669731//ll 
Note: See TracChangeset for help on using the changeset viewer.