Skip to content

Commit

Permalink
dd
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee committed Jul 4, 2024
1 parent d6df7b5 commit 35f8049
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions msgq/msgq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ void msgq_close_queue(msgq_queue_t *q){
}
}


void msgq_init_publisher(msgq_queue_t * q) {
//std::cout << "Starting publisher" << std::endl;
uint64_t uid = msgq_get_uid();
Expand Down Expand Up @@ -388,19 +387,16 @@ int msgq_msg_recv(msgq_msg_t * msg, msgq_queue_t * q){
goto start;
}


return msg->size;
}



int msgq_poll(msgq_pollitem_t * items, size_t nitems, int timeout) {
int num = 0;
int timeout_ms = (timeout == -1) ? 100 : timeout;
uint32_t last_futex_value = 0;

auto start = std::chrono::high_resolution_clock::now();
while (num == 0) {
while (true) {
if (g_futex.wait(last_futex_value, timeout_ms)) {
last_futex_value = g_futex.value();

Expand All @@ -415,6 +411,7 @@ int msgq_poll(msgq_pollitem_t * items, size_t nitems, int timeout) {
break;
}
}

auto now = std::chrono::high_resolution_clock::now();
timeout_ms -= std::chrono::duration_cast<std::chrono::milliseconds>(now - start).count();
if (timeout_ms <= 0) {
Expand Down

0 comments on commit 35f8049

Please sign in to comment.