+ //Wait for queue to be in readable condition
+ while(!pthread_mq_readable(mq)) {
+ if(abs_timeout == NULL) {
+ ret = pthread_cond_wait(&mq->cond_readable, &mq->lock);
+ } else {
+ //printf("RTimed: %p\n", abs_timeout);
+ //assert(abs_timeout != NULL);
+ ret = pthread_cond_timedwait(&mq->cond_readable, &mq->lock, abs_timeout);
+ }
+ if(ret) {
+ pthread_mutex_unlock(&mq->lock);
+ return false;
+ }
+ }
+
+ //Read data from queue
+ void *ptr = mq->data + (mq->head_idx * mq->msg_size);
+ memcpy(data, ptr, mq->msg_size);
+
+ //Delete data from queue if not peeking
+ bool peek = (flags & PTHREAD_XMQ_PEEK);
+ if(!peek) {
+ mq->msg_count--;
+ mq->head_idx = (mq->head_idx+1) % mq->msg_count_max;
+ }
+
+ //Signal conditions and unlock
+ pthread_mq_cond(mq);
+ pthread_mutex_unlock(&mq->lock);
+ return true;