|
41 | 41 | package com.oracle.graal.python.builtins.objects.thread;
|
42 | 42 |
|
43 | 43 | import static com.oracle.graal.python.builtins.objects.thread.AbstractPythonLock.DEFAULT_BLOCKING;
|
44 |
| -import static com.oracle.graal.python.builtins.objects.thread.AbstractPythonLock.DEFAULT_TIMEOUT; |
| 44 | +import static com.oracle.graal.python.builtins.objects.thread.AbstractPythonLock.UNSET_TIMEOUT; |
45 | 45 | import static com.oracle.graal.python.builtins.objects.thread.AbstractPythonLock.TIMEOUT_MAX;
|
46 | 46 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__ENTER__;
|
47 | 47 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__EXIT__;
|
@@ -109,26 +109,28 @@ private CastToBooleanNode getCastToBooleanNode() {
|
109 | 109 | boolean doAcquire(VirtualFrame frame, AbstractPythonLock self, Object blocking, Object timeout) {
|
110 | 110 | // args setup
|
111 | 111 | boolean isBlocking = (blocking instanceof PNone) ? DEFAULT_BLOCKING : getCastToBooleanNode().executeBoolean(frame, blocking);
|
112 |
| - double timeoutSeconds = DEFAULT_TIMEOUT; |
| 112 | + double timeoutSeconds = UNSET_TIMEOUT; |
113 | 113 | if (!(timeout instanceof PNone)) {
|
114 |
| - if (!isBlocking) { |
115 |
| - throw raise(ValueError, "can't specify a timeout for a non-blocking call"); |
116 |
| - } |
117 |
| - |
118 | 114 | timeoutSeconds = getCastToDoubleNode().execute(frame, timeout);
|
119 | 115 |
|
120 |
| - if (timeoutSeconds < 0) { |
121 |
| - throw raise(ValueError, "timeout value must be positive"); |
122 |
| - } else if (timeoutSeconds > TIMEOUT_MAX) { |
123 |
| - throw raise(OverflowError, "timeout value is too large"); |
| 116 | + if (timeoutSeconds != UNSET_TIMEOUT) { |
| 117 | + if (!isBlocking) { |
| 118 | + throw raise(ValueError, "can't specify a timeout for a non-blocking call"); |
| 119 | + } |
| 120 | + |
| 121 | + if (timeoutSeconds < 0) { |
| 122 | + throw raise(ValueError, "timeout value must be positive"); |
| 123 | + } else if (timeoutSeconds > TIMEOUT_MAX) { |
| 124 | + throw raise(OverflowError, "timeout value is too large"); |
| 125 | + } |
124 | 126 | }
|
125 | 127 | }
|
126 | 128 |
|
127 | 129 | // acquire lock
|
128 | 130 | if (isBlockingProfile.profile(!isBlocking)) {
|
129 | 131 | return self.acquireNonBlocking();
|
130 | 132 | } else {
|
131 |
| - if (defaultTimeoutProfile.profile(timeoutSeconds == DEFAULT_TIMEOUT)) { |
| 133 | + if (defaultTimeoutProfile.profile(timeoutSeconds == UNSET_TIMEOUT)) { |
132 | 134 | return self.acquireBlocking();
|
133 | 135 | } else {
|
134 | 136 | return self.acquireTimeout(timeoutSeconds);
|
|
0 commit comments