Lines Matching refs:smq
28 * smq.c: to provide a message queue system for scadm functions (used in the
39 #include "smq.h"
47 smq_init(smq_t *smq, smq_msg_t *msgbuffer, int depth)
50 if (xsem_init(&smq->smq_msgAvail, 0, 0) != 0)
53 smq->smq_control = SMQ_VALID_SMQ;
54 smq->smq_msgBuffer = msgbuffer;
55 smq->smq_head = msgbuffer;
56 smq->smq_tail = msgbuffer;
57 smq->smq_count = 0;
58 smq->smq_depth = depth;
65 smq_destroy(smq_t *smq)
67 if ((smq->smq_control & SMQ_VALID_SMQ_MASK) != SMQ_VALID_SMQ)
70 smq->smq_control = 0;
71 (void) xsem_destroy(&smq->smq_msgAvail);
78 smq_receive(smq_t *smq, smq_msg_t *msg)
80 if ((smq->smq_control & SMQ_VALID_SMQ_MASK) != SMQ_VALID_SMQ)
84 (void) xsem_wait(&smq->smq_msgAvail);
86 if (smq->smq_count == 0)
90 *msg = *smq->smq_head;
92 smq->smq_head++;
93 if ((unsigned long)smq->smq_head > ((unsigned long)smq->smq_msgBuffer +
94 (unsigned long)(smq->smq_depth * sizeof (smq_msg_t)))) {
95 smq->smq_head = smq->smq_msgBuffer;
97 smq->smq_count--;
104 smq_send(smq_t *smq, smq_msg_t *msg)
106 if ((smq->smq_control & SMQ_VALID_SMQ_MASK) != SMQ_VALID_SMQ)
109 if (smq->smq_count == smq->smq_depth)
113 *smq->smq_tail = *msg;
115 smq->smq_tail++;
116 if ((unsigned long)smq->smq_tail > ((unsigned long)smq->smq_msgBuffer +
117 (unsigned long)(smq->smq_depth * sizeof (smq_msg_t)))) {
118 smq->smq_tail = smq->smq_msgBuffer;
121 smq->smq_count++;
122 (void) xsem_post(&smq->smq_msgAvail);
129 smq_pendingmsgs(smq_t *smq, int *num)
131 if ((smq->smq_control & SMQ_VALID_SMQ_MASK) != SMQ_VALID_SMQ)
134 *num = smq->smq_count;
141 smq_depth(smq_t *smq, int *depth)
143 if ((smq->smq_control & SMQ_VALID_SMQ_MASK) != SMQ_VALID_SMQ)
146 *depth = smq->smq_depth;
153 smq_xreceive(smq_t *smq, timestruc_t *timeout, smq_msg_t *msg)
158 if ((smq->smq_control & SMQ_VALID_SMQ_MASK) != SMQ_VALID_SMQ)
162 if ((Status = xsem_xwait(&smq->smq_msgAvail, 1, timeout)) == XSEM_ETIME)
168 if (smq->smq_count == 0)
172 *msg = *smq->smq_head;
174 smq->smq_head++;
175 if ((unsigned long)smq->smq_head > ((unsigned long)smq->smq_msgBuffer +
176 (unsigned long)(smq->smq_depth * sizeof (smq_msg_t)))) {
177 smq->smq_head = smq->smq_msgBuffer;
179 smq->smq_count--;