+ if ((tr_mq_get_head(mq)==NULL) && (maxwait>0)) {
+ /* No msgs yet, and blocking was requested */
+ if (0!=clock_gettime(CLOCK_REALTIME, &expiration)) {
+ tr_notice("tr_mq_pop: error reading realtime clock.");
+ return NULL;
+ }
+ expiration.tv_sec+=maxwait;
+
+ while ((wait_err==0) && (NULL==tr_mq_get_head(mq)))
+ wait_err=pthread_cond_timedwait(&(mq->have_msg_cond),
+ &(mq->mutex),
+ &expiration);
+
+ if ((wait_err!=0) && (wait_err!=ETIMEDOUT)) {
+ tr_notice("tr_mq_pop: error waiting for message.");
+ return NULL;
+ }
+ /* if it timed out, ok to go ahead and check once more for a message, so no special exit */
+ }
+