void consumer (void *cookie) { ssize_t len; void *msg; int err; /* Bind to a queue which has been created elsewhere, either in kernel or user-space. The call will block us until such queue is created with the expected name. The queue should have been created with the Q_SHARED mode set, which is implicit when creation takes place in user-space. */ err = rt_queue_bind(&q_desc,"SomeQueueName",TM_INFINITE); if (err) fail(); /* Collect each message sent to the queue by the queuer() routine, until the queue is eventually removed from the system by a call to rt_queue_delete(). */ while ((len = rt_queue_receive(&q_desc,&msg,TM_INFINITE)) > 0) { printf("received message> len=%d bytes, ptr=%p, s=%s\n", len,msg,(const char *)msg); rt_queue_free(&q_desc,msg); } /* We need to unbind explicitly from the queue in order to properly release the underlying memory mapping. Exiting the process unbinds all mappings automatically. */ rt_queue_unbind(&q_desc); if (len != -EIDRM) /* We received some unexpected error notification. */ fail(); /* ... */ }
void display(void *cookie) { RT_QUEUE q; int n = 0; time_t start; struct smpl_t { long minjitter, avgjitter, maxjitter, overrun; } *smpl; rt_queue_bind(&q, "queue"); time(&start); while (!finished) { smpl = NULL; rt_queue_recv(&q, (void *)&smpl, TM_INFINITE); if (smpl == NULL) continue; if (data_lines && (n++%data_lines) == 0) { time_t now, dt; time(&now); dt = now - start; printf("rth|%12s|%12s|%12s|%8s| %.2ld:%.2ld:%.2ld\n", "lat min", "lat avg", "lat max", "overrun", dt/3600, (dt/60)%60, dt%60 + 1); } printf("rtd|%12ld|%12ld|%12ld|%8ld\n", smpl->minjitter, smpl->avgjitter, smpl->maxjitter, smpl->overrun); rt_queue_free(&q, smpl); } rt_queue_unbind(&q); }