Main Page   Modules   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

/projects/cubeos/src_current/kernel/iobuf.h

Go to the documentation of this file.
00001 /*  src_experimental/kernel/iobuf.h
00002     CubeOS Version 0.4.90 experimental
00003     Copyright (C) 1999,2000 Holger Kenn
00004 
00005     CubeOS is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or any later version.
00009 
00010     CubeOS is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015 */  
00016 #ifndef _IOBUF_H
00017 #define _IOBUF_H
00018 
00023 #define BUFLEN 1024 
00024 
00025 
00029 struct iobuf {
00030   unsigned short head; 
00031   unsigned short tail; 
00032   unsigned short cnt;  
00033   unsigned short buflen; 
00034   char data[BUFLEN];    
00035 };
00036 
00043 static inline void iobuf_init(struct iobuf *x,short bl)
00044 {
00045 
00046 if ((bl<=0)||(bl>BUFLEN)) 
00047         {
00048                 x->buflen=BUFLEN;
00049         }
00050 else {
00051         x->buflen=bl;
00052 }
00053 
00054 x->head=0;
00055 x->tail=0;
00056 x->cnt=0;
00057 
00058 }
00059 
00068 static inline int put(struct iobuf *x,char c) 
00069 {
00070 if (x->cnt < x->buflen) {
00071         x->data[x->head]=c;
00072         x->head=(x->head+1) % x->buflen;
00073         x->cnt++;
00074         return(0);
00075 } else {
00076         return(-1);
00077         }
00078 }
00079 
00089 static inline char get(struct iobuf *x)
00090 {
00091 char c;
00092 while (x->cnt<=0); /* Busy waiting... Not nice...*/
00093 c=x->data[x->tail];
00094 x->tail=(x->tail +1) % x->buflen;
00095 x->cnt--;
00096 return (c);
00097 
00098 }
00099 
00100 #endif

Generated on Thu Feb 20 15:38:44 2003 for cubeOS by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002