Merge commit '9276b3991ba20d5a5660887ba81b0bc7bed25a0c'
[unleashed.git] / share / man / man9f / rmvq.9f
blob847f70bb75690ca0f72ec56e41b9c09b9f2fd10e
1 '\" te
2 .\" Copyright (c) 2006, Sun Microsystems, Inc.  All Rights Reserved.
3 .\" Copyright 1989 AT&T
4 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
5 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
6 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
7 .TH RMVQ 9F "Jan 16, 2006"
8 .SH NAME
9 rmvq \- remove a message from a queue
10 .SH SYNOPSIS
11 .LP
12 .nf
13 #include <sys/stream.h>
17 \fBvoid\fR \fBrmvq\fR(\fBqueue_t *\fR\fIq\fR, \fBmblk_t *\fR\fImp\fR);
18 .fi
20 .SH INTERFACE LEVEL
21 .sp
22 .LP
23 Architecture independent level 1 (DDI/DKI).
24 .SH PARAMETERS
25 .sp
26 .ne 2
27 .na
28 \fB\fIq\fR\fR
29 .ad
30 .RS 6n
31 Queue containing the message to be removed.
32 .RE
34 .sp
35 .ne 2
36 .na
37 \fB\fImp\fR\fR
38 .ad
39 .RS 6n
40 Message to remove.
41 .RE
43 .SH DESCRIPTION
44 .sp
45 .LP
46 The \fBrmvq()\fR function removes a message from a queue. A message can be
47 removed from anywhere on a queue. To prevent modules and drivers from having to
48 deal with the internals of message linkage on a queue, either \fBrmvq()\fR or
49 \fBgetq\fR(9F) should be used to remove a message from a queue.
50 .SH CONTEXT
51 .sp
52 .LP
53 The \fBrmvq()\fR function can be called from user, interrupt, or kernel
54 context.
55 .SH EXAMPLES
56 .sp
57 .LP
58 This code fragment illustrates how one may flush one type of message from a
59 queue. In this case, only \fBM_PROTO T_DATA_IND\fR messages are flushed. For
60 each message on the queue, if it is an \fBM_PROTO\fR message (line 8) of type
61 \fBT_DATA_IND\fR (line 10), save a pointer to the next message (line 11),
62 remove the \fBT_DATA_IND\fR message (line 12) and free it (line 13). Continue
63 with the next message in the list (line 19).
64 .sp
65 .in +2
66 .nf
67 1  mblk_t *mp, *nmp;
68 2  queue_t *q;
69 3  union T_primitives *tp;
71 5       /* Insert code here to protect queue and message block */
72 6       mp = q->q_first;
73 7       while (mp) {
74 8               if (mp->b_datap->db_type == M_PROTO) {
75 9                       tp = (union T_primitives *)mp->b_rptr;
76 10                      if (tp->type == T_DATA_IND) {
77 11                              nmp = mp->b_next;
78 12                              rmvq(q, mp);
79 13                              freemsg(mp);
80 14                              mp = nmp;
81 15                      } else {
82 16                              mp = mp->b_next;
83 17                      }
84 18              } else {
85 19                      mp = mp->b_next;
86 20              }
87 21      }
88 22      /* End of region that must be protected */
89 .fi
90 .in -2
92 .sp
93 .LP
94 When using \fBrmvq()\fR, you must ensure that the queue and the message block
95 is not modified by another thread at the same time. You can achieve this either
96 by using STREAMS functions or by implementing your own locking.
97 .SH SEE ALSO
98 .sp
99 .LP
100 \fBfreemsg\fR(9F), \fBgetq\fR(9F), \fBinsq\fR(9F)
103 \fIWriting Device Drivers\fR
106 \fISTREAMS Programming Guide\fR
107 .SH WARNINGS
110 Make sure that the message \fImp\fR is linked onto \fIq\fR to avoid a possible
111 system panic.