Skip to content

Commit

Permalink
luaproc 1.0-1 commit. See CHANGELOG for changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
askyrme committed May 16, 2014
1 parent 12d6002 commit 9111a2c
Show file tree
Hide file tree
Showing 19 changed files with 1,422 additions and 1,997 deletions.
68 changes: 68 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
***************************************************
*
* Copyright 2014 Alexandre Skyrme, Noemi Rodriguez, Roberto Ierusalimschy
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*****************************************************
*
* [CHANGELOG]
*
****************************************************

[v1.0-1]

* Major code revision by Pablo Musa:
- Internal data structures are now stored in Lua tables, removing the need
for memory management in C;
- Messages can contain strings, numbers, booleans and nil;
- Improved error handling in Lua processes;
- Functions luaproc.createworker and luaproc.destroyworker replaced by
function luaproc.setnumworkers;
- Added function luaproc.getnumworkers;
- Code clean-up.

* Added support to send and receive messages to/from main Lua script, which
also resulted in a unified API for both the main (parent) Lua script and the
child Lua processes (created with luaproc.newproc).

* Removed function luaproc.exit.

* Added function luaproc.wait, which waits until all Lua processes have
finished executing and can be used for synchronization. Unlike luaproc.exit,
which had to be the last function to be called, luaproc.wait can be called at
any point in a script. It is always implicitly called when the main Lua
script finishes executing.

* Fixed a race condition that was trigged by the main Lua script exiting while
luaproc workers were active. When Lua unloads dynamic libraries with
dlclose() while it is exiting, pthreads is unloaded while workers are still
active, causing a segmentation fault. Workers (pthreads) are now joined, via
a finalizer, when luaproc is unloaded.

* Fixed a race condition when creating new Lua processes with recycling.

* Fixed include guard conflict in sched.h (now lpsched.h).

* Included release in LuaRocks.

[v1.0b1]

* First public beta release.

2 changes: 1 addition & 1 deletion COPYRIGHT
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ and commercial purposes at absolutely no cost.

===============================================================================

Copyright (C) 2008 Alexandre Skyrme, Noemi Rodriguez, Roberto Ierusalimschy
Copyright (C) 2008-2014 Alexandre Skyrme, Noemi Rodriguez, Roberto Ierusalimschy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
52 changes: 32 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
####################################################
#
# Copyright 2008 Alexandre Skyrme, Noemi Rodriguez, Roberto Ierusalimschy
# Copyright 2008-2014 Alexandre Skyrme, Noemi Rodriguez, Roberto Ierusalimschy
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -27,38 +27,50 @@
######################################################

# path to lua header files
LUA_INC_PATH=/usr/include/lua5.1
LUA_INCDIR=/usr/include/lua5.1
# path to lua library
LUA_LIB_PATH=/usr/lib/lua5.1
LUA_LIBDIR=/usr/lib/x86_64-linux-gnu/
# path to install library
LUA_CPATH=/usr/share/lua/5.1

# standard makefile variables
CC=gcc
CFLAGS=-c -Wall -fPIC -I${LUA_INC_PATH}
LDFLAGS=-shared -L${LUA_LIB_PATH} -lpthread
SOURCES=sched.c list.c luaproc.c channel.c
SRCDIR=src
BINDIR=bin
CFLAGS=-c -O2 -Wall -fPIC -I${LUA_INCDIR}
# MacOS X users should replace LIBFLAG with the following definition
# LIBFLAG=-bundle -undefined dynamic_lookup
LIBFLAG=-shared
#
LDFLAGS=${LIBFLAG} -L${LUA_LIBDIR} -lpthread
SOURCES=${SRCDIR}/lpsched.c ${SRCDIR}/luaproc.c
OBJECTS=${SOURCES:.c=.o}
LIB=luaproc.so

# luaproc specific variables
LIBNAME=luaproc
LIB=${LIBNAME}.so

# build targets
all: ${SOURCES} ${LIB}

${LIB}: ${OBJECTS}
${CC} ${OBJECTS} -o $@ ${LDFLAGS}
${CC} ${OBJECTS} -o ${BINDIR}/$@ ${LDFLAGS}

sched.o: sched.c sched.h list.h luaproc.h channel.h
${CC} ${CFLAGS} sched.c
install:
mkdir -p ${LUA_CPATH}/${LIBNAME}
cp -v ${LIB} ${LUA_CPATH}/${LIBNAME}

list.o: list.c list.h
${CC} ${CFLAGS} list.c
lpsched.o: lpsched.c lpsched.h luaproc.h
@cd src && ${CC} ${CFLAGS} lpsched.c

luaproc.o: luaproc.c luaproc.h list.h sched.h channel.h
${CC} ${CFLAGS} luaproc.c

channel.o: channel.c channel.h list.h
${CC} ${CFLAGS} channel.c
luaproc.o: luaproc.c luaproc.h lpsched.h
@cd src && ${CC} ${CFLAGS} luaproc.c

clean:
rm -f ${OBJECTS} ${LIB}
rm -f ${OBJECTS} ${BINDIR}/${LIB}

# list targets that do not create files (but not all makes understand .PHONY)
.PHONY: clean install

test:
lua test.lua
# (end of Makefile)

71 changes: 24 additions & 47 deletions README
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
***************************************************
*
* Copyright 2008 Alexandre Skyrme, Noemi Rodriguez, Roberto Ierusalimschy
* Copyright 2014 Alexandre Skyrme, Noemi Rodriguez, Roberto Ierusalimschy
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -26,59 +26,39 @@
*
****************************************************


**************
* PARENT API *
**************

-- Create a new lua process
-- Create a new Lua process
-- Returns true if sucessful or nil, error_message if failed
luaproc.newproc( <string lua_code> )

-- Create a new worker (pthread)
-- Returns true if sucessful or nil, error_message if failed
luaproc.createworker( <void> )
-- Set the number of active workers (default = 1, min = 1)
-- Creates/destroys workers depending on the number of active workers
-- No return, raises error if worker(s) could not be created
luaproc.setnumworkers( <int number_of_workers> )

-- Destroy a worker (pthread)
-- Returns true if sucessful or nil, error_message if failed
luaproc.destroyworker( <void> )
-- Get the number of active workers
-- Returns the number of active workers
luaproc.getnumworkers( <void> )

-- Synchronize workers (pthreads) and exit after all lua processes have ended
-- No return, finishes execution.
luaproc.exit( <void> )
-- Wait for all Lua processes to finish
-- No return
-- Obs.: It only makes sense to call this function from the main Lua script.
-- Moreover, this function is always implicitly called when the main Lua
-- script finishes executing.
luaproc.wait( <void> )

-- Set maximum lua processes that should be recycled (default = 0)
-- Set the maximum number of Lua processes that can be recycled (default = 0)
-- Returns true if sucessful or nil, error_message if failed
luaproc.recycle( <int maxrecycle> )

************************************************************
* CHILD API *
* Available only to processes spawned *
* with luaproc.newproc *
************************************************************

-- Create a new lua process
-- Returns true if sucessful or nil, error_message if failed
luaproc.newproc( <string lua_code> )

-- Create a new worker (pthread)
-- Send a message (boolean, nil, number or string) on a channel
-- Returns true if sucessful or nil, error_message if failed
luaproc.createworker( <void> )
-- Blocks when there is no matching receive
luaproc.send( <string channel_name>, <msg1>, [msg2], [msg3], ... )

-- Destroy a worker (pthread)
-- Returns true if sucessful or nil, error_message if failed
luaproc.destroyworker( <void> )

-- Send a message on a channel
-- Returns true if sucessful or nil, error_message if failed
-- Results in blocking if there is no matching receive
luaproc.send( <string channel_name>, <string msg1>,
[string msg2], [string msg3], ... )

-- Receive a message on a channel
-- Returns message string(s) if sucessful or nil, error_message if failed
-- Results in blocking if there is no matching send
-- and the asynchronous flag is not set (nil) or set to false
-- Receive a message (boolean, nil, number or string) on a channel
-- Returns message(s) if sucessful or nil, error_message if failed
-- Blocks when there is no matching send and the optional asynchronous
-- flag is not set (nil) or set to false
luaproc.receive( <string channel_name>, [boolean asynchronous] )

-- Create a new channel
Expand All @@ -89,9 +69,6 @@ luaproc.newchannel( <string channel_name> )
-- Returns true if sucessful or nil, error_message if failed
luaproc.delchannel( <string channel_name> )

-- Set maximum lua processes that should be recycled (default = 0)
-- Returns true if sucessful or nil, error_message if failed
luaproc.recycle( <int maxrecycle> )

<> = mandatory arguments
[] = optional arguments

Loading

0 comments on commit 9111a2c

Please sign in to comment.