Skip to content

Commit

Permalink
Naming change to be more applicable in FT mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jmao-denver committed Nov 6, 2024
1 parent 1c51917 commit 99f130a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/jpy/PyObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private static void startCleanupThread() {
}

public static int cleanup() {
return REFERENCES.asProxy().cleanupOnlyUseFromGIL();
return REFERENCES.asProxy().threadSafeCleanup();
}

private final PyObjectState state;
Expand All @@ -71,8 +71,8 @@ public static int cleanup() {
PyObject(long pointer, boolean fromJNI) {
state = new PyObjectState(pointer);
if (fromJNI) {
if (CLEANUP_ON_INIT && PyLib.hasGil()) {
REFERENCES.cleanupOnlyUseFromGIL(); // only performs *one* cleanup
if (CLEANUP_ON_INIT) {
REFERENCES.threadSafeCleanup(); // only performs *one* cleanup
}
if (CLEANUP_ON_THREAD) {
// ensures that we've only started after python has been started, and we know there is something to cleanup
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jpy/PyObjectCleanup.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package org.jpy;

interface PyObjectCleanup {
int cleanupOnlyUseFromGIL();
int threadSafeCleanup();
}
8 changes: 4 additions & 4 deletions src/main/java/org/jpy/PyObjectReferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ private Reference<PyObject> asRef(PyObject pyObject) {
/**
* This should *only* be invoked through the proxy, or when we *know* we have the GIL.
*/
public int cleanupOnlyUseFromGIL() {
return cleanupOnlyUseFromGIL(buffer);
public int threadSafeCleanup() {
return threadSafeCleanup(buffer);
}

private int cleanupOnlyUseFromGIL(long[] buffer) {
private int threadSafeCleanup(long[] buffer) {
return PyLib.ensureGil(() -> {
int index = 0;
while (index < buffer.length) {
Expand Down Expand Up @@ -164,7 +164,7 @@ def cleanup(references):
// any fairness guarantees. As such, we need to be mindful of other python users/code,
// and ensure we don't overly acquire the GIL causing starvation issues, especially when
// there is no cleanup work to do.
final int size = proxy.cleanupOnlyUseFromGIL();
final int size = proxy.threadSafeCleanup();


// Although, it *does* make sense to potentially take the GIL in a tight loop when there
Expand Down

0 comments on commit 99f130a

Please sign in to comment.