This source file includes following definitions.
- mqe_alloc
- mqe_free
- msgqueue_initialise
- msgqueue_free
- msgqueue_msglength
- msgqueue_getmsg
- msgqueue_addmsg
- msgqueue_flush
1
2
3
4
5
6
7
8
9 #include <linux/module.h>
10 #include <linux/kernel.h>
11 #include <linux/stddef.h>
12 #include <linux/init.h>
13
14 #include "msgqueue.h"
15
16
17
18
19
20
21
22 static struct msgqueue_entry *mqe_alloc(MsgQueue_t *msgq)
23 {
24 struct msgqueue_entry *mq;
25
26 if ((mq = msgq->free) != NULL)
27 msgq->free = mq->next;
28
29 return mq;
30 }
31
32
33
34
35
36
37
38 static void mqe_free(MsgQueue_t *msgq, struct msgqueue_entry *mq)
39 {
40 if (mq) {
41 mq->next = msgq->free;
42 msgq->free = mq;
43 }
44 }
45
46
47
48
49
50
51 void msgqueue_initialise(MsgQueue_t *msgq)
52 {
53 int i;
54
55 msgq->qe = NULL;
56 msgq->free = &msgq->entries[0];
57
58 for (i = 0; i < NR_MESSAGES; i++)
59 msgq->entries[i].next = &msgq->entries[i + 1];
60
61 msgq->entries[NR_MESSAGES - 1].next = NULL;
62 }
63
64
65
66
67
68
69
70 void msgqueue_free(MsgQueue_t *msgq)
71 {
72 }
73
74
75
76
77
78
79
80 int msgqueue_msglength(MsgQueue_t *msgq)
81 {
82 struct msgqueue_entry *mq = msgq->qe;
83 int length = 0;
84
85 for (mq = msgq->qe; mq; mq = mq->next)
86 length += mq->msg.length;
87
88 return length;
89 }
90
91
92
93
94
95
96
97
98 struct message *msgqueue_getmsg(MsgQueue_t *msgq, int msgno)
99 {
100 struct msgqueue_entry *mq;
101
102 for (mq = msgq->qe; mq && msgno; mq = mq->next, msgno--);
103
104 return mq ? &mq->msg : NULL;
105 }
106
107
108
109
110
111
112
113
114
115 int msgqueue_addmsg(MsgQueue_t *msgq, int length, ...)
116 {
117 struct msgqueue_entry *mq = mqe_alloc(msgq);
118 va_list ap;
119
120 if (mq) {
121 struct msgqueue_entry **mqp;
122 int i;
123
124 va_start(ap, length);
125 for (i = 0; i < length; i++)
126 mq->msg.msg[i] = va_arg(ap, unsigned int);
127 va_end(ap);
128
129 mq->msg.length = length;
130 mq->msg.fifo = 0;
131 mq->next = NULL;
132
133 mqp = &msgq->qe;
134 while (*mqp)
135 mqp = &(*mqp)->next;
136
137 *mqp = mq;
138 }
139
140 return mq != NULL;
141 }
142
143
144
145
146
147
148 void msgqueue_flush(MsgQueue_t *msgq)
149 {
150 struct msgqueue_entry *mq, *mqnext;
151
152 for (mq = msgq->qe; mq; mq = mqnext) {
153 mqnext = mq->next;
154 mqe_free(msgq, mq);
155 }
156 msgq->qe = NULL;
157 }
158
159 EXPORT_SYMBOL(msgqueue_initialise);
160 EXPORT_SYMBOL(msgqueue_free);
161 EXPORT_SYMBOL(msgqueue_msglength);
162 EXPORT_SYMBOL(msgqueue_getmsg);
163 EXPORT_SYMBOL(msgqueue_addmsg);
164 EXPORT_SYMBOL(msgqueue_flush);
165
166 MODULE_AUTHOR("Russell King");
167 MODULE_DESCRIPTION("SCSI message queue handling");
168 MODULE_LICENSE("GPL");