diff options
author | Benoit Germain <bnt.germain@gmail.com> | 2011-02-21 20:33:39 +0100 |
---|---|---|
committer | Benoit Germain <bnt.germain@gmail.com> | 2011-02-21 20:33:39 +0100 |
commit | 974aa4343cf900938b5d357d10798d91faf60f5a (patch) | |
tree | b71a342e26ce04c447955f2fc135b69760ab7837 /src/lanes.c | |
parent | 1760eafa1d2ebce8f07e11414a53d4a251af5b8e (diff) | |
download | lanes-974aa4343cf900938b5d357d10798d91faf60f5a.tar.gz lanes-974aa4343cf900938b5d357d10798d91faf60f5a.tar.bz2 lanes-974aa4343cf900938b5d357d10798d91faf60f5a.zip |
Make the number of internal keeper states selectable by an optional parameter passed to require.
Diffstat (limited to 'src/lanes.c')
-rw-r--r-- | src/lanes.c | 33 |
1 files changed, 11 insertions, 22 deletions
diff --git a/src/lanes.c b/src/lanes.c index a8aba71..8b62532 100644 --- a/src/lanes.c +++ b/src/lanes.c | |||
@@ -4,20 +4,7 @@ | |||
4 | * Multithreading in Lua. | 4 | * Multithreading in Lua. |
5 | * | 5 | * |
6 | * History: | 6 | * History: |
7 | * 3-Jan-11 (2.0.10): linda_send bugfix, was waiting on the wrong signal | 7 | * See CHANGES |
8 | * 3-Dec-10 (2.0.9): Added support to generate a lane from a string | ||
9 | * 2-Dec-10 (2.0.8): Fix LuaJIT2 incompatibility (no 'tostring' hijack anymore) | ||
10 | * ???????? (2.0.7): Fixed 'memory leak' in some situations where a free running | ||
11 | * lane is collected before application shutdown | ||
12 | * 24-Aug-10 (2.0.6): Mem fixes, argument checking (lua_toLinda result), thread name | ||
13 | * 24-Jun-09 (2.0.4): Made friendly to already multithreaded host apps. | ||
14 | * 20-Oct-08 (2.0.2): Added closing of free-running threads, but it does | ||
15 | * not seem to eliminate the occasional segfaults at process | ||
16 | * exit. | ||
17 | * ... | ||
18 | * 24-Jun-08 .. 14-Aug-08 AKa: Major revise, Lanes 2008 version (2.0 rc1) | ||
19 | * ... | ||
20 | * 18-Sep-06 AKa: Started the module. | ||
21 | * | 8 | * |
22 | * Platforms (tested internally): | 9 | * Platforms (tested internally): |
23 | * OS X (10.5.7 PowerPC/Intel) | 10 | * OS X (10.5.7 PowerPC/Intel) |
@@ -64,7 +51,7 @@ | |||
64 | * ... | 51 | * ... |
65 | */ | 52 | */ |
66 | 53 | ||
67 | const char *VERSION= "2.0.11"; | 54 | const char *VERSION= "2.1.0"; |
68 | 55 | ||
69 | /* | 56 | /* |
70 | =============================================================================== | 57 | =============================================================================== |
@@ -1913,7 +1900,7 @@ static const struct luaL_reg lanes_functions [] = { | |||
1913 | /* | 1900 | /* |
1914 | * One-time initializations | 1901 | * One-time initializations |
1915 | */ | 1902 | */ |
1916 | static void init_once_LOCKED( lua_State *L, volatile DEEP_PRELUDE ** timer_deep_ref ) | 1903 | static void init_once_LOCKED( lua_State *L, volatile DEEP_PRELUDE ** timer_deep_ref, int const nbKeepers) |
1917 | { | 1904 | { |
1918 | const char *err; | 1905 | const char *err; |
1919 | 1906 | ||
@@ -1964,7 +1951,7 @@ static void init_once_LOCKED( lua_State *L, volatile DEEP_PRELUDE ** timer_deep_ | |||
1964 | } | 1951 | } |
1965 | #endif | 1952 | #endif |
1966 | #endif | 1953 | #endif |
1967 | err= init_keepers(); | 1954 | err= init_keepers( nbKeepers); |
1968 | if (err) | 1955 | if (err) |
1969 | { | 1956 | { |
1970 | luaL_error( L, "Unable to initialize: %s", err ); | 1957 | luaL_error( L, "Unable to initialize: %s", err ); |
@@ -2001,8 +1988,11 @@ int | |||
2001 | #if (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) | 1988 | #if (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) |
2002 | __declspec(dllexport) | 1989 | __declspec(dllexport) |
2003 | #endif | 1990 | #endif |
2004 | luaopen_lanes( lua_State *L ) { | 1991 | luaopen_lanes( lua_State *L ) |
2005 | 1992 | { | |
1993 | static volatile int /*bool*/ go_ahead; // = 0 | ||
1994 | int const nbKeepers = luaL_optint( L, 2, 1); | ||
1995 | luaL_argcheck( L, nbKeepers > 0, 2, "Number of keeper states must be > 0"); | ||
2006 | /* | 1996 | /* |
2007 | * Making one-time initializations. | 1997 | * Making one-time initializations. |
2008 | * | 1998 | * |
@@ -2010,7 +2000,6 @@ __declspec(dllexport) | |||
2010 | * there is no problem. But if the host is multithreaded, we need to lock around the | 2000 | * there is no problem. But if the host is multithreaded, we need to lock around the |
2011 | * initializations. | 2001 | * initializations. |
2012 | */ | 2002 | */ |
2013 | static volatile int /*bool*/ go_ahead; // = 0 | ||
2014 | #ifdef PLATFORM_WIN32 | 2003 | #ifdef PLATFORM_WIN32 |
2015 | { | 2004 | { |
2016 | // TBD: Someone please replace this with reliable Win32 API code. Problem is, | 2005 | // TBD: Someone please replace this with reliable Win32 API code. Problem is, |
@@ -2022,7 +2011,7 @@ __declspec(dllexport) | |||
2022 | static volatile unsigned my_number; // = 0 | 2011 | static volatile unsigned my_number; // = 0 |
2023 | 2012 | ||
2024 | if (my_number++ == 0) { // almost atomic | 2013 | if (my_number++ == 0) { // almost atomic |
2025 | init_once_LOCKED(L, &timer_deep); | 2014 | init_once_LOCKED(L, &timer_deep, nbKeepers); |
2026 | go_ahead= 1; // let others pass | 2015 | go_ahead= 1; // let others pass |
2027 | } else { | 2016 | } else { |
2028 | while( !go_ahead ) { Sleep(1); } // changes threads | 2017 | while( !go_ahead ) { Sleep(1); } // changes threads |
@@ -2036,7 +2025,7 @@ __declspec(dllexport) | |||
2036 | // Recheck now that we're within the lock | 2025 | // Recheck now that we're within the lock |
2037 | // | 2026 | // |
2038 | if (!go_ahead) { | 2027 | if (!go_ahead) { |
2039 | init_once_LOCKED(L, &timer_deep); | 2028 | init_once_LOCKED(L, &timer_deep, nbKeepers); |
2040 | go_ahead= 1; | 2029 | go_ahead= 1; |
2041 | } | 2030 | } |
2042 | } | 2031 | } |