don't make so many clock_gettime syscalls
For all of the code that runs periodically for short periods of time,
making more than just 1 syscall to figure out what time it currently is
is pointless and a waste of CPU.
diff --git a/bbb_cape/src/bbb/uart_reader.cc b/bbb_cape/src/bbb/uart_reader.cc
index 7f88d51..fe1c526 100644
--- a/bbb_cape/src/bbb/uart_reader.cc
+++ b/bbb_cape/src/bbb/uart_reader.cc
@@ -56,13 +56,13 @@
ssize_t UartReader::ReadBytes(uint8_t *dest, size_t max_bytes,
const ::aos::time::Time &timeout_time) {
+ fd_set fds;
+ FD_ZERO(&fds);
do {
::aos::time::Time timeout = timeout_time - ::aos::time::Time::Now();
if (timeout < ::aos::time::Time(0, 0)) return -2;
struct timeval timeout_timeval = timeout.ToTimeval();
- fd_set fds;
- FD_ZERO(&fds);
- FD_SET(fd_, &fds);
+ FD_SET(fd_, &fds);
switch (select(fd_ + 1, &fds, NULL, NULL, &timeout_timeval)) {
case 0:
return -2;