Print this page
5083 avoid undefined order of operations in assignments
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/scadm/sparc/mpxu/common/smq.c
+++ new/usr/src/cmd/scadm/sparc/mpxu/common/smq.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22 /*
23 23 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 -#pragma ident "%Z%%M% %I% %E% SMI"
28 -
29 27 /*
30 28 * smq.c: to provide a message queue system for scadm functions (used in the
31 29 * firmware download context where BP messages, received from the service
32 30 * processor, are stored in the message queue)
33 31 *
34 32 * these routines come from the libxposix library
35 33 */
36 34
37 35 #include <sys/types.h>
38 36 #include <time.h>
39 37
40 38 #include "xsem.h"
41 39 #include "smq.h"
42 40
43 41
44 42 #define SMQ_VALID_SMQ 0x0000003b
45 43 #define SMQ_VALID_SMQ_MASK 0x000000FF
46 44
47 45
48 46 int
49 47 smq_init(smq_t *smq, smq_msg_t *msgbuffer, int depth)
50 48 {
51 49 /* allocate local semaphore initialized to 0 */
52 50 if (xsem_init(&smq->smq_msgAvail, 0, 0) != 0)
53 51 return (SMQ_ERROR);
54 52
55 53 smq->smq_control = SMQ_VALID_SMQ;
56 54 smq->smq_msgBuffer = msgbuffer;
57 55 smq->smq_head = msgbuffer;
58 56 smq->smq_tail = msgbuffer;
59 57 smq->smq_count = 0;
60 58 smq->smq_depth = depth;
61 59
62 60 return (0);
63 61 }
64 62
65 63
66 64 int
67 65 smq_destroy(smq_t *smq)
68 66 {
69 67 if ((smq->smq_control & SMQ_VALID_SMQ_MASK) != SMQ_VALID_SMQ)
70 68 return (SMQ_INVALID);
71 69
72 70 smq->smq_control = 0;
73 71 (void) xsem_destroy(&smq->smq_msgAvail);
74 72
75 73 return (0);
76 74 }
77 75
78 76
79 77 int
80 78 smq_receive(smq_t *smq, smq_msg_t *msg)
81 79 {
82 80 if ((smq->smq_control & SMQ_VALID_SMQ_MASK) != SMQ_VALID_SMQ)
83 81 return (SMQ_INVALID);
↓ open down ↓ |
45 lines elided |
↑ open up ↑ |
84 82
85 83 /* Wait for message */
86 84 (void) xsem_wait(&smq->smq_msgAvail);
87 85
88 86 if (smq->smq_count == 0)
89 87 return (SMQ_ERROR);
90 88
91 89 /* Copy messaged into queue */
92 90 *msg = *smq->smq_head;
93 91
94 - /* Increment Head */
95 - smq->smq_head = smq->smq_head++;
92 + smq->smq_head++;
96 93 if ((unsigned long)smq->smq_head > ((unsigned long)smq->smq_msgBuffer +
97 94 (unsigned long)(smq->smq_depth * sizeof (smq_msg_t)))) {
98 95 smq->smq_head = smq->smq_msgBuffer;
99 96 }
100 97 smq->smq_count--;
101 98
102 99 return (0);
103 100 }
104 101
105 102
106 103 int
107 104 smq_send(smq_t *smq, smq_msg_t *msg)
↓ open down ↓ |
2 lines elided |
↑ open up ↑ |
108 105 {
109 106 if ((smq->smq_control & SMQ_VALID_SMQ_MASK) != SMQ_VALID_SMQ)
110 107 return (SMQ_INVALID);
111 108
112 109 if (smq->smq_count == smq->smq_depth)
113 110 return (SMQ_FULL);
114 111
115 112 /* Copy messaged into queue */
116 113 *smq->smq_tail = *msg;
117 114
118 - /* Increment Tail */
119 - smq->smq_tail = smq->smq_tail++;
115 + smq->smq_tail++;
120 116 if ((unsigned long)smq->smq_tail > ((unsigned long)smq->smq_msgBuffer +
121 117 (unsigned long)(smq->smq_depth * sizeof (smq_msg_t)))) {
122 118 smq->smq_tail = smq->smq_msgBuffer;
123 119 }
124 120
125 121 smq->smq_count++;
126 122 (void) xsem_post(&smq->smq_msgAvail);
127 123
128 124 return (0);
129 125 }
130 126
131 127
132 128 int
133 129 smq_pendingmsgs(smq_t *smq, int *num)
134 130 {
135 131 if ((smq->smq_control & SMQ_VALID_SMQ_MASK) != SMQ_VALID_SMQ)
136 132 return (SMQ_INVALID);
137 133
138 134 *num = smq->smq_count;
139 135
140 136 return (0);
141 137 }
142 138
143 139
144 140 int
145 141 smq_depth(smq_t *smq, int *depth)
146 142 {
147 143 if ((smq->smq_control & SMQ_VALID_SMQ_MASK) != SMQ_VALID_SMQ)
148 144 return (SMQ_INVALID);
149 145
150 146 *depth = smq->smq_depth;
151 147
152 148 return (0);
153 149 }
154 150
155 151
156 152 int
157 153 smq_xreceive(smq_t *smq, timestruc_t *timeout, smq_msg_t *msg)
158 154 {
159 155 int Status;
160 156
161 157
162 158 if ((smq->smq_control & SMQ_VALID_SMQ_MASK) != SMQ_VALID_SMQ)
163 159 return (SMQ_INVALID);
164 160
165 161 /* Wait for message */
166 162 if ((Status = xsem_xwait(&smq->smq_msgAvail, 1, timeout)) == XSEM_ETIME)
167 163 return (SMQ_ETIME);
↓ open down ↓ |
38 lines elided |
↑ open up ↑ |
168 164
169 165 if (Status != 0)
170 166 return (SMQ_ERROR);
171 167
172 168 if (smq->smq_count == 0)
173 169 return (SMQ_ERROR);
174 170
175 171 /* Copy messaged into queue */
176 172 *msg = *smq->smq_head;
177 173
178 - /* Increment Head */
179 - smq->smq_head = smq->smq_head++;
174 + smq->smq_head++;
180 175 if ((unsigned long)smq->smq_head > ((unsigned long)smq->smq_msgBuffer +
181 176 (unsigned long)(smq->smq_depth * sizeof (smq_msg_t)))) {
182 177 smq->smq_head = smq->smq_msgBuffer;
183 178 }
184 179 smq->smq_count--;
185 180
186 181
187 182 return (0);
188 183 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX