Skip to content

Commit

Permalink
(ext) manually allocate loop
Browse files Browse the repository at this point in the history
  • Loading branch information
stakach committed Oct 16, 2018
1 parent a679fe9 commit 4b5adb7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/libuv/ext/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ class FsRequest < FFI::Struct
attach_function :version_string, :uv_version_string, [], :string
attach_function :loop_alive, :uv_loop_alive, [:uv_loop_t], :int

attach_function :loop_size, :uv_loop_size, [], :size_t, :blocking => false
attach_function :loop_init, :uv_loop_init, [:uv_loop_t], :int, :blocking => false
attach_function :loop_close, :uv_loop_close, [:uv_loop_t], :int, :blocking => false

attach_function :loop_new, :uv_loop_new, [], :uv_loop_t, :blocking => true
attach_function :loop_delete, :uv_loop_delete, [:uv_loop_t], :void, :blocking => true
attach_function :default_loop, :uv_default_loop, [], :uv_loop_t, :blocking => true
Expand Down
5 changes: 4 additions & 1 deletion lib/libuv/reactor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ def default
#
# @return [::Libuv::Reactor]
def new(&blk)
thread = create(::Libuv::Ext.loop_new)
memory = ::Libuv::Ext::LIBC.malloc(::Libuv::Ext.loop_size)
::Libuv::Ext.loop_init(memory)

thread = create(memory)
if block_given?
::Thread.new do
thread.run &blk
Expand Down

0 comments on commit 4b5adb7

Please sign in to comment.