Author: mturk Date: Thu Aug 13 14:15:52 2009 New Revision: 803899 URL: http://svn.apache.org/viewvc?rev=803899&view=rev Log: Allow to break the INFINIITE wait loops
Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c commons/sandbox/runtime/trunk/src/main/native/os/win32/pmutex.c Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h?rev=803899&r1=803898&r2=803899&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h Thu Aug 13 14:15:52 2009 @@ -345,14 +345,6 @@ return; } -/** - * Utility functions - */ -wchar_t *res_name_from_filenamew(int, wchar_t *, const wchar_t *); -int utf8_to_unicode_path(wchar_t *, size_t, const char *); -int unicode_to_utf8_path(char *, size_t, const wchar_t *); - - struct dirent { ino_t d_ino; /* inode number */ off_t d_off; /* offset to the next dirent */ Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h?rev=803899&r1=803898&r2=803899&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h Thu Aug 13 14:15:52 2009 @@ -88,12 +88,22 @@ /** * Heap allocation from main.c */ +extern HANDLE dll_psig_handle; extern HANDLE dll_heap_handle; #define ACR_HeapMalloc(S) HeapAlloc(dll_heap_handle, 0, (S)) #define ACR_HeapCalloc(S) HeapAlloc(dll_heap_handle, HEAP_ZERO_MEMORY, (S)) #define ACR_HeapFree(M) HeapFree(dll_heap_handle, 0, (M)) +/** + * Utility functions from wutilc. + */ +wchar_t *res_name_from_filenamew(int, wchar_t *, const wchar_t *); +int utf8_to_unicode_path(wchar_t *, size_t, const char *); +int unicode_to_utf8_path(char *, size_t, const wchar_t *); + + + #ifdef __cplusplus } #endif Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c?rev=803899&r1=803898&r2=803899&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c Thu Aug 13 14:15:52 2009 @@ -31,6 +31,7 @@ static WCHAR dll_file_name[ACR_HBUFF_SIZ]; static DWORD dll_tls_index = TLS_OUT_OF_INDEXES; HANDLE dll_heap_handle = NULL; +HANDLE dll_psig_handle = NULL; static SYSTEM_INFO osinf; static OSVERSIONINFOEXA osver; @@ -267,6 +268,12 @@ } ++pp; } + /* + * Create a simple unnamed signaling event. + */ + dll_psig_handle = CreateEvent(NULL, TRUE, FALSE, NULL); + if (IS_INVALID_HANDLE(dll_psig_handle)) + return ACR_GET_OS_ERROR(); /* Do not display file not found messge boxes. * Return the error to the application instead */ Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/pmutex.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/pmutex.c?rev=803899&r1=803898&r2=803899&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/pmutex.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/pmutex.c Thu Aug 13 14:15:52 2009 @@ -37,6 +37,7 @@ { int rc; HANDLE m; + SECURITY_ATTRIBUTES sa; wchar_t *reskey; wchar_t keybuf[128]; @@ -51,7 +52,13 @@ */ reskey = res_name_from_filenamew(ACR_DT_MUTEX, keybuf, fname); } - m = CreateMutexW(NULL, FALSE, reskey); + /* Mark the mutex as non inheritable + */ + sa.nLength = sizeof(SECURITY_ATTRINUTES); + sa.lpSecurityDescriptor = NULL; + sa.bInheritHandle = FALSE: + + m = CreateMutexW(&sa, FALSE, reskey); if (!m) return -1; @@ -87,17 +94,39 @@ ACR_DECLARE(int) ACR_ProcMutexLock(JNIEnv *_E, int mutex) { int rc; - HANDLE m = (HANDLE)ACR_IOH(mutex); - - if (IS_INVALID_HANDLE(m) || ACR_IOH_TYPE(mutex) != ACR_DT_MUTEX) { + DWORD ws; + HANDLE wh[2]; + + wh[0] = (HANDLE)ACR_IOH(mutex); + wh[1] = dll_psig_handle; + if (IS_INVALID_HANDLE(wh[0]) || ACR_IOH_TYPE(mutex) != ACR_DT_MUTEX) { return ACR_EINVAL; } - rc = WaitForSingleObject(m, INFINITE); + do { + rc = 0; + ws = WaitForMultipleObjectExObject(2, wh, FALSE, INFINITE, TRUE); + + if (ws == WAIT_OBJECT_0 || ws == WAIT_ABANDONED) { + /* We got the lock */ + return 0; + } + else if (ws == WAIT_OBJECT_0 + 1) { + /* Signal event is set + * TODO: Deliver a signal + */ + rc = ACR_EINTR; + } + else if (ws == WAIT_IO_COMPLETION) { + /* APC queued to this thread + * TODO: Deliver a signal + */ + rc = ACR_TIMEUP; + } + else + rc = ACR_GET_OS_ERROR(); + } while (rc == ACR_EINTR); - if (rc == WAIT_OBJECT_0 || rc == WAIT_ABANDONED) { - return 0; - } - return ACR_GET_OS_ERROR(); + return rc; } ACR_DECLARE(int) ACR_ProcMutexTryLock(JNIEnv *_E, int mutex)