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 e32dd78 commit 4e11eba
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions messaging/impl_msgq.cc
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
#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 @@ -87,7 +82,7 @@ Message *MSGQSubSocket::receive(bool non_blocking) {

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

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

0 comments on commit 4e11eba

Please sign in to comment.