Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ResetEvent function #295

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Features
* [#271](https://github.com/twall/jna/pull/271): Added `com.sun.jna.platform.win32.OpenGL32`, `OpenGL32Util` and `WinOpenGL` - [@kc7bfi](https://github.com/kc7bfi).
* [#250](https://github.com/twall/jna/pull/250): Added `com.sun.jna.platform.win32.Kernel32.GetPrivateProfileSection`, `GetPrivateProfileSectionNames` and `WritePrivateProfileSection` and corresponding `Kernel32Util` helpers - [@quipsy-karg](https://github.com/quipsy-karg).
* [#287](https://github.com/twall/jna/pull/287): Added `DBTF_MEDIA` and `DBTF_NET` to `com.sun.jna.platform.win32.DBT` - [@daifei4321](https://github.com/daifei4321).
* Added ResetEvent - [@manithree](https://github.com/manithree).

Bug Fixes
---------
Expand Down
14 changes: 13 additions & 1 deletion contrib/platform/src/com/sun/jna/platform/win32/Kernel32.java
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,18 @@ HANDLE CreateEvent(WinBase.SECURITY_ATTRIBUTES lpEventAttributes,
*/
boolean SetEvent(HANDLE hEvent);

/**
* Resets (to non-signaled state) the specified event object.
*
* @param hEvent
* A handle to the event object
*
* @return If the function succeeds, the return value is nonzero.
* If the function fails the return value is zero. To get
* extended error information, call GetLastError.
*/
boolean ResetEvent(HANDLE hEvent);

/**
* Sets the specified event object to the signaled state and then resets it
* to the nonsignaled state after releasing the appropriate number of
Expand Down Expand Up @@ -2042,4 +2054,4 @@ boolean WritePrivateProfileString(String lpAppName, String lpKeyName,
* @return If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.
*/
boolean WritePrivateProfileSection(String lpAppName, String lpString, String lpFileName);
}
}
21 changes: 21 additions & 0 deletions contrib/platform/test/com/sun/jna/platform/win32/Kernel32Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,27 @@ public void testWaitForSingleObject() {
Kernel32.INSTANCE.CloseHandle(handle);
}

public void testResetEvent() {
HANDLE handle = Kernel32.INSTANCE.CreateEvent(null, true, false, null);

// set the event to the signalled state
Kernel32.INSTANCE.SetEvent(handle);

// This should return successfully
assertEquals(WinBase.WAIT_OBJECT_0, Kernel32.INSTANCE.WaitForSingleObject(
handle, 1000));

// now reset it to unsignalled
Kernel32.INSTANCE.ResetEvent(handle);

// handle runs into timeout since it is not triggered
// WAIT_TIMEOUT = 0x00000102
assertEquals(WinError.WAIT_TIMEOUT, Kernel32.INSTANCE.WaitForSingleObject(
handle, 1000));

Kernel32.INSTANCE.CloseHandle(handle);
}

public void testWaitForMultipleObjects(){
HANDLE[] handles = new HANDLE[2];

Expand Down