ArnavBalyan commented on code in PR #6791:
URL: https://github.com/apache/incubator-gluten/pull/6791#discussion_r1715078692


##########
gluten-core/src/main/java/org/apache/gluten/vectorized/JniLibLoader.java:
##########
@@ -175,160 +150,80 @@ public static synchronized void unloadFromPath(String 
libPath) {
     }
   }
 
-  private static final class LoadRequest {
-    final String libName;
-    final String linkName;
-    final boolean requireUnload;
-
-    private LoadRequest(String libName, String linkName, boolean 
requireUnload) {
-      this.libName = libName;
-      this.linkName = linkName;
-      this.requireUnload = requireUnload;
+  public void mapAndLoad(String unmappedLibName, boolean requireUnload) {
+    sync.lock();
+    try {
+      final String mappedLibName = System.mapLibraryName(unmappedLibName);
+      load(mappedLibName, requireUnload);
+    } catch (Exception e) {
+      throw new GlutenException(e);
+    } finally {
+      sync.unlock();
     }
   }
 
-  private static final class LoadAction {
-    final String libName;
-    final String linkName;
-    final boolean requireUnload;
-    final File file;
-
-    private LoadAction(String libName, String linkName, boolean requireUnload, 
File file) {
-      this.libName = libName;
-      this.linkName = linkName;
-      this.requireUnload = requireUnload;
-      this.file = file;
-    }
-
-    public boolean requireLinking() {
-      return !Objects.isNull(linkName);
+  public void load(String libName, boolean requireUnload) {
+    sync.lock();
+    try {
+      if (loadedLibraries.contains(libName)) {
+        LOG.debug("Library {} has already been loaded, skipping", libName);
+        return;
+      }
+      File file = moveToWorkDir(workDir, libName);
+      loadWithLink(file.getAbsolutePath(), null, requireUnload);
+      loadedLibraries.add(libName);
+      LOG.info("Successfully loaded library {}", libName);
+    } catch (IOException e) {
+      throw new GlutenException(e);
+    } finally {
+      sync.unlock();
     }
   }
 
-  public class JniLoadTransaction {
-    private final AtomicBoolean finished = new AtomicBoolean(false);
-    private final Map<String, LoadRequest> toLoad = new LinkedHashMap<>(); // 
ordered
-
-    private JniLoadTransaction() {
-      JniLibLoader.this.sync.lock();
-    }
-
-    public JniLoadTransaction mapAndLoad(String unmappedLibName, boolean 
requireUnload) {
-      try {
-        final String mappedLibName = System.mapLibraryName(unmappedLibName);
-        load(mappedLibName, requireUnload);
-        return this;
-      } catch (Exception e) {
-        abort();
-        throw new GlutenException(e);
+  public void loadAndCreateLink(String libName, String linkName, boolean 
requireUnload) {
+    sync.lock();

Review Comment:
   That's a good catch, updated thanks



##########
gluten-core/src/main/java/org/apache/gluten/vectorized/JniLibLoader.java:
##########
@@ -72,7 +62,7 @@ public class JniLibLoader {
   private final Set<String> loadedLibraries = new HashSet<>();
   private final Lock sync = new ReentrantLock();
 
-  JniLibLoader(String workDir) {
+  public JniLibLoader(String workDir) {

Review Comment:
   Done thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to