Poll error is not longer breaking everything

This commit is contained in:
Андреев Григорий 2024-08-25 21:37:04 +03:00
parent 785cbff2a7
commit 2ad4f5b52d

View File

@ -212,7 +212,7 @@ namespace een9 {
pthread_create(&workers[i], NULL, worker_func, wtes[i].get()); pthread_create(&workers[i], NULL, worker_func, wtes[i].get());
} }
// todo: move this try block inside the loop // todo: right now this try block protects threads. So I need to put pthreads in some kind of guarding object
try { try {
int ret; int ret;
struct Ear { struct Ear {
@ -251,18 +251,16 @@ namespace een9 {
} }
ASSERT(params.mainloop_recheck_interval_us > 0, "Incorrect poll timeout"); ASSERT(params.mainloop_recheck_interval_us > 0, "Incorrect poll timeout");
while (true) { while (true) {
// MutexLockGuard lg1(wtec.corvee_bed, "poller termination check");
if (wtec.termination) if (wtec.termination)
break; break;
// lg1.unlock();
for (size_t i = 0; i < Nip; i++) { for (size_t i = 0; i < Nip; i++) {
pollfds[i].revents = 0; pollfds[i].revents = 0;
} }
errno = 0; errno = 0;
ret = poll(pollfds.data(), Nip, params.mainloop_recheck_interval_us); ret = poll(pollfds.data(), Nip, params.mainloop_recheck_interval_us);
if (errno == EINTR) if (ret != 0) {
break; printf("poll() error :> %d\n", errno);
// todo: do not end program here (in the loop. Nothing in the loop should be able to end program) }
ASSERT_on_iret(ret, "poll()"); ASSERT_on_iret(ret, "poll()");
for (size_t i = 0; i < Nip; i++) { for (size_t i = 0; i < Nip; i++) {
if ((pollfds[i].revents & POLLRDNORM)) { if ((pollfds[i].revents & POLLRDNORM)) {
@ -294,7 +292,7 @@ namespace een9 {
} catch (const std::exception& e) { } catch (const std::exception& e) {
printf("System failure 2\n"); printf("System failure 2\n");
printf("%s\n", e.what()); printf("%s\n", e.what());
/* There is no need to tiptoe around this multi-access field. It is write-onle-and-for-good-kind */ /* There is no need to tiptoe around this multi-access field. It is write-once-and-for-good-kind */
wtec.termination = true; wtec.termination = true;
wtec.corvee_bed.wake_them_all(); wtec.corvee_bed.wake_them_all();
} }