Skip to content

Commit 35c743d

Browse files
manithreedblock
authored andcommitted
Added com.sun.jna.platform.win32.Kernel32.ResetEvent.
1 parent c94c3b9 commit 35c743d

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Features
1717
* [#271](https://github.com/twall/jna/pull/271): Added `com.sun.jna.platform.win32.OpenGL32`, `OpenGL32Util` and `WinOpenGL` - [@kc7bfi](https://github.com/kc7bfi).
1818
* [#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).
1919
* [#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).
20+
* [#295](https://github.com/twall/jna/pull/295): Added `com.sun.jna.platform.win32.Kernel32.ResetEvent` - [@manithree](https://github.com/manithree).
2021

2122
Bug Fixes
2223
---------

contrib/platform/src/com/sun/jna/platform/win32/Kernel32.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,18 @@ HANDLE CreateEvent(WinBase.SECURITY_ATTRIBUTES lpEventAttributes,
948948
*/
949949
boolean SetEvent(HANDLE hEvent);
950950

951+
/**
952+
* Resets (to non-signaled state) the specified event object.
953+
*
954+
* @param hEvent
955+
* A handle to the event object
956+
*
957+
* @return If the function succeeds, the return value is nonzero.
958+
* If the function fails the return value is zero. To get
959+
* extended error information, call GetLastError.
960+
*/
961+
boolean ResetEvent(HANDLE hEvent);
962+
951963
/**
952964
* Sets the specified event object to the signaled state and then resets it
953965
* to the nonsignaled state after releasing the appropriate number of
@@ -2042,4 +2054,4 @@ boolean WritePrivateProfileString(String lpAppName, String lpKeyName,
20422054
* @return If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.
20432055
*/
20442056
boolean WritePrivateProfileSection(String lpAppName, String lpString, String lpFileName);
2045-
}
2057+
}

contrib/platform/test/com/sun/jna/platform/win32/Kernel32Test.java

+21
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,27 @@ public void testWaitForSingleObject() {
120120
Kernel32.INSTANCE.CloseHandle(handle);
121121
}
122122

123+
public void testResetEvent() {
124+
HANDLE handle = Kernel32.INSTANCE.CreateEvent(null, true, false, null);
125+
126+
// set the event to the signaled state
127+
Kernel32.INSTANCE.SetEvent(handle);
128+
129+
// This should return successfully
130+
assertEquals(WinBase.WAIT_OBJECT_0, Kernel32.INSTANCE.WaitForSingleObject(
131+
handle, 1000));
132+
133+
// now reset it to not signaled
134+
Kernel32.INSTANCE.ResetEvent(handle);
135+
136+
// handle runs into timeout since it is not triggered
137+
// WAIT_TIMEOUT = 0x00000102
138+
assertEquals(WinError.WAIT_TIMEOUT, Kernel32.INSTANCE.WaitForSingleObject(
139+
handle, 1000));
140+
141+
Kernel32.INSTANCE.CloseHandle(handle);
142+
}
143+
123144
public void testWaitForMultipleObjects(){
124145
HANDLE[] handles = new HANDLE[2];
125146

0 commit comments

Comments
 (0)