d2df1795facb66eab3e418c64a3683a15ee4bf0e
2 #include "wilc_msgqueue.h"
3 #include <linux/spinlock.h>
4 #include "linux_wlan_common.h"
5 #include <linux/errno.h>
6 #include <linux/slab.h>
11 * @note copied from FLO glue implementatuion
14 int wilc_mq_create(struct message_queue
*mq
)
16 spin_lock_init(&mq
->lock
);
17 sema_init(&mq
->sem
, 0);
27 * @note copied from FLO glue implementatuion
30 int wilc_mq_destroy(struct message_queue
*mq
)
34 /* Release any waiting receiver thread. */
35 while (mq
->recv_count
> 0) {
40 while (mq
->msg_list
) {
41 struct message
*msg
= mq
->msg_list
->next
;
53 * @note copied from FLO glue implementatuion
56 int wilc_mq_send(struct message_queue
*mq
,
57 const void *send_buf
, u32 send_buf_size
)
60 struct message
*new_msg
= NULL
;
62 if ((!mq
) || (send_buf_size
== 0) || (!send_buf
)) {
63 PRINT_ER("mq or send_buf is null\n");
68 PRINT_ER("mq fail\n");
72 /* construct a new message */
73 new_msg
= kmalloc(sizeof(struct message
), GFP_ATOMIC
);
77 new_msg
->len
= send_buf_size
;
79 new_msg
->buf
= kmemdup(send_buf
, send_buf_size
, GFP_ATOMIC
);
85 spin_lock_irqsave(&mq
->lock
, flags
);
87 /* add it to the message queue */
89 mq
->msg_list
= new_msg
;
91 struct message
*tail_msg
= mq
->msg_list
;
93 while (tail_msg
->next
)
94 tail_msg
= tail_msg
->next
;
96 tail_msg
->next
= new_msg
;
99 spin_unlock_irqrestore(&mq
->lock
, flags
);
109 * @note copied from FLO glue implementatuion
112 int wilc_mq_recv(struct message_queue
*mq
,
113 void *pvRecvBuffer
, u32 u32RecvBufferSize
,
114 u32
*pu32ReceivedLength
)
116 struct message
*pstrMessage
;
119 if ((!mq
) || (u32RecvBufferSize
== 0)
120 || (!pvRecvBuffer
) || (!pu32ReceivedLength
)) {
121 PRINT_ER("mq or pvRecvBuffer is null\n");
126 PRINT_ER("mq fail\n");
130 spin_lock_irqsave(&mq
->lock
, flags
);
132 spin_unlock_irqrestore(&mq
->lock
, flags
);
135 spin_lock_irqsave(&mq
->lock
, flags
);
137 pstrMessage
= mq
->msg_list
;
139 spin_unlock_irqrestore(&mq
->lock
, flags
);
140 PRINT_ER("pstrMessage is null\n");
143 /* check buffer size */
144 if (u32RecvBufferSize
< pstrMessage
->len
) {
145 spin_unlock_irqrestore(&mq
->lock
, flags
);
147 PRINT_ER("u32RecvBufferSize overflow\n");
151 /* consume the message */
153 memcpy(pvRecvBuffer
, pstrMessage
->buf
, pstrMessage
->len
);
154 *pu32ReceivedLength
= pstrMessage
->len
;
156 mq
->msg_list
= pstrMessage
->next
;
158 kfree(pstrMessage
->buf
);
161 spin_unlock_irqrestore(&mq
->lock
, flags
);
This page took 0.034162 seconds and 4 git commands to generate.