1insq(9F) Kernel Functions for Drivers insq(9F)
2
3
4
6 insq - insert a message into a queue
7
9 #include <sys/stream.h>
10
11
12
13 int insq(queue_t *q, mblk_t *emp, mblk_t *nmp);
14
15
17 Architecture independent level 1 (DDI/DKI).
18
20 q Pointer to the queue containing message emp.
21
22
23 emp Enqueued message before which the new message is to be inserted.
24 mblk_t is an instance of the msgb(9S) structure.
25
26
27 nmp Message to be inserted.
28
29
31 The insq() function inserts a message into a queue. The message to be
32 inserted, nmp, is placed in q immediately before the message emp. If
33 emp is NULL, the new message is placed at the end of the queue. The
34 queue class of the new message is ignored. All flow control parameters
35 are updated. The service procedure is enabled unless QNOENB is set.
36
38 The insq() function returns 1 on success, and 0 on failure.
39
41 The insq() function can be called from user, interrupt, or kernel con‐
42 text.
43
45 This routine illustrates the steps a transport provider may take to
46 place expedited data ahead of normal data on a queue (assume all M_DATA
47 messages are converted into M_PROTO T_DATA_REQ messages). Normal
48 T_DATA_REQ messages are just placed on the end of the queue (line 16).
49 However, expedited T_EXDATA_REQ messages are inserted before any normal
50 messages already on the queue (line 25). If there are no normal mes‐
51 sages on the queue, bp will be NULL and we fall out of the for loop
52 (line 21). insq acts like putq(9F) in this case.
53
54 1 #include <sys/stream.h>
55 2 #include <sys/tihdr.h>
56 3
57 4 static int
58 5 xxxwput(queue_t *q, mblk_t *mp)
59 6 {
60 7 union T_primitives *tp;
61 8 mblk_t *bp;
62 9 union T_primitives *ntp;
63 10
64 11 switch (mp->b_datap->db_type) {
65 12 case M_PROTO:
66 13 tp = (union T_primitives *)mp->b_rptr;
67 14 switch (tp->type) {
68 15 case T_DATA_REQ:
69 16 putq(q, mp);
70 17 break;
71 18
72 19 case T_EXDATA_REQ:
73 20 /* Insert code here to protect queue and message block */
74 21 for (bp = q->q_first; bp; bp = bp->b_next) {
75 22 if (bp->b_datap->db_type == M_PROTO) {
76 23 ntp = (union T_primitives *)bp->b_rptr;
77 24 if (ntp->type != T_EXDATA_REQ)
78 25 break;
79 26 }
80 27 }
81 28 (void)insq(q, bp, mp);
82 29 /* End of region that must be protected */
83 30 break;
84 . . .
85 31 }
86 32 }
87 33 }
88
89
90
91 When using insq(), you must ensure that the queue and the message block
92 is not modified by another thread at the same time. You can achieve
93 this either by using STREAMS functions or by implementing your own
94 locking.
95
97 putq(9F), rmvq(9F), msgb(9S)
98
99
100 Writing Device Drivers
101
102
103 STREAMS Programming Guide
104
106 If emp is non-NULL, it must point to a message on q or a system panic
107 could result.
108
109
110
111SunOS 5.11 23 Mar 2009 insq(9F)