HCCU Buffer pool
{
BufPool - static allocated buffers
-----------------------------------------------------
As method for avoiding Copying of the data through
mailboxes, the static buffer concept has these
advantages:
-a minimum of copying is required
-as a resource, access is protected by a semaphore
-the protection is internal to the access
-----------------------------------------------------
concept of use :
a task allocates the buffer, and fills it,
it then passes the index to the next task,
the final task releases the buffer.
note :
the allocating task waits until it gets the buffer,
should there be none available
-----------------------------------------------------
Use:
k:=GetFreeMMUBuffer; / allocate
..
..
MMUBufferPool[k].s:=size; / use
MMUBufferPool[k].v:=data;
..
..
ReleaseMMUBuffer(k); / release
-----------------------------------------------------
changes
24.6.94 :add MMUBufFree,NetBufFree
4.8.94 :remove net part
19.feb97:increse BufSize from $80 to 140
9.okt97:increse BufSize from 140 to 160
-----------------------------------------------------
Created :15/apr/94
Last Update :24.6.94,4.8.94,9.10.97
-----------------------------------------------------
Is updated version of :
}
{$D-,L-}
UNIT BufPool;
INTERFACE
CONST
{$IFDEF EV}
BufSize=160; { see also Globdef.bufsize for network buffer size }
{$ELSE}
BufSize=160; { $80; }
{$ENDIF}
MMUBufCount=20;
TYPE
BufType=RECORD
InUse:BOOLEAN;
s:BYTE;
V:ARRAY[0..BufSize-1]OF BYTE;
END;
FUNCTION GetFreeMMUBuffer:BYTE;
PROCEDURE ReleaseMMUBuffer(z:BYTE);
VAR
MMUBufferPool:ARRAY[1..MMUBufCount]OF BufType;
MMUBufFree:BYTE;
IMPLEMENTATION
{-----------------------------------------------------}
USES RTKernel;
VAR MMUBufSema:RTKERNEL.Semaphore;
{-----------------------------------------------------}
FUNCTION GetFreeMMUBuffer:BYTE;
VAR i:BYTE;
f:BOOLEAN;
BEGIN
f:=FALSE;
REPEAT
Wait(MMUBufSema);
IF (MMUBufFree<>0) THEN BEGIN
i:=0;
REPEAT
inc(i);
IF (Not MMUBufferPool[i].InUse) THEN BEGIN
f:=TRUE;
Dec(MMUBufFree);
MMUBufferPool[i].InUse:=TRUE;
END;
UNTIL (f)OR(i>=MMUBufCount);
END;
Signal(MMUBufSema);
IF (Not f) THEN RTKERNEL.Delay(1);
UNTIL f;
GetFreeMMUBuffer:=i;
END;
{-----------------------------------------------------}
PROCEDURE ReleaseMMUBuffer(z:BYTE);
BEGIN
Wait(MMUBufSema);
MMUBufferPool[z].InUse:=FALSE;
Inc(MMUBufFree);
Signal(MMUBufSema);
END;
{-----------------------------------------------------}
VAR i:BYTE;
BEGIN { autoinit of this unit}
FOR i:=1 TO MMUBufCount DO MMUBufferPool[i].Inuse:=FALSE;
MMUBufFree:=MMUBufCount;
InitSemaphore(MMUBufSema,resource,1,'MMUBuf');
END. { unit }
home
last updated 4.dec.99
Copyright (99,2000) Ing.Büro R.Tschaggelar