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 ea5e441 commit 7ecf0a0
Showing 1 changed file with 0 additions and 71 deletions.
71 changes: 0 additions & 71 deletions msgq/msgq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,34 +50,6 @@ struct shared_data_t {
int data;
};

// int futex_wait(int *futexp, int val, int timeout_ms) {
// struct timespec ts;
// clock_gettime(CLOCK_REALTIME, &ts);
// ts.tv_sec += (timeout_ms / 1000);
// ts.tv_nsec += (timeout_ms % 1000) * 1000000;
// if (ts.tv_nsec >= 1000000000) {
// ts.tv_sec += 1;
// ts.tv_nsec -= 1000000000;
// }

// int s = syscall(SYS_futex, futexp, FUTEX_WAIT, val, NULL, NULL, 0);
// if (s == -1 && errno != EAGAIN && errno != ETIMEDOUT) {
// perror("futex_wait");
// exit(EXIT_FAILURE);
// }
// return s;
// return syscall(SYS_futex, futexp, FUTEX_WAIT, val, NULL, NULL, 0);
// while (1) {
// int s = syscall(SYS_futex, futexp, FUTEX_WAIT, 0, NULL, NULL, 0);
// if (s == -1 && errno != EAGAIN) {
// perror("futex_wait");
// exit(EXIT_FAILURE);
// }
// if (*futexp == 1) break;
// }
// return 0;
// }

int futex_wake(int *futexp, int val) {
return syscall(SYS_futex, futexp, FUTEX_WAKE, val, NULL, NULL, 0);
}
Expand All @@ -98,25 +70,12 @@ Futex() {
}
header = (shared_data_t *)mmap(NULL, sizeof(shared_data_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
close(fd);
// header->futex = 0;
// header->data = 0;
futex = (std::atomic<int>*)(&header->futex);
event_counter = (std::atomic<int>*)(&header->data);
// if (futex == NULL){
// assert(0);
// }
}

void post() {
printf("begin post\n");
// // while (1) {
// __atomic_exchange_n(futex, 1, __ATOMIC_ACQUIRE);
// int futex_rc = futex_wake(futex, 1);
// if (futex_rc == -1) {
// perror("futex wake");
// exit(1);
// }
// // }
(*event_counter) += 1;
(*futex) += 1;
futex_wake(&(header->futex), INT_MAX);
Expand All @@ -139,39 +98,9 @@ printf("wait %d\n", last_event);
return -1; // Timeout occurred
}
}
// printf("end wait %d %d\n", ret, errno);
return 0;
// while (1) {
// printf("begin wait %d\n", timeout_ms);
// int futex_rc = futex_wait(futex, 0, timeout_ms);
// printf("wait fu %d\n", futex_rc);
// if (futex_rc == -1) {
// if (errno != EAGAIN) {
// perror("futex");
// exit(1);
// }
// } else if (futex_rc == 0) {
// if (*futex == 1) {
// // This is a real wakeup.
// return;
// }
// } else {
// abort();
// }
// }
}

// int acquire(int timeout_ms) {
// // Acquire the futex
// while (__atomic_exchange_n(futex, 1, __ATOMIC_ACQUIRE) != 0) {
// if (futex_wait(futex, 1, timeout_ms) == -1 && errno == ETIMEDOUT) {
// printf("timeout\n");
// return -1;
// }
// }
// return 0;
// }

~Futex() {
munmap(futex, sizeof(int));
}
Expand Down

0 comments on commit 7ecf0a0

Please sign in to comment.