home *** CD-ROM | disk | FTP | other *** search
- /* Common ISDN API C-Library Functions: buffer handling
- Author: Dietmar Friede
- Copyright (c) 1992 D.Friede
- #include "copy"
- #include "copying.doc"
- */
- #include "stdio.h"
- #include "types.h"
-
- typedef byte buf[2064];
- static buf sendbuf[4];
- static byte far *freelist[4];
- static int free, head, tail;
-
- void
- init_buf(void)
- {
- int i;
- for(i= 0; i<4; i++) freelist[i]= sendbuf[i];
- free= 4; head= tail= 0;
- }
-
- byte far * getbuf(void)
- {
- byte far * p;
- if( free == 0) return null;
- free --;
- p= freelist[head];
- freelist[head++]= null;
- head&=0x3;
- return(p);
- }
-
- void
- freebuf(byte far *p)
- {
- if(p == null)
- {
- printf("buffer problem\n");
- return;
- }
- free++;
- if(free>4)
- {
- free= 4;
- printf("panic buffer\n");
- return;
- }
- freelist[tail++]= p;
- tail&= 0x3;
- }
-
- typedef byte mbuf[190];
- static mbuf messages[4];
- static char took[4];
- extern byte is_api_int;
-
- byte far * getmsg(void)
- {
- if(is_api_int&0xfc)
- {
- printf("panic msg problem %d ..\n",is_api_int);
- if(is_api_int<0) is_api_int= 0;
- return null;
- }
- if(took[is_api_int]++)
- {
- printf("panic msg took %d\n",is_api_int);
- return null;
- }
-
- return(messages[is_api_int]);
- }
-
- void
- freemsg(byte far *p)
- {
- took[is_api_int]--;
- if(p == null)
- {
- printf("buffer problem\n");
- return;
- }
- }
-