Skip to content

Commit

Permalink
use libuv thread functions to ease portability, and hopefully work ar…
Browse files Browse the repository at this point in the history
…ound #178
  • Loading branch information
stevengj committed May 20, 2014
1 parent 4ab3df9 commit ca8d926
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/heartbeat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,13 @@
function heartbeat_thread(sock::Ptr{Void})
ccall((:zmq_device,ZMQ.zmq), Cint, (Cint, Ptr{Void}, Ptr{Void}),
2, sock, sock)
nothing # not correct on Windows, but irrelevant since we never return
nothing
end
const heartbeat_c = cfunction(heartbeat_thread, Void, (Ptr{Void},))

if @windows? false : true
const threadid = Array(Int, 128) # sizeof(pthread_t) is <= 8 on Linux & OSX
end
const threadid = Array(Int, 128) # sizeof(uv_thread_t) <= 8 on Linux, OSX, Win

function start_heartbeat(sock)
@windows? begin
ccall(:_beginthread, Int, (Ptr{Void}, Cuint, Ptr{Void}),
heartbeat_c, 0, sock.data)
end : begin
ccall((:pthread_create, :libpthread), Cint,
(Ptr{Int}, Ptr{Void}, Ptr{Void}, Ptr{Void}),
threadid, C_NULL, heartbeat_c, sock.data)
end
ccall(:uv_thread_create, Cint, (Ptr{Int}, Ptr{Void}, Ptr{Void}),
threadid, heartbeat_c, sock.data)
end

0 comments on commit ca8d926

Please sign in to comment.