forked from kohsuke/com4j
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWin32Lock.java
More file actions
61 lines (54 loc) · 1.37 KB
/
Win32Lock.java
File metadata and controls
61 lines (54 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com4j;
/**
* Represents a Win32 Event lock.
*
* <p>
* We can't use Java synchronization for {@link ComThreadMulti},
* as it blocks incoming method dispatching requests.
* We need to use this instead.
*
* @author Kohsuke Kawaguchi
* @author Michael Schnell (ScM, (C) 2009, Michael-Schnell@gmx.de)
*/
final class Win32Lock {
private final long eventHandle;
/**
* Constructs a new native win32 lock object.
*/
Win32Lock() {
eventHandle = createEvent();
}
/**
* Signals the event.
*/
void activate() {
activate0(eventHandle);
}
/**
* Blocks until the event is signaled.
*
* This runs Windows message loop.
*/
void suspend() {
suspend0(eventHandle);
}
/**
* Blocks until the event is signaled or the timeout is reached.
*
* This runs Windows message loop.
*/
void suspend(int timeoutMillis){
suspend1(eventHandle, timeoutMillis);
}
/**
* Closes the allocated resource.
*/
void dispose() {
closeHandle(eventHandle);
}
private static native void closeHandle(long eventHandle);
private static native int createEvent();
private static native void activate0(long handle);
private static native void suspend0(long handle);
private static native void suspend1(long handle, int timeoutMillis);
}