guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

81/376: Add some assertions


From: Ludovic Courtès
Subject: 81/376: Add some assertions
Date: Wed, 28 Jan 2015 22:04:11 +0000

civodul pushed a commit to tag 1.8
in repository guix.

commit 1eb0af7ed563c6d77e1b8e36e81ba6ede7e49f5a
Author: Eelco Dolstra <address@hidden>
Date:   Thu Jul 24 00:16:06 2014 +0200

    Add some assertions
---
 src/libutil/monitor-fd.hh |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/src/libutil/monitor-fd.hh b/src/libutil/monitor-fd.hh
index d8db650..ebfc230 100644
--- a/src/libutil/monitor-fd.hh
+++ b/src/libutil/monitor-fd.hh
@@ -1,6 +1,7 @@
 #pragma once
 
 #include <thread>
+#include <atomic>
 
 #include <poll.h>
 #include <sys/types.h>
@@ -14,10 +15,12 @@ class MonitorFdHup
 {
 private:
     std::thread thread;
+    std::atomic_bool quit;
 
 public:
     MonitorFdHup(int fd)
     {
+        quit = false;
         thread = std::thread([&]() {
             /* Wait indefinitely until a POLLHUP occurs. */
             struct pollfd fds[1];
@@ -25,8 +28,10 @@ public:
             fds[0].events = 0;
             if (poll(fds, 1, -1) == -1) {
                 if (errno != EINTR) abort(); // can't happen
+                assert(quit);
                 return; // destructor is asking us to exit
             }
+            assert(fds[0].revents & POLLHUP);
             /* We got POLLHUP, so send an INT signal to the main thread. */
             kill(getpid(), SIGINT);
         });
@@ -34,6 +39,7 @@ public:
 
     ~MonitorFdHup()
     {
+        quit = true;
         pthread_kill(thread.native_handle(), SIGINT);
         thread.join();
     }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]