-/*
- mq_timedreceive(3) mq_timedreceive(2)
-
- mq_timedsend(3) mq_timedsend(2)
-
-void vQueueDelete( QueueHandle_t xQueue );
-BaseType_t xQueueReset( QueueHandle_t xQueue );
-
- BaseType_t xQueueSend(
- QueueHandle_t xQueue,
- const void * pvItemToQueue,
- TickType_t xTicksToWait
- );
- BaseType_t xQueueReceive(
- QueueHandle_t xQueue,
- void *pvBuffer,
- TickType_t xTicksToWait
- );
+bool pthread_mq_receive_generic(pthread_mq_t *mq, void * data, pthread_mq_flags_t flags, const struct timespec *restrict abs_timeout) {
+ int ret;
+
+ //Lock queue
+ if(pthread_mutex_timedlock(&mq->lock, abs_timeout)) return false;
+
+ //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;
+ }
+ }