diff options
author | sapier <Sapier at GMX dot net> | 2014-01-14 22:21:15 +0100 |
---|---|---|
committer | sapier <Sapier at GMX dot net> | 2014-01-15 20:03:11 +0100 |
commit | 4896d4b829d5e980dd3da586d7d713209ed72e89 (patch) | |
tree | c0c100ebfedba80d59d044323f3a0f5c52b68f2d /src/jthread/win32 | |
parent | f42f01758c72c28c0428f9eb0989e6846c72f7d1 (diff) | |
download | minetest-4896d4b829d5e980dd3da586d7d713209ed72e89.tar.gz minetest-4896d4b829d5e980dd3da586d7d713209ed72e89.tar.bz2 minetest-4896d4b829d5e980dd3da586d7d713209ed72e89.zip |
Fix win32 reading semaphore count not working (broke all queues)
Diffstat (limited to 'src/jthread/win32')
-rwxr-xr-x | src/jthread/win32/jsemaphore.cpp | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/src/jthread/win32/jsemaphore.cpp b/src/jthread/win32/jsemaphore.cpp index 34167f391..40623b13d 100755 --- a/src/jthread/win32/jsemaphore.cpp +++ b/src/jthread/win32/jsemaphore.cpp @@ -66,14 +66,41 @@ bool JSemaphore::Wait(unsigned int time_ms) { } } +typedef LONG (NTAPI *_NtQuerySemaphore)( + HANDLE SemaphoreHandle, + DWORD SemaphoreInformationClass, + PVOID SemaphoreInformation, + ULONG SemaphoreInformationLength, + PULONG ReturnLength OPTIONAL +); + +typedef struct _SEMAPHORE_BASIC_INFORMATION { + ULONG CurrentCount; + ULONG MaximumCount; +} SEMAPHORE_BASIC_INFORMATION; + +/* Note: this will only work as long as jthread is directly linked to application */ +/* it's gonna fail if someone tries to build jthread as dll */ +static _NtQuerySemaphore NtQuerySemaphore = + (_NtQuerySemaphore) + GetProcAddress + (GetModuleHandle ("ntdll.dll"), "NtQuerySemaphore"); + int JSemaphore::GetValue() { + SEMAPHORE_BASIC_INFORMATION BasicInfo; + LONG retval; - long int retval = 0; - ReleaseSemaphore( - m_hSemaphore, - 0, - &retval); + assert(NtQuerySemaphore); + + retval = NtQuerySemaphore (m_hSemaphore, 0, + &BasicInfo, sizeof (SEMAPHORE_BASIC_INFORMATION), NULL); - return retval; + if (retval == ERROR_SUCCESS) + { + return BasicInfo.CurrentCount; + } + else { + assert("unable to read semaphore count" == 0); + } } |