Skip to content

Commit

Permalink
dd
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee committed May 29, 2024
1 parent 1806010 commit e32dd78
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions messaging/impl_msgq.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
#include <cassert>
#include <cstring>
#include <iostream>
#include <chrono>
#include <csignal>

#include "cereal/services.h"
#include "cereal/messaging/impl_msgq.h"

static inline uint64_t nanos_since_boot() {
struct timespec t;
clock_gettime(CLOCK_BOOTTIME, &t);
return t.tv_sec * 1000000000ULL + t.tv_nsec;
}

static bool service_exists(std::string path){
return services.count(path) > 0;
}
Expand Down Expand Up @@ -80,10 +85,9 @@ Message *MSGQSubSocket::receive(bool non_blocking) {
sigaddset(&mask, SIGTERM);
sigprocmask(SIG_BLOCK, &mask, nullptr);

int64_t timeout_ns = ((timeout != -1) ? timeout : 100) * 1000000;
int64_t remaining = timeout_ns;
auto start_time = std::chrono::steady_clock::now();

int64_t timieout_ns = ((timeout != -1) ? timeout : 100) * 1000000;
int64_t remaining = timieout_ns;
uint64_t start_ns = nanos_since_boot();
while (rc == 0 && remaining > 0) {
struct timespec ts {remaining / 1000000000, remaining % 1000000000};
int ret = sigtimedwait(&mask, nullptr, &ts);
Expand All @@ -95,8 +99,7 @@ Message *MSGQSubSocket::receive(bool non_blocking) {
}

rc = msgq_msg_recv(&msg, q);
auto elapsed_time = std::chrono::steady_clock::now() - start_time;
remaining = timeout == -1 ? timeout_ns : (timeout_ns - std::chrono::duration_cast<std::chrono::nanoseconds>(elapsed_time).count());
remaining = timeout == -1 ? timieout_ns : (timieout_ns - (nanos_since_boot() - start_ns));
}
sigprocmask(SIG_UNBLOCK, &mask, nullptr);
}
Expand Down

0 comments on commit e32dd78

Please sign in to comment.