int test_hrt(int argc, char *argv[]) { struct hrt_call call; hrt_abstime prev, now; int i; struct timeval tv1, tv2; printf("start-time (hrt, sec/usec), end-time (hrt, sec/usec), microseconds per 1/10 second\n"); for (i = 0; i < 10; i++) { prev = hrt_absolute_time(); gettimeofday(&tv1, nullptr); usleep(100000); now = hrt_absolute_time(); gettimeofday(&tv2, nullptr); printf("%lu (%lu/%lu), %lu (%lu/%lu), %lu\n", (unsigned long)prev, (unsigned long)tv1.tv_sec, (unsigned long)tv1.tv_usec, (unsigned long)now, (unsigned long)tv2.tv_sec, (unsigned long)tv2.tv_usec, (unsigned long)(hrt_absolute_time() - prev)); fflush(stdout); } usleep(1000000); printf("one-second ticks\n"); for (i = 0; i < 3; i++) { hrt_call_after(&call, 1000000, nullptr, nullptr); while (!hrt_called(&call)) { usleep(1000); } printf("tick\n"); fflush(stdout); } return 0; }
bool ORBDevNode::appears_updated(SubscriberData *sd) { /* assume it doesn't look updated */ bool ret = false; /* avoid racing between interrupt and non-interrupt context calls */ irqstate_t state = irqsave(); /* check if this topic has been published yet, if not bail out */ if (_data == nullptr) { ret = false; goto out; } /* * If the subscriber's generation count matches the update generation * count, there has been no update from their perspective; if they * don't match then we might have a visible update. */ while (sd->generation != _generation) { /* * Handle non-rate-limited subscribers. */ if (sd->update_interval == 0) { ret = true; break; } /* * If we have previously told the subscriber that there is data, * and they have not yet collected it, continue to tell them * that there has been an update. This mimics the non-rate-limited * behaviour where checking / polling continues to report an update * until the topic is read. */ if (sd->update_reported) { ret = true; break; } /* * If the interval timer is still running, the topic should not * appear updated, even though at this point we know that it has. * We have previously been through here, so the subscriber * must have collected the update we reported, otherwise * update_reported would still be true. */ if (!hrt_called(&sd->update_call)) break; /* * Make sure that we don't consider the topic to be updated again * until the interval has passed once more by restarting the interval * timer and thereby re-scheduling a poll notification at that time. */ hrt_call_after(&sd->update_call, sd->update_interval, &ORBDevNode::update_deferred_trampoline, (void *)this); /* * Remember that we have told the subscriber that there is data. */ sd->update_reported = true; ret = true; break; } out: irqrestore(state); /* consider it updated */ return ret; }