Hi, Harsh
I can't share all the project source code with you. It is a large project with so many source code files and also limited by my company policy. I post the function where it crashes. Hope it helps.
typedef struct evt_event_ty
{
EVT_CONTENT
} t_event;
// The Event Queue object type:
typedef struct evt_queue_ty
{
t_event *evt_buffer; // the address of the event buffer
word evtqsize; // and size of it.
word evt_head; // event head -index (keep it word!)
t_event *pevt_tail; // event tail -pointer
word evt_cnt; // counts events in the queue
word max_evt_cnt; // max used event queue size
word lost_events; // events lost -counter
struct evt_queue_ty *next; // next evtQueue in chain
} evtQueue;
pevtQueue evtCreateEventQueue(unsigned int size)
{
evtQueue *This;
evtQueue *Chain;
This = (evtQueue*)malloc(sizeof(evtQueue) + size*sizeof(t_event));
if (This != NULL)
{
This->evt_buffer = (t_event*)(This+1);
/* preset instance: */
This->evt_head = 0;
This->pevt_tail = This->evt_buffer;
This->evt_cnt = 0;
This->max_evt_cnt = 0;
This->lost_events = 0;
This->next = NULL;
This->evtqsize = size;
if (evtFirstQ == NULL) /* the first time ? (..is the best? HUH!) */
{
kernServiceReg(&evtPump);
/* preset static variables: */
curEvent = NULL; /* no events under progress */
evtFirstQ = This; /* and This is the first queue in chain */
}
else
for (Chain=evtFirstQ; ; Chain=Chain->next)
{
/* chain the queue: */
if (Chain->next == NULL) /* if the end-of-chain found */
{
if (evtFirstQ == NULL) /* if there's no chain yet, */
evtFirstQ = This; /* then start it by This. */
else /* Otherwise */
Chain->next = This; /* set This to the end of the chain. */
break; /* a faster way out, than next loop... */
}
}
}
K2_ASSERT(This != NULL);
return This; /* ok, give the pointer to the created queue */
}