Please explain arrayq_put() in arrayq.c
Hi ,
I am a novice programmer in Device Driver and Kernel Programming.I have come through a function in arrayq.c whose main work is to put element in the Queue.The function is given below:-
int arrayq_put(arrayq_t *q, void *base, arrayq_elem_t *data)
{
spin_lock(&q->lock);
if (arrayq_full(q))
{
spin_unlock(&q->lock);
return 10;
}
if ((data->size + sizeof(arrayq_elem_t)) > q->elem_size)
{
printk ("<%d> <%d> : <%d>\n", data->size, sizeof(arrayq_elem_t), q->elem_size);
spin_unlock(&q->lock);
return 0;
}
memcpy(base + q->put * q->elem_size,
data,
data->size + sizeof(arrayq_elem_t));
q->put++;
q->put &= q->mask;
spin_unlock(&q->lock);
return 1;
}
The thing here I don't understand is use of arrayq_elem_t *data which is used both as Source Pointer and Size in memcpy() method.The various structure used are given as follows:-
typedef struct
{
unsigned exponent;
unsigned size;
unsigned mask;
unsigned put;
unsigned get;
unsigned elem_size;
spinlock_t lock;
}
arrayq_t;
typedef struct
{
unsigned size;
}
arrayq_elem_t;
|