about summary refs log tree commit homepage
path: root/lib/yahns/queue_quitter_pipe.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-10-25 22:55:16 +0000
committerEric Wong <normalperson@yhbt.net>2013-10-25 23:02:01 +0000
commit9bece9d13543743e2a0fdc6eab56c54098d4d0e6 (patch)
tree3aba695efd2d28b8b034520f3c95a16ff8bdd7f7 /lib/yahns/queue_quitter_pipe.rb
parentb73d91e6235f2c83cb768268a6661b88cdc96d4c (diff)
downloadyahns-9bece9d13543743e2a0fdc6eab56c54098d4d0e6.tar.gz
pipes and eventfd are always writable after creation, thus
there's no need to trigger it and watch for readability.
This saves us some code in the Linux case (and we currently
only support GNU/Linux).
Diffstat (limited to 'lib/yahns/queue_quitter_pipe.rb')
-rw-r--r--lib/yahns/queue_quitter_pipe.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/yahns/queue_quitter_pipe.rb b/lib/yahns/queue_quitter_pipe.rb
new file mode 100644
index 0000000..1aa0643
--- /dev/null
+++ b/lib/yahns/queue_quitter_pipe.rb
@@ -0,0 +1,24 @@
+# Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> and all contributors
+# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
+#
+# POSIX pipe version, see queue_quitter.rb for the (preferred) eventfd one
+class Yahns::QueueQuitter # :nodoc:
+  attr_reader :to_io
+  def initialize
+    reader, @to_io = IO.pipe
+    @to_io.close_on_exec = true
+    reader.close
+  end
+
+  def yahns_step
+    Thread.current.exit
+  end
+
+  def fileno
+    @to_io.fileno
+  end
+
+  def close
+    @to_io.close
+  end
+end