/* Get next message from message queue. Return NULL if no message present. User must call next_message() to move to next message. rmq message queue  */
void* gru_get_next_message(struct gru_message_queue_desc *mqd)
/* Get next message from message queue. Return NULL if no message present. User must call next_message() to move to next message. rmq message queue  */
void* gru_get_next_message(struct gru_message_queue_desc *mqd)
{
	struct message_queue *mq = mqd->mq;
	struct message_header *mhdr = mq->next;
	int present = mhdr->present;
	while (present == MQS_NOOP) {
		gru_free_message(mqd, mhdr);
		mhdr = mq->next;
		present = mhdr->present;
	}
	if (present == MQS_FULL && mhdr->lines == 2 &&
				get_present2(mhdr) == MQS_EMPTY)
		present = MQS_EMPTY;
	if (!present) {
		STAT(mesq_receive_none);
		return NULL;
	}
	if (mhdr->lines == 2)
		restore_present2(mhdr, mhdr->present2);
	STAT(mesq_receive);
	return mhdr;
}