|
|
1.1 ! root 1: /* ringbuf.h */ ! 2: ! 3: /* Synchronet ring buffer routines */ ! 4: ! 5: /* $Id: ringbuf.h,v 1.12 2006/05/09 02:55:38 rswindell Exp $ */ ! 6: ! 7: /**************************************************************************** ! 8: * @format.tab-size 4 (Plain Text/Source Code File Header) * ! 9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * ! 10: * * ! 11: * Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html * ! 12: * * ! 13: * This program is free software; you can redistribute it and/or * ! 14: * modify it under the terms of the GNU General Public License * ! 15: * as published by the Free Software Foundation; either version 2 * ! 16: * of the License, or (at your option) any later version. * ! 17: * See the GNU General Public License for more details: gpl.txt or * ! 18: * http://www.fsf.org/copyleft/gpl.html * ! 19: * * ! 20: * Anonymous FTP access to the most recent released source is available at * ! 21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net * ! 22: * * ! 23: * Anonymous CVS access to the development source and modification history * ! 24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: * ! 25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login * ! 26: * (just hit return, no password is necessary) * ! 27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src * ! 28: * * ! 29: * For Synchronet coding style and modification guidelines, see * ! 30: * http://www.synchro.net/source.html * ! 31: * * ! 32: * You are encouraged to submit any modifications (preferably in Unix diff * ! 33: * format) via e-mail to [email protected] * ! 34: * * ! 35: * Note: If this box doesn't appear square, then you need to fix your tabs. * ! 36: ****************************************************************************/ ! 37: ! 38: ! 39: /* Pre-define RINGBUF_USE_STD_RTL to use standard C runtime library symbols ! 40: for malloc, free, and memcpy ! 41: */ ! 42: ! 43: #ifndef _RINGBUF_H_ ! 44: #define _RINGBUF_H_ ! 45: ! 46: #include "gen_defs.h" ! 47: ! 48: #ifdef RINGBUF_SEM ! 49: #include "semwrap.h" /* sem_t */ ! 50: #endif ! 51: #ifdef RINGBUF_EVENT ! 52: #include "eventwrap.h" /* xpevent_t */ ! 53: #endif ! 54: #ifdef RINGBUF_MUTEX ! 55: #include "threadwrap.h" /* pthread_mutex_t */ ! 56: #endif ! 57: ! 58: #ifndef NULL ! 59: #define NULL 0 ! 60: #endif ! 61: ! 62: #define RINGBUF_USE_STD_RTL ! 63: ! 64: #if defined(_WIN32) && !defined(__GNUC__) ! 65: #define RINGBUFCALL _cdecl ! 66: #else ! 67: #define RINGBUFCALL ! 68: #endif ! 69: ! 70: /************/ ! 71: /* Typedefs */ ! 72: /************/ ! 73: ! 74: typedef struct { ! 75: ! 76: BYTE* pStart; ! 77: BYTE* pHead; /* next space available for data */ ! 78: BYTE* pTail; /* next byte to be consumed */ ! 79: BYTE* pEnd; /* end of the buffer, used for wrap around */ ! 80: DWORD size; ! 81: #ifdef RINGBUF_SEM ! 82: sem_t sem; /* semaphore used to signal data waiting */ ! 83: sem_t highwater_sem; /* semaphore used to signal highwater mark reached */ ! 84: DWORD highwater_mark; ! 85: #endif ! 86: #ifdef RINGBUF_EVENT ! 87: xpevent_t empty_event; ! 88: #endif ! 89: #ifdef RINGBUF_MUTEX ! 90: pthread_mutex_t mutex; /* mutex used to protect ring buffer pointers */ ! 91: #endif ! 92: ! 93: } RingBuf; ! 94: ! 95: #ifdef __cplusplus ! 96: extern "C" { ! 97: #endif ! 98: ! 99: /***********************/ ! 100: /* Function Prototypes */ ! 101: /***********************/ ! 102: ! 103: int RINGBUFCALL RingBufInit( RingBuf* rb, DWORD size ! 104: #ifndef RINGBUF_USE_STD_RTL ! 105: ,void *(os_malloc)(size_t) ! 106: ,void (os_free)(void *) ! 107: ,void *(os_memcpy)(void *, const void *, size_t) ! 108: #endif ! 109: ); ! 110: void RINGBUFCALL RingBufDispose( RingBuf* rb ); ! 111: DWORD RINGBUFCALL RingBufFull( RingBuf* rb ); ! 112: DWORD RINGBUFCALL RingBufFree( RingBuf* rb ); ! 113: DWORD RINGBUFCALL RingBufWrite( RingBuf* rb, BYTE *src, DWORD cnt ); ! 114: DWORD RINGBUFCALL RingBufRead( RingBuf* rb, BYTE *dst, DWORD cnt ); ! 115: DWORD RINGBUFCALL RingBufPeek( RingBuf* rb, BYTE *dst, DWORD cnt ); ! 116: void RINGBUFCALL RingBufReInit( RingBuf* rb ); ! 117: ! 118: #ifdef __cplusplus ! 119: } ! 120: #endif ! 121: ! 122: #endif /* Don't add anything afterthis endif */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.