diff options
author | Benoit Germain <bnt.germain@gmail.com> | 2011-11-07 20:09:06 +0100 |
---|---|---|
committer | Benoit Germain <bnt.germain@gmail.com> | 2011-11-07 20:09:06 +0100 |
commit | fb4b7acae4bdacd6c0f669591956281011bc0068 (patch) | |
tree | 6b6b94da4dba678ace69256e8400c1e71ca84956 /src | |
parent | 053f7cff3c95acb915e6babfd306971f11bb7986 (diff) | |
download | lanes-fb4b7acae4bdacd6c0f669591956281011bc0068.tar.gz lanes-fb4b7acae4bdacd6c0f669591956281011bc0068.tar.bz2 lanes-fb4b7acae4bdacd6c0f669591956281011bc0068.zip |
* fix all compilation warnings raised by -Wextra
* fix a multithreading issue at desinit causing invalid memory accesses (to be verified)
Diffstat (limited to 'src')
-rw-r--r-- | src/lanes.c | 32 | ||||
-rw-r--r-- | src/threading.c | 6 | ||||
-rw-r--r-- | src/tools.c | 4 |
3 files changed, 23 insertions, 19 deletions
diff --git a/src/lanes.c b/src/lanes.c index 44db625..1ebe91d 100644 --- a/src/lanes.c +++ b/src/lanes.c | |||
@@ -296,7 +296,7 @@ LUAG_FUNC( linda_send) | |||
296 | check_key_types( L, key_i, key_i); | 296 | check_key_types( L, key_i, key_i); |
297 | 297 | ||
298 | // make sure there is something to send | 298 | // make sure there is something to send |
299 | if( lua_gettop( L) == key_i) | 299 | if( (uint_t)lua_gettop( L) == key_i) |
300 | { | 300 | { |
301 | luaL_error( L, "no data to send"); | 301 | luaL_error( L, "no data to send"); |
302 | } | 302 | } |
@@ -994,8 +994,9 @@ static void selfdestruct_add( struct s_lane *s ) { | |||
994 | /* | 994 | /* |
995 | * A free-running lane has ended; remove it from selfdestruct chain | 995 | * A free-running lane has ended; remove it from selfdestruct chain |
996 | */ | 996 | */ |
997 | static void selfdestruct_remove( struct s_lane *s ) { | 997 | static bool_t selfdestruct_remove( struct s_lane *s ) |
998 | 998 | { | |
999 | bool_t found = FALSE; | ||
999 | MUTEX_LOCK( &selfdestruct_cs ); | 1000 | MUTEX_LOCK( &selfdestruct_cs ); |
1000 | { | 1001 | { |
1001 | // Make sure (within the MUTEX) that we actually are in the chain | 1002 | // Make sure (within the MUTEX) that we actually are in the chain |
@@ -1004,7 +1005,6 @@ static void selfdestruct_remove( struct s_lane *s ) { | |||
1004 | // | 1005 | // |
1005 | if (s->selfdestruct_next != NULL) { | 1006 | if (s->selfdestruct_next != NULL) { |
1006 | struct s_lane **ref= (struct s_lane **) &selfdestruct_first; | 1007 | struct s_lane **ref= (struct s_lane **) &selfdestruct_first; |
1007 | bool_t found= FALSE; | ||
1008 | 1008 | ||
1009 | while( *ref != SELFDESTRUCT_END ) { | 1009 | while( *ref != SELFDESTRUCT_END ) { |
1010 | if (*ref == s) { | 1010 | if (*ref == s) { |
@@ -1019,6 +1019,7 @@ static void selfdestruct_remove( struct s_lane *s ) { | |||
1019 | } | 1019 | } |
1020 | } | 1020 | } |
1021 | MUTEX_UNLOCK( &selfdestruct_cs ); | 1021 | MUTEX_UNLOCK( &selfdestruct_cs ); |
1022 | return found; | ||
1022 | } | 1023 | } |
1023 | 1024 | ||
1024 | // Initialized by 'init_once_LOCKED()': the deep userdata Linda object | 1025 | // Initialized by 'init_once_LOCKED()': the deep userdata Linda object |
@@ -1031,6 +1032,7 @@ volatile DEEP_PRELUDE *timer_deep; // = NULL | |||
1031 | */ | 1032 | */ |
1032 | static int selfdestruct_atexit( lua_State *L) | 1033 | static int selfdestruct_atexit( lua_State *L) |
1033 | { | 1034 | { |
1035 | (void)L; // unused | ||
1034 | if (selfdestruct_first == SELFDESTRUCT_END) return 0; // no free-running threads | 1036 | if (selfdestruct_first == SELFDESTRUCT_END) return 0; // no free-running threads |
1035 | 1037 | ||
1036 | // Signal _all_ still running threads to exit (including the timer thread) | 1038 | // Signal _all_ still running threads to exit (including the timer thread) |
@@ -1466,7 +1468,8 @@ LUAG_FUNC( set_debug_threadname) | |||
1466 | lua_newtable(L); | 1468 | lua_newtable(L); |
1467 | } | 1469 | } |
1468 | s->waiting_on = NULL; // just in case | 1470 | s->waiting_on = NULL; // just in case |
1469 | if (s->selfdestruct_next != NULL) { | 1471 | if( selfdestruct_remove( s)) // check and remove (under lock!) |
1472 | { | ||
1470 | // We're a free-running thread and no-one's there to clean us up. | 1473 | // We're a free-running thread and no-one's there to clean us up. |
1471 | // | 1474 | // |
1472 | lua_close( s->L ); | 1475 | lua_close( s->L ); |
@@ -1476,7 +1479,6 @@ LUAG_FUNC( set_debug_threadname) | |||
1476 | SIGNAL_FREE( &s->done_signal_ ); | 1479 | SIGNAL_FREE( &s->done_signal_ ); |
1477 | MUTEX_FREE( &s->done_lock_ ); | 1480 | MUTEX_FREE( &s->done_lock_ ); |
1478 | #endif | 1481 | #endif |
1479 | selfdestruct_remove(s); // away from selfdestruct chain | ||
1480 | free(s); | 1482 | free(s); |
1481 | 1483 | ||
1482 | } else { | 1484 | } else { |
@@ -2201,7 +2203,7 @@ LUAG_FUNC( now_secs ) | |||
2201 | LUAG_FUNC( wakeup_conv ) | 2203 | LUAG_FUNC( wakeup_conv ) |
2202 | { | 2204 | { |
2203 | int year, month, day, hour, min, sec, isdst; | 2205 | int year, month, day, hour, min, sec, isdst; |
2204 | struct tm tm= {0}; | 2206 | struct tm t = {0,0,0,0,0,0,0,0,0}; |
2205 | // | 2207 | // |
2206 | // .year (four digits) | 2208 | // .year (four digits) |
2207 | // .month (1..12) | 2209 | // .month (1..12) |
@@ -2228,15 +2230,15 @@ LUAG_FUNC( wakeup_conv ) | |||
2228 | lua_pop(L,1); | 2230 | lua_pop(L,1); |
2229 | STACK_END(L,0) | 2231 | STACK_END(L,0) |
2230 | 2232 | ||
2231 | tm.tm_year= year-1900; | 2233 | t.tm_year= year-1900; |
2232 | tm.tm_mon= month-1; // 0..11 | 2234 | t.tm_mon= month-1; // 0..11 |
2233 | tm.tm_mday= day; // 1..31 | 2235 | t.tm_mday= day; // 1..31 |
2234 | tm.tm_hour= hour; // 0..23 | 2236 | t.tm_hour= hour; // 0..23 |
2235 | tm.tm_min= min; // 0..59 | 2237 | t.tm_min= min; // 0..59 |
2236 | tm.tm_sec= sec; // 0..60 | 2238 | t.tm_sec= sec; // 0..60 |
2237 | tm.tm_isdst= isdst; // 0/1/negative | 2239 | t.tm_isdst= isdst; // 0/1/negative |
2238 | 2240 | ||
2239 | lua_pushnumber( L, (double) mktime( &tm ) ); // ms=0 | 2241 | lua_pushnumber( L, (double) mktime( &t)); // ms=0 |
2240 | return 1; | 2242 | return 1; |
2241 | } | 2243 | } |
2242 | 2244 | ||
diff --git a/src/threading.c b/src/threading.c index 0a07d47..4e3d8f6 100644 --- a/src/threading.c +++ b/src/threading.c | |||
@@ -74,7 +74,9 @@ THE SOFTWARE. | |||
74 | #if (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) | 74 | #if (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) |
75 | static void FAIL( const char *funcname, int rc ) { | 75 | static void FAIL( const char *funcname, int rc ) { |
76 | fprintf( stderr, "%s() failed! (%d)\n", funcname, rc ); | 76 | fprintf( stderr, "%s() failed! (%d)\n", funcname, rc ); |
77 | #ifdef _MSC_VER | ||
77 | __debugbreak(); // give a chance to the debugger! | 78 | __debugbreak(); // give a chance to the debugger! |
79 | #endif // _MSC_VER | ||
78 | abort(); | 80 | abort(); |
79 | } | 81 | } |
80 | #endif | 82 | #endif |
@@ -281,9 +283,9 @@ static void prepare_timeout( struct timespec *ts, time_d abs_secs ) { | |||
281 | } | 283 | } |
282 | // | 284 | // |
283 | bool_t THREAD_WAIT( THREAD_T *ref, double secs ) { | 285 | bool_t THREAD_WAIT( THREAD_T *ref, double secs ) { |
284 | long ms= (long)((secs*1000.0)+0.5); | 286 | DWORD ms = (secs<0.0) ? INFINITE : (DWORD)((secs*1000.0)+0.5); |
285 | 287 | ||
286 | DWORD rc= WaitForSingleObject( *ref, ms<0 ? INFINITE:ms /*timeout*/ ); | 288 | DWORD rc= WaitForSingleObject( *ref, ms /*timeout*/ ); |
287 | // | 289 | // |
288 | // (WAIT_ABANDONED) | 290 | // (WAIT_ABANDONED) |
289 | // WAIT_OBJECT_0 success (0) | 291 | // WAIT_OBJECT_0 success (0) |
diff --git a/src/tools.c b/src/tools.c index b412e84..36e0051 100644 --- a/src/tools.c +++ b/src/tools.c | |||
@@ -136,6 +136,7 @@ static bool_t openlib( lua_State *L, const char *name, size_t len ) { | |||
136 | 136 | ||
137 | static int dummy_writer(lua_State *L, const void* p, size_t sz, void* ud) | 137 | static int dummy_writer(lua_State *L, const void* p, size_t sz, void* ud) |
138 | { | 138 | { |
139 | (void)L; (void)p; (void)sz; (void) ud; // unused | ||
139 | return 666; | 140 | return 666; |
140 | } | 141 | } |
141 | 142 | ||
@@ -1229,7 +1230,6 @@ static void inter_copy_func( lua_State *L2, uint_t L2_cache_i, lua_State *L, uin | |||
1229 | { | 1230 | { |
1230 | FuncSubType funcSubType; | 1231 | FuncSubType funcSubType; |
1231 | lua_CFunction cfunc = luaG_tocfunction( L, i, &funcSubType); // NULL for LuaJIT-fast && bytecode functions | 1232 | lua_CFunction cfunc = luaG_tocfunction( L, i, &funcSubType); // NULL for LuaJIT-fast && bytecode functions |
1232 | i = STACK_ABS( L, i); | ||
1233 | 1233 | ||
1234 | ASSERT_L( L2_cache_i != 0 ); | 1234 | ASSERT_L( L2_cache_i != 0 ); |
1235 | STACK_GROW(L,2); | 1235 | STACK_GROW(L,2); |
@@ -1241,7 +1241,7 @@ static void inter_copy_func( lua_State *L2, uint_t L2_cache_i, lua_State *L, uin | |||
1241 | luaL_Buffer b; | 1241 | luaL_Buffer b; |
1242 | // 'lua_dump()' needs the function at top of stack | 1242 | // 'lua_dump()' needs the function at top of stack |
1243 | // if already on top of the stack, no need to push again | 1243 | // if already on top of the stack, no need to push again |
1244 | int needToPush = (i != lua_gettop( L)); | 1244 | int needToPush = (i != (uint_t)lua_gettop( L)); |
1245 | if( needToPush) | 1245 | if( needToPush) |
1246 | lua_pushvalue( L, i); | 1246 | lua_pushvalue( L, i); |
1247 | 1247 | ||