diff options
author | Benoit Germain <bnt period germain arrobase gmail period com> | 2014-01-16 14:17:23 +0100 |
---|---|---|
committer | Benoit Germain <bnt period germain arrobase gmail period com> | 2014-01-16 14:17:23 +0100 |
commit | 1843a0add00186eee129b0b0a2ee605866acbb61 (patch) | |
tree | 5de8d13e1b8495836f898c17790adf571f05365c /src/threading.c | |
parent | baaea3cebf9d787f76557b68f18a012dc6adbbbc (diff) | |
download | lanes-1843a0add00186eee129b0b0a2ee605866acbb61.tar.gz lanes-1843a0add00186eee129b0b0a2ee605866acbb61.tar.bz2 lanes-1843a0add00186eee129b0b0a2ee605866acbb61.zip |
Cancellation improvements and some fixes
* bumped version to 3.7.8
* lane:cancel() now accepts a boolean second argument when soft
cancelling (negative timeout) to wake the thread if necessary
* if a blocked linda send() or receive() call is interrupted by a
cancellation request, it returns CANCEL_ERROR so that this case can be
differentiated from a simple timeout
* fixed WIN32 THREAD_CREATE() wrong _beginthreadex() error detection
* fatal WIN32 threading errors retrieve and output the error description
string with FormatMessage()
* fixed missing lanes.set_singlethreaded
* fixed perftest.lua
* added test/cancel.lua
Diffstat (limited to 'src/threading.c')
-rw-r--r-- | src/threading.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/threading.c b/src/threading.c index 3014136..5a3e64b 100644 --- a/src/threading.c +++ b/src/threading.c | |||
@@ -87,11 +87,13 @@ THE SOFTWARE. | |||
87 | #if defined( PLATFORM_XBOX) || defined( PLATFORM_WIN32) || defined( PLATFORM_POCKETPC) | 87 | #if defined( PLATFORM_XBOX) || defined( PLATFORM_WIN32) || defined( PLATFORM_POCKETPC) |
88 | static void FAIL( char const* funcname, int rc) | 88 | static void FAIL( char const* funcname, int rc) |
89 | { | 89 | { |
90 | fprintf( stderr, "%s() failed! (%d)\n", funcname, rc ); | 90 | char buf[256]; |
91 | FormatMessageA( FORMAT_MESSAGE_FROM_SYSTEM, NULL, rc, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 256, NULL); | ||
92 | fprintf( stderr, "%s() failed! [GetLastError() -> %d] '%s'", funcname, rc, buf); | ||
91 | #ifdef _MSC_VER | 93 | #ifdef _MSC_VER |
92 | __debugbreak(); // give a chance to the debugger! | 94 | __debugbreak(); // give a chance to the debugger! |
93 | #endif // _MSC_VER | 95 | #endif // _MSC_VER |
94 | abort(); | 96 | abort(); |
95 | } | 97 | } |
96 | #endif // win32 build | 98 | #endif // win32 build |
97 | 99 | ||
@@ -296,11 +298,15 @@ void THREAD_CREATE( THREAD_T* ref, THREAD_RETURN_T (__stdcall *func)( void*), vo | |||
296 | NULL // thread id (not used) | 298 | NULL // thread id (not used) |
297 | ); | 299 | ); |
298 | 300 | ||
299 | if( h == INVALID_HANDLE_VALUE) | 301 | if( h == NULL) // _beginthreadex returns 0L on failure instead of -1L (like _beginthread) |
302 | { | ||
300 | FAIL( "CreateThread", GetLastError()); | 303 | FAIL( "CreateThread", GetLastError()); |
304 | } | ||
301 | 305 | ||
302 | if (!SetThreadPriority( h, gs_prio_remap[prio + 3])) | 306 | if (!SetThreadPriority( h, gs_prio_remap[prio + 3])) |
307 | { | ||
303 | FAIL( "SetThreadPriority", GetLastError()); | 308 | FAIL( "SetThreadPriority", GetLastError()); |
309 | } | ||
304 | 310 | ||
305 | *ref = h; | 311 | *ref = h; |
306 | } | 312 | } |