#include "icq_queue.h" icq_queue_t* icq_queue_init(){ icq_queue_t *queue = malloc(sizeof(icq_queue_t)); if(queue == NULL){ locked_printf("Failed to allocate memory in icq_task_init\n"); exit(1); } queue->msg_counter = 0; queue->msg_received = 0; queue->write_ptx = 0; queue->read_ptx = 0; return queue; } int icq_queue_post_message(icq_queue_t *icq, icq_message_t msg){ if(icq==NULL){ locked_printf("icq is NULL in icq_queue_post_message\n"); exit(1); } if(icq->msg_counter<=CONFIGURE_ICQ_INTERCOREQUEUE_SIZE){ icq_spinlock_lock(icq->spinLock); icq->queue[icq->write_ptx] = msg; icq->write_ptx = icq->write_ptx + 1; if(icq->write_ptx >= CONFIGURE_ICQ_INTERCOREQUEUE_SIZE){ icq->write_ptx = 0; } icq->msg_counter = icq->msg_counter + 1; icq_spinlock_unlock(icq->spinLock); return icq->msg_counter; } else{ return -1; } } icq_message_t icq_queue_read_message(icq_queue_t *icq){ icq_message_t msg; if(icq->msg_counter>0){ msg = icq->queue[icq->read_ptx]; icq->read_ptx = icq->read_ptx + 1; if(icq->read_ptx >= CONFIGURE_ICQ_INTERCOREQUEUE_SIZE){ icq->read_ptx = 0; } icq->msg_counter = icq->msg_counter - 1; } return msg; }