Example #1
0
/* Function to read a message from queue with timeout */
int IPC_popMsgTout(void *data, int tout)
{
	struct ipc_queue *qrd   = &q_ipc[CPUID_CURR];
	int raise_event = QUEUE_IS_FULL(qrd);

	if (!QUEUE_IS_VALID(qrd)) {
		return QUEUE_ERROR;
	}

	if ((tout == 0) && QUEUE_IS_EMPTY(qrd)) {
		return QUEUE_EMPTY;
	}

	while (QUEUE_IS_EMPTY(qrd)) {
		if (IPC_EventHandler(IPC_EVENT_WAIT_RX, CPUID_CURR, tout) && (tout > 0)) {
			return QUEUE_TIMEOUT;
		}
	}

	/* Pop the queue Item */
	memcpy(data, qrd->data + ((qrd->tail & (qrd->count - 1)) * qrd->size), qrd->size);
	qrd->tail++;

	if (raise_event) {
		ipc_send_signal();
	}
	return QUEUE_VALID;
}
Example #2
0
// ---------------------------------------------------------------------------
// Read a message from queue with timeout
int IPC_popMsgTout(void *data, int tout)
{
#ifdef EVENT_ON_RX
    int raise_event = QUEUE_IS_FULL(qrd);
#endif

    if (!QUEUE_IS_VALID(qrd)) {
        return QUEUE_ERROR;
    }

    if (tout == 0) {
        // Check if read queue is empty
        if (QUEUE_IS_EMPTY(qrd)) {
            return QUEUE_EMPTY;
        }
    }
    else if (tout < 0) {
        // Wait for read queue to have some data
        //ipc_wait_event(QUEUE_IS_EMPTY(qrd), event_rx);
    }
    else {
        // Wait for event or timeout
        //ipc_wait_event_tout(QUEUE_IS_EMPTY(qrd), tout, event_rx);
        if (tout == 0) {
          return QUEUE_TIMEOUT;
        }
    }

    // Pop the queue Item
    memcpy(data, qrd->data + ((qrd->tail & (qrd->count - 1)) * qrd->size), qrd->size);
    qrd->tail++;

#ifdef EVENT_ON_RX
    if (raise_event) {
        ipc_send_signal();
    }
#endif
    return QUEUE_VALID;
}