@ -36,7 +36,7 @@ int RingBuffer::WriteBytesAvailable() {
int RingBuffer : : Read ( int size , uint8_t * bytes ) {
int RingBuffer : : Read ( int size , uint8_t * bytes ) {
int rd_ix = rd_ix_ ;
int rd_ix = rd_ix_ ;
SynthMemoryBarrier ( ) ; // read barrier, make sure data is committed before ix
SynthMemoryBarrier ( ) ; // read barrier, make sure data is committed before ix
int fragment_size = min ( size , kBufSize - rd_ix ) ;
unsigned int fragment_size = min ( ( unsigned int ) size , kBufSize - rd_ix ) ;
memcpy ( bytes , buf_ + rd_ix , fragment_size ) ;
memcpy ( bytes , buf_ + rd_ix , fragment_size ) ;
if ( size > fragment_size ) {
if ( size > fragment_size ) {
memcpy ( bytes + fragment_size , buf_ , size - fragment_size ) ;
memcpy ( bytes + fragment_size , buf_ , size - fragment_size ) ;
@ -46,20 +46,20 @@ int RingBuffer::Read(int size, uint8_t *bytes) {
return size ;
return size ;
}
}
int RingBuffer : : Write ( const uint8_t * bytes , int size ) {
void RingBuffer : : Write ( const uint8_t * bytes , int size ) {
int remaining = size ;
unsigned int remaining = ( unsigned int ) size ;
while ( remaining > 0 ) {
while ( remaining > 0 ) {
int rd_ix = rd_ix_ ;
int rd_ix = rd_ix_ ;
int wr_ix = wr_ix_ ;
int wr_ix = wr_ix_ ;
int space_available = ( rd_ix - wr_ix - 1 ) & ( kBufSize - 1 ) ;
unsigned int space_available = ( rd_ix - wr_ix - 1 ) & ( kBufSize - 1 ) ;
if ( space_available = = 0 ) {
if ( space_available = = 0 ) {
struct timespec sleepTime ;
struct timespec sleepTime ;
sleepTime . tv_sec = 0 ;
sleepTime . tv_sec = 0 ;
sleepTime . tv_nsec = 1000000 ;
sleepTime . tv_nsec = 1000000 ;
nanosleep ( & sleepTime , NULL ) ;
nanosleep ( & sleepTime , NULL ) ;
} else {
} else {
int wr_size = min ( remaining , space_available ) ;
unsigned int wr_size = min ( remaining , space_available ) ;
int fragment_size = min ( wr_size , kBufSize - wr_ix ) ;
unsigned int fragment_size = min ( wr_size , kBufSize - wr_ix ) ;
memcpy ( buf_ + wr_ix , bytes , fragment_size ) ;
memcpy ( buf_ + wr_ix , bytes , fragment_size ) ;
if ( wr_size > fragment_size ) {
if ( wr_size > fragment_size ) {
memcpy ( buf_ , bytes + fragment_size , wr_size - fragment_size ) ;
memcpy ( buf_ , bytes + fragment_size , wr_size - fragment_size ) ;