|
|
1.1 root 1: /* ringbuf.h */
2:
3: /* Synchronet ring buffer routines */
4:
1.1.1.2 ! root 5: /* $Id: ringbuf.h,v 1.8 2003/10/09 17:27:05 deuce Exp $ */
1.1 root 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: * *
1.1.1.2 ! root 11: * Copyright 2003 Rob Swindell - http://www.synchro.net/copyright.html *
1.1 root 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:
1.1.1.2 ! root 39: /* Pre-define RINGBUF_USE_STD_RTL to use standard C runtime library symbols
! 40: for malloc, free, and memcpy
! 41: */
1.1 root 42:
43: #ifndef _RINGBUF_H_
44: #define _RINGBUF_H_
45:
1.1.1.2 ! root 46: #ifdef RINGBUF_SEM
! 47: #include "semwrap.h" /* sem_t */
! 48: #endif
! 49: #ifdef RINGBUF_MUTEX
! 50: #include "threadwrap.h" /* pthread_mutex_t */
! 51: #endif
! 52:
1.1 root 53: #ifndef DWORD
54: #define DWORD unsigned long
55: #endif
56:
57: #ifndef BYTE
58: #define BYTE unsigned char
59: #endif
60:
61: #ifndef NULL
62: #define NULL 0
63: #endif
64:
65: #define RINGBUF_USE_STD_RTL
66:
67: #if defined(_WIN32) && !defined(__GNUC__)
68: #define RINGBUFCALL _cdecl
69: #else
70: #define RINGBUFCALL
71: #endif
72:
73: /************/
74: /* Typedefs */
75: /************/
76:
77: typedef struct {
78:
1.1.1.2 ! root 79: BYTE* pStart;
1.1 root 80: BYTE* pHead; /* next space available for data */
81: BYTE* pTail; /* next byte to be consumed */
82: BYTE* pEnd; /* end of the buffer, used for wrap around */
83: DWORD size;
1.1.1.2 ! root 84: #ifdef RINGBUF_SEM
! 85: sem_t sem; /* semaphore used to signal data waiting */
! 86: sem_t highwater_sem; /* semaphore used to signal highwater mark reached */
! 87: DWORD highwater_mark;
! 88: #endif
! 89: #ifdef RINGBUF_MUTEX
! 90: pthread_mutex_t mutex; /* mutex used to protect ring buffer pointers */
! 91: #endif
1.1 root 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:
1.1.1.2 ! root 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.