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 7ecf0a0 commit 007444c
Showing 1 changed file with 0 additions and 8 deletions.
8 changes: 0 additions & 8 deletions msgq/msgq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,20 @@ Futex() {
}

void post() {
printf("begin post\n");
(*event_counter) += 1;
(*futex) += 1;
futex_wake(&(header->futex), INT_MAX);
printf("posted %d\n", futex->load());
}

int wait(int last_event, int timeout_ms) {
printf("begin wait\n");

struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
ts.tv_sec = (timeout_ms / 1000);
ts.tv_nsec = (timeout_ms % 1000) * 1000000;
printf("wait %d\n", last_event);
if ((*futex) == last_event) {

int ret = syscall(SYS_futex, &header->futex, FUTEX_WAIT, last_event, &ts, NULL, 0);
if (ret == -1 && errno == ETIMEDOUT) {
printf("time out \n");
return -1; // Timeout occurred
}
}
Expand Down Expand Up @@ -512,11 +506,9 @@ int msgq_poll(msgq_pollitem_t * items, size_t nitems, int timeout){

int ret = g_futex.wait(last_event, ms);
if (ret == -1) {
printf("timeout !!\n");
break;
}
last_event = g_futex.futex->load();
printf("%d\n", last_event);
// Check if messages ready
for (size_t i = 0; i < nitems; i++) {
if (items[i].revents == 0 && msgq_msg_ready(items[i].q)){
Expand Down

0 comments on commit 007444c

Please sign in to comment.