2 #include "wilc_msgqueue.h"
3 #include <linux/spinlock.h>
4 #include <linux/errno.h>
5 #include <linux/slab.h>
10 * @note copied from FLO glue implementatuion
13 int wilc_mq_create(struct message_queue *mq)
15 spin_lock_init(&mq->lock);
16 sema_init(&mq->sem, 0);
17 INIT_LIST_HEAD(&mq->msg_list);
26 * @note copied from FLO glue implementatuion
29 int wilc_mq_destroy(struct message_queue *mq)
35 /* Release any waiting receiver thread. */
36 while (mq->recv_count > 0) {
41 while (!list_empty(&mq->msg_list)) {
42 msg = list_first_entry(&mq->msg_list, struct message, list);
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)
68 /* construct a new message */
69 new_msg = kmalloc(sizeof(*new_msg), GFP_ATOMIC);
73 new_msg->len = send_buf_size;
74 INIT_LIST_HEAD(&new_msg->list);
75 new_msg->buf = kmemdup(send_buf, send_buf_size, GFP_ATOMIC);
81 spin_lock_irqsave(&mq->lock, flags);
83 /* add it to the message queue */
84 list_add_tail(&new_msg->list, &mq->msg_list);
86 spin_unlock_irqrestore(&mq->lock, flags);
96 * @note copied from FLO glue implementatuion
99 int wilc_mq_recv(struct message_queue *mq,
100 void *recv_buf, u32 recv_buf_size, u32 *recv_len)
105 if (!mq || (recv_buf_size == 0) || !recv_buf || !recv_len)
111 spin_lock_irqsave(&mq->lock, flags);
113 spin_unlock_irqrestore(&mq->lock, flags);
116 spin_lock_irqsave(&mq->lock, flags);
118 if (list_empty(&mq->msg_list)) {
119 spin_unlock_irqrestore(&mq->lock, flags);
123 /* check buffer size */
124 msg = list_first_entry(&mq->msg_list, struct message, list);
125 if (recv_buf_size < msg->len) {
126 spin_unlock_irqrestore(&mq->lock, flags);
131 /* consume the message */
133 memcpy(recv_buf, msg->buf, msg->len);
134 *recv_len = msg->len;
136 list_del(&msg->list);
141 spin_unlock_irqrestore(&mq->lock, flags);