summaryrefslogtreecommitdiff
path: root/src/q_fifo.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/q_fifo.h')
-rw-r--r--src/q_fifo.h57
1 files changed, 33 insertions, 24 deletions
diff --git a/src/q_fifo.h b/src/q_fifo.h
index 3bb5124..fbe0501 100644
--- a/src/q_fifo.h
+++ b/src/q_fifo.h
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -28,16 +28,17 @@ typedef struct {
size_t ax, ay, bs;
} fifo_t;
-static inline void *FIFO_Reserve( fifo_t *fifo, size_t *len ) {
+static inline void *FIFO_Reserve(fifo_t *fifo, size_t *len)
+{
size_t tail;
- if( fifo->bs ) {
+ if (fifo->bs) {
*len = fifo->ax - fifo->bs;
return fifo->data + fifo->bs;
}
tail = fifo->size - fifo->ay;
- if( tail ) {
+ if (tail) {
*len = tail;
return fifo->data + fifo->ay;
}
@@ -46,16 +47,17 @@ static inline void *FIFO_Reserve( fifo_t *fifo, size_t *len ) {
return fifo->data;
}
-static inline void FIFO_Commit( fifo_t *fifo, size_t len ) {
+static inline void FIFO_Commit(fifo_t *fifo, size_t len)
+{
size_t tail;
- if( fifo->bs ) {
+ if (fifo->bs) {
fifo->bs += len;
return;
}
tail = fifo->size - fifo->ay;
- if( tail ) {
+ if (tail) {
fifo->ay += len;
return;
}
@@ -63,13 +65,15 @@ static inline void FIFO_Commit( fifo_t *fifo, size_t len ) {
fifo->bs = len;
}
-static inline void *FIFO_Peek( fifo_t *fifo, size_t *len ) {
+static inline void *FIFO_Peek(fifo_t *fifo, size_t *len)
+{
*len = fifo->ay - fifo->ax;
return fifo->data + fifo->ax;
}
-static inline void FIFO_Decommit( fifo_t *fifo, size_t len ) {
- if( fifo->ax + len < fifo->ay ) {
+static inline void FIFO_Decommit(fifo_t *fifo, size_t len)
+{
+ if (fifo->ax + len < fifo->ay) {
fifo->ax += len;
return;
}
@@ -78,39 +82,44 @@ static inline void FIFO_Decommit( fifo_t *fifo, size_t len ) {
fifo->ax = fifo->bs = 0;
}
-static inline size_t FIFO_Usage( fifo_t *fifo ) {
+static inline size_t FIFO_Usage(fifo_t *fifo)
+{
return fifo->ay - fifo->ax + fifo->bs;
}
-static inline int FIFO_Percent( fifo_t *fifo ) {
- if( !fifo->size ) {
+static inline int FIFO_Percent(fifo_t *fifo)
+{
+ if (!fifo->size) {
return 0;
}
- return ( int )( FIFO_Usage( fifo ) * 100 / fifo->size );
+ return (int)(FIFO_Usage(fifo) * 100 / fifo->size);
}
-static inline void FIFO_Clear( fifo_t *fifo ) {
+static inline void FIFO_Clear(fifo_t *fifo)
+{
fifo->ax = fifo->ay = fifo->bs = 0;
}
-size_t FIFO_Read( fifo_t *fifo, void *buffer, size_t len );
-size_t FIFO_Write( fifo_t *fifo, const void *buffer, size_t len );
+size_t FIFO_Read(fifo_t *fifo, void *buffer, size_t len);
+size_t FIFO_Write(fifo_t *fifo, const void *buffer, size_t len);
-static inline qboolean FIFO_TryRead( fifo_t *fifo, void *buffer, size_t len ) {
- if( FIFO_Read( fifo, NULL, len ) < len ) {
+static inline qboolean FIFO_TryRead(fifo_t *fifo, void *buffer, size_t len)
+{
+ if (FIFO_Read(fifo, NULL, len) < len) {
return qfalse;
}
- FIFO_Read( fifo, buffer, len );
+ FIFO_Read(fifo, buffer, len);
return qtrue;
}
-static inline qboolean FIFO_TryWrite( fifo_t *fifo, void *buffer, size_t len ) {
- if( FIFO_Write( fifo, NULL, len ) < len ) {
+static inline qboolean FIFO_TryWrite(fifo_t *fifo, void *buffer, size_t len)
+{
+ if (FIFO_Write(fifo, NULL, len) < len) {
return qfalse;
}
- FIFO_Write( fifo, buffer, len );
+ FIFO_Write(fifo, buffer, len);
return qtrue;
}
-qboolean FIFO_ReadMessage( fifo_t *fifo, size_t msglen );
+qboolean FIFO_ReadMessage(fifo_t *fifo, size_t msglen);