-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathPySemLock.java
More file actions
69 lines (59 loc) · 1.94 KB
/
Copy pathPySemLock.java
File metadata and controls
69 lines (59 loc) · 1.94 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
62
63
64
65
66
67
68
69
package org.python.modules._multiprocessing;
import org.python.core.ArgParser;
import org.python.core.BuiltinDocs;
import org.python.core.Py;
import org.python.core.PyNewWrapper;
import org.python.core.PyObject;
import org.python.core.PyStringMap;
import org.python.core.PyType;
import org.python.core.Untraversable;
import org.python.expose.ExposedGet;
import org.python.expose.ExposedMethod;
import org.python.expose.ExposedNew;
import org.python.expose.ExposedType;
import java.util.concurrent.Semaphore;
/**
* Created by isaiah on 6/16/16.
*/
@Untraversable
@ExposedType(name = "_multiprocessing.SemLock", base = PyObject.class)
public class PySemLock extends PyObject {
public static int SEM_VALUE_MAX = Integer.MAX_VALUE;
public static PyType TYPE = PyType.fromClass(PySemLock.class);
private Semaphore semaphore;
private int kind;
private int value;
private int maxvalue;
private String name;
private boolean unlink;
public PySemLock(int value) {
super(TYPE);
semaphore = new Semaphore(value);
}
@ExposedGet
protected PyStringMap __dict__ = new PyStringMap();
@Override
public PyStringMap fastGetDict() {
return __dict__;
}
@ExposedNew
final static PyObject SemLock___new__(PyNewWrapper new_, boolean init, PyType subtype,
PyObject[] args, String[] keywords) {
ArgParser ap = new ArgParser("SemLock", args, keywords, "kind", "value", "maxvalue", "name", "unlink");
return new PySemLock(SEM_VALUE_MAX);
}
@ExposedMethod(doc = BuiltinDocs.SemLock_acquire_doc)
final PyObject SemLock_acquire() {
try {
semaphore.acquire();
} catch (InterruptedException e) {
return Py.False;
}
return Py.True;
}
@ExposedMethod(doc = BuiltinDocs.SemLock_release_doc)
final PyObject SemLock_release() {
semaphore.release();
return Py.None;
}
}