Kernel Functions for Drivers insq(9F)
NAME
insq - insert a message into a queue
SYNOPSIS
#include
int insq(queuet *q, mblkt *emp, mblkt *nmp);
INTERFACE LEVEL
Architecture independent level 1 (DI/DKI).
PARAMETERS
q Pointer to the queue containing message emp.
emp Enqueued message before which the new message is to
be inserted. mblkt is an instance of the msgb(9S)
structure.
nmp Message to be inserted.
DESCRIPTION
The insq() function inserts a message into a queue. The mes-
sage to be inserted, nmp, is placed in q immediately before
the message emp. If emp is NUL, the new message is placed
at the end of the queue. The queue class of the new message
is ignored. All flow control parameters are updated. The
service procedure is enabled unless QNOENB is set.
RETURN VALUES
The insq() function returns 1 on success, and 0 on failure.
CONTEXT
The insq() function can be called from user, interrupt, or
kernel context.
EXAMPLES
This routine illustrates the steps a transport provider may
take to place expedited data ahead of normal data on a queue
(assume all MDATA messages are converted into MPROTO
TDATAREQ messages). Normal TDATAREQ messages are just
placed on the end of the queue (line 16). However, expedited
TEXDATAREQ messages are inserted before any normal mes-
sages already on the queue (line 25). If there are no normal
messages on the queue, bp will be NUL and we fall out of
the for loop (line 21). insq acts like putq(9F) in this
case.
SunOS 5.11 Last change: 16 Jan 2006 1
Kernel Functions for Drivers insq(9F)
1 #include
2 #include
3
4 static int
5 xxxwput(queuet *q, mblkt *mp)
6 {
7 union Tprimitives *tp;
8 mblkt *bp;
9 union Tprimitives *ntp;
10
11 switch (mp->bdatap->dbtype) {
12 case MPROTO:
13 tp = (union Tprimitives *)mp->brptr;
14 switch (tp->type) {
15 case TDATAREQ:
16 putq(q, mp);
17 break;
18
19 case TEXDATAREQ:
20 /* Insert code here to protect queue and message block */
21 for (bp = q->qfirst; bp; bp = bp->bnext) {
22 if (bp->bdatap->dbtype == MPROTO) {
23 ntp = (union Tprimitives *)bp->brptr;
24 if (ntp->type != TEXDATAREQ)
25 break;
26 }
27 }
28 (void)insq(q, bp, mp);
29 /* End of region that must be protected */
30 break;
. . .
31 }
32 }
33 }
When using insq(), you must ensure that the queue and the
message block is not modified by another thread at the same
time. You can achieve this either by using STREAMS functions
or by implementing your own locking.
SEE ALSO
putq(9F), rmvq(9F), msgb(9S)
Writing Device Drivers
STREAMS Programming Guide
SunOS 5.11 Last change: 16 Jan 2006 2
Kernel Functions for Drivers insq(9F)
WARNINGS
If emp is non-NUL, it must point to a message on q or a
system panic could result.
SunOS 5.11 Last change: 16 Jan 2006 3
|