From 99f130aec3ac16f230aa42df5d2c599ec43f5cb1 Mon Sep 17 00:00:00 2001 From: jianfengmao Date: Wed, 6 Nov 2024 09:30:49 -0500 Subject: [PATCH] Naming change to be more applicable in FT mode --- src/main/java/org/jpy/PyObject.java | 6 +++--- src/main/java/org/jpy/PyObjectCleanup.java | 2 +- src/main/java/org/jpy/PyObjectReferences.java | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/jpy/PyObject.java b/src/main/java/org/jpy/PyObject.java index e0715ec7..44f07409 100644 --- a/src/main/java/org/jpy/PyObject.java +++ b/src/main/java/org/jpy/PyObject.java @@ -58,7 +58,7 @@ private static void startCleanupThread() { } public static int cleanup() { - return REFERENCES.asProxy().cleanupOnlyUseFromGIL(); + return REFERENCES.asProxy().threadSafeCleanup(); } private final PyObjectState state; @@ -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 diff --git a/src/main/java/org/jpy/PyObjectCleanup.java b/src/main/java/org/jpy/PyObjectCleanup.java index cda84557..7285e3a2 100644 --- a/src/main/java/org/jpy/PyObjectCleanup.java +++ b/src/main/java/org/jpy/PyObjectCleanup.java @@ -1,5 +1,5 @@ package org.jpy; interface PyObjectCleanup { - int cleanupOnlyUseFromGIL(); + int threadSafeCleanup(); } diff --git a/src/main/java/org/jpy/PyObjectReferences.java b/src/main/java/org/jpy/PyObjectReferences.java index 9eec1903..4afea8a0 100644 --- a/src/main/java/org/jpy/PyObjectReferences.java +++ b/src/main/java/org/jpy/PyObjectReferences.java @@ -76,11 +76,11 @@ private Reference 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) { @@ -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