Skip to content

Commit

Permalink
include nanomsg in std libs
Browse files Browse the repository at this point in the history
  • Loading branch information
richardhundt committed Apr 7, 2014
1 parent d29cab9 commit 0ba06e6
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 33 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Expand Up @@ -7,3 +7,6 @@
[submodule "deps/tvmjit"]
path = deps/tvmjit
url = https://github.com/richardhundt/tvmjit.git
[submodule "deps/nanomsg"]
path = deps/nanomsg
url = https://github.com/nanomsg/nanomsg.git
15 changes: 8 additions & 7 deletions Makefile
Expand Up @@ -63,23 +63,22 @@ export LDPOST

LPEG := ${DEPDIR}/lpeg/lpeg.so

DEPS := ${BUILD}/deps/liblpeg.a \
${BUILD}/deps/libtvmjit.a

EXEC := ${BUILD}/shine

NGAC := ${BUILD}/shinec

XDEPS = ${DEPS} \
NDEPS = ${BUILD}/deps/liblpeg.a \
${BUILD}/deps/libtvmjit.a

XDEPS = ${NDEPS} \
${BUILD}/lang.a \
${BUILD}/core.a \
${BUILD}/main.o \
${BUILD}/shnc.o

CDEPS = ${BUILD}/deps/liblpeg.a \
${BUILD}/deps/libtvmjit.a \
${BUILD}/core.a \
CDEPS = ${NDEPS} \
${BUILD}/lang.a \
${BUILD}/core.a \
${BUILD}/shnc.o

all: dirs ${TJ} ${LPEG} ${LIBS} ${EXEC} ${NGAC} libs
Expand All @@ -93,6 +92,7 @@ dirs:
libs:
git submodule update --init ${DEPDIR}/upoll
git submodule update --init ${DEPDIR}/uthread
git submodule update --init ${DEPDIR}/nanomsg
make -C ./lib

${BUILD}/shine: ${TJ} ${XDEPS}
Expand Down Expand Up @@ -169,6 +169,7 @@ realclean: clean
make -C ./lib clean
make -C ${DEPDIR}/tvmjit clean
make -C ${DEPDIR}/lpeg clean
stat -q ${DEPDIR}/nanomsg/Makefile && make -C ${DEPDIR}/nanomsg clean
rm -rf ${BUILD}

bootstrap: ${TJ} ${LPEG}
Expand Down
1 change: 1 addition & 0 deletions deps/nanomsg
Submodule nanomsg added at 6e840d
13 changes: 11 additions & 2 deletions lib/Makefile
Expand Up @@ -9,7 +9,7 @@ LIBS := ${BUILD}/libs/sys.so \

all: ${LIBS}

${BUILD}/libs/sys.so: ${BUILD}/uthread.o
${BUILD}/libs/sys.so: ${BUILD}/libnanomsg.a ${BUILD}/uthread.o
${SHC} -n "sys" sys/init.shn ${BUILD}/sys.o
${SHC} -n "sys.unix" sys/unix.shn ${BUILD}/sys_unix.o
${SHC} -n "sys.win32" sys/win32.shn ${BUILD}/sys_win32.o
Expand All @@ -20,11 +20,13 @@ ${BUILD}/libs/sys.so: ${BUILD}/uthread.o
${SHC} -n "sys.ffi.linux" sys/ffi/linux.shn ${BUILD}/sys_ffi_linux.o
${SHC} -n "sys.argparse" sys/argparse.shn ${BUILD}/sys_argparse.o
${SHC} -n "sys.thread" sys/thread.shn ${BUILD}/sys_thread.o
${SHC} -n "sys.nanomsg" sys/nanomsg.shn ${BUILD}/sys_nanomsg.o
${CC} ${SOFLAGS} -o ${BUILD}/libs/sys.so ${LDFLAGS} \
${BUILD}/sys.o ${BUILD}/sys_unix.o ${BUILD}/sys_win32.o \
${BUILD}/sys_ffi.o ${BUILD}/sys_ffi_posix.o ${BUILD}/sys_ffi_osx.o \
${BUILD}/sys_ffi_bsd.o ${BUILD}/sys_ffi_linux.o ${BUILD}/sys_argparse.o \
${BUILD}/sys_thread.o ${BUILD}/uthread.o ${LPTHREAD}
${BUILD}/sys_nanomsg.o ${BUILD}/sys_thread.o \
${LDPRE} ${BUILD}/libnanomsg.a ${LDPOST} ${BUILD}/uthread.o ${LPTHREAD}

${BUILD}/libs/async.so: ${BUILD}/upoll.o
${SHC} -n "async" async/init.shn ${BUILD}/async.o
Expand Down Expand Up @@ -80,11 +82,18 @@ ${BUILD}/trex.o:
${CC} -c -O2 -fPIC -Wno-unused-value ${DEPDIR}/trex/trex.c \
-o ${BUILD}/trex.o -I${DEPDIR}/trex

${DEPDIR}/nanomsg/Makefile:
cd ${DEPDIR}/nanomsg && ./autogen.sh && ./configure --prefix=${BUILD}

${BUILD}/libnanomsg.a: ${DEPDIR}/nanomsg/Makefile
cd ${DEPDIR}/nanomsg && make && make install
cp ${DEPDIR}/nanomsg/.libs/libnanomsg.a ${BUILD}/libnanomsg.a

clean:
rm -f ${BUILD}/upoll.o
rm -f ${BUILD}/trex.o
rm -f ${BUILD}/libs/*.so
rm -f ${BUILD}/libnanomsg.a

install:
install -m 0644 ${BUILD}/libs/sys.so ${PREFIX}/lib/shine/sys.so
Expand Down
23 changes: 14 additions & 9 deletions lib/async/fiber.shn
Expand Up @@ -45,16 +45,21 @@ class Fiber
for i=1, #alive do
fiber = alive[i]
if fiber.active and fiber.status() != "dead" then
Fiber::current = fiber
ok, rv = resume(fiber.coro, unpack(fiber.args))
Fiber::current = Fiber::main
if not ok then
error(rv, 2)
end
if fiber.status() == "dead" then
fiber.finish(rv)
if fiber == Fiber::main then
fiber.queued = false
return
else
ready[#ready + 1] = fiber
Fiber::current = fiber
ok, rv = resume(fiber.coro, unpack(fiber.args))
Fiber::current = Fiber::main
if not ok then
error(rv, 2)
end
if fiber.status() == "dead" then
fiber.finish(rv)
else
ready[#ready + 1] = fiber
end
end
else
fiber.queued = false
Expand Down
9 changes: 8 additions & 1 deletion lib/async/loop.shn
Expand Up @@ -196,6 +196,13 @@ module IOLoop
mod_poller(poller)
if poller.index then
lib::upoll_ctl(upoll, lib.UPOLL_CTL_MOD, poller.fd, poller.event)
if poller.event.events == 0 and not poller.paused then
poller.paused = true
poll_cnt -= 1
elseif poller.paused and poller.event.events != 0 then
poll_cnt += 1
poller.paused = nil
end
end
end

Expand Down Expand Up @@ -294,7 +301,7 @@ module IOLoop
end

-- poll
--print "upoll_wait:", poll_dur
--print "upoll_wait:", poll_dur, poll_cnt
rv = lib::upoll_wait(upoll, poll_evt, poll_max, poll_dur)

-- run expired timers
Expand Down
48 changes: 34 additions & 14 deletions sample/thread.shn
@@ -1,30 +1,50 @@
import Thread, Pipe from "sys.thread"
import Thread from "sys.thread"
import Socket from "sys.nanomsg"

local ch1 = Pipe(64)
local ch1 = "inproc://1"

local th1 = Thread::create =>

import async from "async"

nns = Socket(Socket::NN_PAIR)
print("bind:", nns.bind(ch1))

print "Hello from a th1"
print "ch1:", ch1
for i=1, 100000 do
--print "[1] tick %{i}"
ch1.put("[1] %{i}")
f1 = async =>
for i=1, 100000 do
--print "[1] tick %{i}"
nns.send("[1] %{i}")
end
end
print "1 join..."
f1.join()
print "1 done"
end

local th2 = Thread::create =>
print "Hello from th2"
local got
for i=1, 100000 do
got = ch1.get()
assert(got != null)
--print "[2] got: %{got}"

import async from "async"

nns = Socket(Socket::NN_PAIR)
nns.connect(ch1)

f1 = async =>
local got
for i=1, 100000 do
got = nns.recv()
--print "[2] got: %{got}"
assert(got != null)
end
print "got: %{got}"
end
print "got: %{got}"
print "2 join..."
f1.join()
print "2 done."
end

th2.join()
th1.join()
print "HERE:", ch1.$c
ch1 = nil
--collectgarbage "collect"

0 comments on commit 0ba06e6

Please sign in to comment.