Fix bogus pass by reference

http://hydra.nixos.org/build/12711659
This commit is contained in:
Eelco Dolstra 2014-07-24 09:52:10 +02:00
parent 24c6d992c6
commit aa1560ca07

View file

@ -15,23 +15,19 @@ class MonitorFdHup
{ {
private: private:
std::thread thread; std::thread thread;
std::atomic_bool quit;
public: public:
MonitorFdHup(int fd) MonitorFdHup(int fd)
{ {
quit = false; thread = std::thread([fd]() {
thread = std::thread([&]() {
/* Wait indefinitely until a POLLHUP occurs. */ /* Wait indefinitely until a POLLHUP occurs. */
struct pollfd fds[1]; struct pollfd fds[1];
fds[0].fd = fd; fds[0].fd = fd;
fds[0].events = 0; fds[0].events = 0;
if (poll(fds, 1, -1) == -1) { if (poll(fds, 1, -1) == -1) {
if (errno != EINTR) abort(); // can't happen if (errno != EINTR) abort(); // can't happen
assert(quit);
return; // destructor is asking us to exit return; // destructor is asking us to exit
} }
fprintf(stderr, "GOT: %d\n", fds[0].revents);
assert(fds[0].revents & POLLHUP); assert(fds[0].revents & POLLHUP);
/* We got POLLHUP, so send an INT signal to the main thread. */ /* We got POLLHUP, so send an INT signal to the main thread. */
kill(getpid(), SIGINT); kill(getpid(), SIGINT);
@ -40,7 +36,6 @@ public:
~MonitorFdHup() ~MonitorFdHup()
{ {
quit = true;
pthread_kill(thread.native_handle(), SIGINT); pthread_kill(thread.native_handle(), SIGINT);
thread.join(); thread.join();
} }