b996c47af15d423fc2f3ed6b32dead48c9501341
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
*pHandle
)
16 spin_lock_init(&pHandle
->strCriticalSection
);
17 sema_init(&pHandle
->sem
, 0);
18 pHandle
->pstrMessageList
= NULL
;
19 pHandle
->u32ReceiversCount
= 0;
20 pHandle
->bExiting
= false;
27 * @note copied from FLO glue implementatuion
30 int wilc_mq_destroy(struct message_queue
*pHandle
)
32 pHandle
->bExiting
= true;
34 /* Release any waiting receiver thread. */
35 while (pHandle
->u32ReceiversCount
> 0) {
37 pHandle
->u32ReceiversCount
--;
40 while (pHandle
->pstrMessageList
) {
41 struct message
*pstrMessge
= pHandle
->pstrMessageList
->next
;
43 kfree(pHandle
->pstrMessageList
);
44 pHandle
->pstrMessageList
= pstrMessge
;
53 * @note copied from FLO glue implementatuion
56 int wilc_mq_send(struct message_queue
*pHandle
,
57 const void *pvSendBuffer
, u32 u32SendBufferSize
)
60 struct message
*pstrMessage
= NULL
;
62 if ((!pHandle
) || (u32SendBufferSize
== 0) || (!pvSendBuffer
)) {
63 PRINT_ER("pHandle or pvSendBuffer is null\n");
67 if (pHandle
->bExiting
) {
68 PRINT_ER("pHandle fail\n");
72 /* construct a new message */
73 pstrMessage
= kmalloc(sizeof(struct message
), GFP_ATOMIC
);
77 pstrMessage
->len
= u32SendBufferSize
;
78 pstrMessage
->next
= NULL
;
79 pstrMessage
->buf
= kmemdup(pvSendBuffer
, u32SendBufferSize
,
81 if (!pstrMessage
->buf
) {
86 spin_lock_irqsave(&pHandle
->strCriticalSection
, flags
);
88 /* add it to the message queue */
89 if (!pHandle
->pstrMessageList
) {
90 pHandle
->pstrMessageList
= pstrMessage
;
92 struct message
*pstrTailMsg
= pHandle
->pstrMessageList
;
94 while (pstrTailMsg
->next
)
95 pstrTailMsg
= pstrTailMsg
->next
;
97 pstrTailMsg
->next
= pstrMessage
;
100 spin_unlock_irqrestore(&pHandle
->strCriticalSection
, flags
);
110 * @note copied from FLO glue implementatuion
113 int wilc_mq_recv(struct message_queue
*pHandle
,
114 void *pvRecvBuffer
, u32 u32RecvBufferSize
,
115 u32
*pu32ReceivedLength
)
117 struct message
*pstrMessage
;
120 if ((!pHandle
) || (u32RecvBufferSize
== 0)
121 || (!pvRecvBuffer
) || (!pu32ReceivedLength
)) {
122 PRINT_ER("pHandle or pvRecvBuffer is null\n");
126 if (pHandle
->bExiting
) {
127 PRINT_ER("pHandle fail\n");
131 spin_lock_irqsave(&pHandle
->strCriticalSection
, flags
);
132 pHandle
->u32ReceiversCount
++;
133 spin_unlock_irqrestore(&pHandle
->strCriticalSection
, flags
);
136 spin_lock_irqsave(&pHandle
->strCriticalSection
, flags
);
138 pstrMessage
= pHandle
->pstrMessageList
;
140 spin_unlock_irqrestore(&pHandle
->strCriticalSection
, flags
);
141 PRINT_ER("pstrMessage is null\n");
144 /* check buffer size */
145 if (u32RecvBufferSize
< pstrMessage
->len
) {
146 spin_unlock_irqrestore(&pHandle
->strCriticalSection
, flags
);
148 PRINT_ER("u32RecvBufferSize overflow\n");
152 /* consume the message */
153 pHandle
->u32ReceiversCount
--;
154 memcpy(pvRecvBuffer
, pstrMessage
->buf
, pstrMessage
->len
);
155 *pu32ReceivedLength
= pstrMessage
->len
;
157 pHandle
->pstrMessageList
= pstrMessage
->next
;
159 kfree(pstrMessage
->buf
);
162 spin_unlock_irqrestore(&pHandle
->strCriticalSection
, flags
);
This page took 0.033563 seconds and 4 git commands to generate.