spring cleaning

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4795 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale committed 2007-03-29 22:31:56 +00:00
1 parent a021945cef
commit 3a54126261
143 files changed
+22413 -31567

No files matched your search

+102 -111
View File
@@ -81,17 +81,17 @@
# define PaUtil_WriteMemoryBarrier()
#else
#if defined(__APPLE__) //|| defined(__FreeBSD__)
#if defined(__APPLE__) //|| defined(__FreeBSD__)
# include <libkern/OSAtomic.h>
/* Here are the memory barrier functions. Mac OS X and FreeBSD only provide
full memory barriers, so the three types of barriers are the same. */
/* Here are the memory barrier functions. Mac OS X and FreeBSD only provide
full memory barriers, so the three types of barriers are the same. */
# define PaUtil_FullMemoryBarrier() OSMemoryBarrier()
# define PaUtil_ReadMemoryBarrier() OSMemoryBarrier()
# define PaUtil_WriteMemoryBarrier() OSMemoryBarrier()
#elif defined(__GNUC__)
/* GCC understands volatile asm and "memory" to mean it
* should not reorder memory read/writes */
/* GCC understands volatile asm and "memory" to mean it
* should not reorder memory read/writes */
# if defined( __PPC__ )
# define PaUtil_FullMemoryBarrier() __asm__ volatile("sync":::"memory")
# define PaUtil_ReadMemoryBarrier() __asm__ volatile("sync":::"memory")
@@ -123,37 +123,39 @@
* Initialize FIFO.
* numBytes must be power of 2, returns -1 if not.
*/
long PaUtil_InitializeRingBuffer( PaUtilRingBuffer *rbuf, long numBytes, void *dataPtr )
long PaUtil_InitializeRingBuffer(PaUtilRingBuffer * rbuf, long numBytes, void *dataPtr)
{
if( ((numBytes-1) & numBytes) != 0) return -1; /* Not Power of two. */
rbuf->bufferSize = numBytes;
rbuf->buffer = (char *)dataPtr;
PaUtil_FlushRingBuffer( rbuf );
rbuf->bigMask = (numBytes*2)-1;
rbuf->smallMask = (numBytes)-1;
return 0;
if (((numBytes - 1) & numBytes) != 0)
return -1; /* Not Power of two. */
rbuf->bufferSize = numBytes;
rbuf->buffer = (char *) dataPtr;
PaUtil_FlushRingBuffer(rbuf);
rbuf->bigMask = (numBytes * 2) - 1;
rbuf->smallMask = (numBytes) - 1;
return 0;
}
/***************************************************************************
** Return number of bytes available for reading. */
long PaUtil_GetRingBufferReadAvailable( PaUtilRingBuffer *rbuf )
long PaUtil_GetRingBufferReadAvailable(PaUtilRingBuffer * rbuf)
{
PaUtil_ReadMemoryBarrier();
return ( (rbuf->writeIndex - rbuf->readIndex) & rbuf->bigMask );
PaUtil_ReadMemoryBarrier();
return ((rbuf->writeIndex - rbuf->readIndex) & rbuf->bigMask);
}
/***************************************************************************
** Return number of bytes available for writing. */
long PaUtil_GetRingBufferWriteAvailable( PaUtilRingBuffer *rbuf )
long PaUtil_GetRingBufferWriteAvailable(PaUtilRingBuffer * rbuf)
{
/* Since we are calling PaUtil_GetRingBufferReadAvailable, we don't need an aditional MB */
return ( rbuf->bufferSize - PaUtil_GetRingBufferReadAvailable(rbuf));
/* Since we are calling PaUtil_GetRingBufferReadAvailable, we don't need an aditional MB */
return (rbuf->bufferSize - PaUtil_GetRingBufferReadAvailable(rbuf));
}
/***************************************************************************
** Clear buffer. Should only be called when buffer is NOT being read. */
void PaUtil_FlushRingBuffer( PaUtilRingBuffer *rbuf )
void PaUtil_FlushRingBuffer(PaUtilRingBuffer * rbuf)
{
rbuf->writeIndex = rbuf->readIndex = 0;
rbuf->writeIndex = rbuf->readIndex = 0;
}
/***************************************************************************
@@ -162,42 +164,39 @@ void PaUtil_FlushRingBuffer( PaUtilRingBuffer *rbuf )
** If non-contiguous, size2 will be the size of second region.
** Returns room available to be written or numBytes, whichever is smaller.
*/
long PaUtil_GetRingBufferWriteRegions( PaUtilRingBuffer *rbuf, long numBytes,
void **dataPtr1, long *sizePtr1,
void **dataPtr2, long *sizePtr2 )
long PaUtil_GetRingBufferWriteRegions(PaUtilRingBuffer * rbuf, long numBytes,
void **dataPtr1, long *sizePtr1, void **dataPtr2, long *sizePtr2)
{
long index;
long available = PaUtil_GetRingBufferWriteAvailable( rbuf );
if( numBytes > available ) numBytes = available;
/* Check to see if write is not contiguous. */
index = rbuf->writeIndex & rbuf->smallMask;
if( (index + numBytes) > rbuf->bufferSize )
{
/* Write data in two blocks that wrap the buffer. */
long firstHalf = rbuf->bufferSize - index;
*dataPtr1 = &rbuf->buffer[index];
*sizePtr1 = firstHalf;
*dataPtr2 = &rbuf->buffer[0];
*sizePtr2 = numBytes - firstHalf;
}
else
{
*dataPtr1 = &rbuf->buffer[index];
*sizePtr1 = numBytes;
*dataPtr2 = NULL;
*sizePtr2 = 0;
}
return numBytes;
long index;
long available = PaUtil_GetRingBufferWriteAvailable(rbuf);
if (numBytes > available)
numBytes = available;
/* Check to see if write is not contiguous. */
index = rbuf->writeIndex & rbuf->smallMask;
if ((index + numBytes) > rbuf->bufferSize) {
/* Write data in two blocks that wrap the buffer. */
long firstHalf = rbuf->bufferSize - index;
*dataPtr1 = &rbuf->buffer[index];
*sizePtr1 = firstHalf;
*dataPtr2 = &rbuf->buffer[0];
*sizePtr2 = numBytes - firstHalf;
} else {
*dataPtr1 = &rbuf->buffer[index];
*sizePtr1 = numBytes;
*dataPtr2 = NULL;
*sizePtr2 = 0;
}
return numBytes;
}
/***************************************************************************
*/
long PaUtil_AdvanceRingBufferWriteIndex( PaUtilRingBuffer *rbuf, long numBytes )
long PaUtil_AdvanceRingBufferWriteIndex(PaUtilRingBuffer * rbuf, long numBytes)
{
/* we need to ensure that previous writes are seen before we update the write index */
PaUtil_WriteMemoryBarrier();
return rbuf->writeIndex = (rbuf->writeIndex + numBytes) & rbuf->bigMask;
/* we need to ensure that previous writes are seen before we update the write index */
PaUtil_WriteMemoryBarrier();
return rbuf->writeIndex = (rbuf->writeIndex + numBytes) & rbuf->bigMask;
}
/***************************************************************************
@@ -206,81 +205,73 @@ long PaUtil_AdvanceRingBufferWriteIndex( PaUtilRingBuffer *rbuf, long numBytes )
** If non-contiguous, size2 will be the size of second region.
** Returns room available to be written or numBytes, whichever is smaller.
*/
long PaUtil_GetRingBufferReadRegions( PaUtilRingBuffer *rbuf, long numBytes,
void **dataPtr1, long *sizePtr1,
void **dataPtr2, long *sizePtr2 )
long PaUtil_GetRingBufferReadRegions(PaUtilRingBuffer * rbuf, long numBytes,
void **dataPtr1, long *sizePtr1, void **dataPtr2, long *sizePtr2)
{
long index;
long available = PaUtil_GetRingBufferReadAvailable( rbuf );
if( numBytes > available ) numBytes = available;
/* Check to see if read is not contiguous. */
index = rbuf->readIndex & rbuf->smallMask;
if( (index + numBytes) > rbuf->bufferSize )
{
/* Write data in two blocks that wrap the buffer. */
long firstHalf = rbuf->bufferSize - index;
*dataPtr1 = &rbuf->buffer[index];
*sizePtr1 = firstHalf;
*dataPtr2 = &rbuf->buffer[0];
*sizePtr2 = numBytes - firstHalf;
}
else
{
*dataPtr1 = &rbuf->buffer[index];
*sizePtr1 = numBytes;
*dataPtr2 = NULL;
*sizePtr2 = 0;
}
return numBytes;
long index;
long available = PaUtil_GetRingBufferReadAvailable(rbuf);
if (numBytes > available)
numBytes = available;
/* Check to see if read is not contiguous. */
index = rbuf->readIndex & rbuf->smallMask;
if ((index + numBytes) > rbuf->bufferSize) {
/* Write data in two blocks that wrap the buffer. */
long firstHalf = rbuf->bufferSize - index;
*dataPtr1 = &rbuf->buffer[index];
*sizePtr1 = firstHalf;
*dataPtr2 = &rbuf->buffer[0];
*sizePtr2 = numBytes - firstHalf;
} else {
*dataPtr1 = &rbuf->buffer[index];
*sizePtr1 = numBytes;
*dataPtr2 = NULL;
*sizePtr2 = 0;
}
return numBytes;
}
/***************************************************************************
*/
long PaUtil_AdvanceRingBufferReadIndex( PaUtilRingBuffer *rbuf, long numBytes )
long PaUtil_AdvanceRingBufferReadIndex(PaUtilRingBuffer * rbuf, long numBytes)
{
/* we need to ensure that previous writes are always seen before updating the index. */
PaUtil_WriteMemoryBarrier();
return rbuf->readIndex = (rbuf->readIndex + numBytes) & rbuf->bigMask;
/* we need to ensure that previous writes are always seen before updating the index. */
PaUtil_WriteMemoryBarrier();
return rbuf->readIndex = (rbuf->readIndex + numBytes) & rbuf->bigMask;
}
/***************************************************************************
** Return bytes written. */
long PaUtil_WriteRingBuffer( PaUtilRingBuffer *rbuf, const void *data, long numBytes )
long PaUtil_WriteRingBuffer(PaUtilRingBuffer * rbuf, const void *data, long numBytes)
{
long size1, size2, numWritten;
void *data1, *data2;
numWritten = PaUtil_GetRingBufferWriteRegions( rbuf, numBytes, &data1, &size1, &data2, &size2 );
if( size2 > 0 )
{
long size1, size2, numWritten;
void *data1, *data2;
numWritten = PaUtil_GetRingBufferWriteRegions(rbuf, numBytes, &data1, &size1, &data2, &size2);
if (size2 > 0) {
memcpy( data1, data, size1 );
data = ((char *)data) + size1;
memcpy( data2, data, size2 );
}
else
{
memcpy( data1, data, size1 );
}
PaUtil_AdvanceRingBufferWriteIndex( rbuf, numWritten );
return numWritten;
memcpy(data1, data, size1);
data = ((char *) data) + size1;
memcpy(data2, data, size2);
} else {
memcpy(data1, data, size1);
}
PaUtil_AdvanceRingBufferWriteIndex(rbuf, numWritten);
return numWritten;
}
/***************************************************************************
** Return bytes read. */
long PaUtil_ReadRingBuffer( PaUtilRingBuffer *rbuf, void *data, long numBytes )
long PaUtil_ReadRingBuffer(PaUtilRingBuffer * rbuf, void *data, long numBytes)
{
long size1, size2, numRead;
void *data1, *data2;
numRead = PaUtil_GetRingBufferReadRegions( rbuf, numBytes, &data1, &size1, &data2, &size2 );
if( size2 > 0 )
{
memcpy( data, data1, size1 );
data = ((char *)data) + size1;
memcpy( data, data2, size2 );
}
else
{
memcpy( data, data1, size1 );
}
PaUtil_AdvanceRingBufferReadIndex( rbuf, numRead );
return numRead;
long size1, size2, numRead;
void *data1, *data2;
numRead = PaUtil_GetRingBufferReadRegions(rbuf, numBytes, &data1, &size1, &data2, &size2);
if (size2 > 0) {
memcpy(data, data1, size1);
data = ((char *) data) + size1;
memcpy(data, data2, size2);
} else {
memcpy(data, data1, size1);
}
PaUtil_AdvanceRingBufferReadIndex(rbuf, numRead);
return numRead;
}