Kernel Functions for Drivers testb(9F)
NAME
testb - check for an available buffer
SYNOPSIS
#include
int testb(sizet size, uintt pri);
INTERFACE LEVEL
Architecture independent level 1 (DI/DKI).
PARAMETERS
size Size of the requested buffer.
pri Priority of the allocb request.
DESCRIPTION
The testb() function checks to see if an allocb(9F) call is
likely to succeed if a buffer of size bytes at priority pri
is requested. Even if testb() returns successfully, the call
to allocb(9F) can fail. The pri argument is no longer used,
but is retained for compatibility.
RETURN VALUES
Returns 1 if a buffer of the requested size is available,
and 0 if one is not.
CONTEXT
The testb() function can be called user, interrupt, or ker-
nel context.
EXAMPLES
Example 1 testb() example
In a service routine, if copymsg(9F) fails (line 6), the
message is put back on the queue (line 7) and a routine,
tryagain, is scheduled to be run in one tenth of a second.
Then the service routine returns.
When the timeout(9F) function runs, if there is no message
on the front of the queue, it just returns. Otherwise, for
each message block in the first message, check to see if an
allocation would succeed. If the number of message blocks
equals the number we can allocate, then enable the service
SunOS 5.11 Last change: 16 Jan 2006 1
Kernel Functions for Drivers testb(9F)
procedure. Otherwise, reschedule tryagain to run again in
another tenth of a second. Note that tryagain is merely an
approximation. Its accounting may be faulty. Consider the
case of a message comprised of two 1024-byte message blocks.
If there is only one free 1024-byte message block and no
free 2048-byte message blocks, then testb() will still
succeed twice. If no message blocks are freed of these sizes
before the service procedure runs again, then the
copymsg(9F) will still fail. The reason testb() is used here
is because it is significantly faster than calling copymsg.
We must minimize the amount of time spent in a timeout()
routine.
1 xxxsrv(q)
2 queuet *q;
3 {
4 mblkt *mp;
5 mblkt *nmp;
. . .
6 if ((nmp = copymsg(mp)) == NUL) {
7 putbq(q, mp);
8 timeout(tryagain, (intptrt)q, drvusectohz(100000));
9 return;
10 }
. . .
11 }
12
13 tryagain(q)
14 queuet *q;
15 {
16 register int canalloc = 0;
17 register int numblks = 0;
18 register mblkt *mp;
19
20 if (!q->qfirst)
21 return;
22 for (mp = q->qfirst; mp; mp = mp->bcont) {
23 numblks];
24 canalloc ]= testb((mp->bdatap->dblim -
25 mp->bdatap->dbbase), BPRIMED);
26 }
27 if (numblks == canalloc)
28 qenable(q);
29 else
30 timeout(tryagain, (intptrt)q, drvusectohz(100000));
31 }
SEE ALSO
allocb(9F), bufcall(9F), copymsg(9F), timeout(9F)
SunOS 5.11 Last change: 16 Jan 2006 2
Kernel Functions for Drivers testb(9F)
Writing Device Drivers
STREAMS Programming Guide
NOTES
The pri argument is provided for compatibility only. Its
value is ignored.
SunOS 5.11 Last change: 16 Jan 2006 3
|