Changeset 7857


Ignore:
Timestamp:
12/30/11 00:45:57 (8 years ago)
Author:
aivar
Message:

When the library loads tidied up logging and synchronized for multithreading.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/projects/curve-fitter/src/main/java/loci/curvefitter/SLIMCurveFitter.java

    r7841 r7857  
    5555 */ 
    5656public class SLIMCurveFitter extends AbstractCurveFitter { 
    57     private static boolean s_libraryLoaded = false; 
     57    private static Object s_synchObject = new Object(); 
     58    private static volatile boolean s_libraryLoaded = false; 
    5859    private static boolean s_libraryOnPath = false; 
    5960    private static CLibrary s_library; 
     
    185186        if (!s_libraryLoaded) { 
    186187 
    187             // look for library on path 
    188             try { 
    189                 // use JNA 
    190                 s_library = (CLibrary) Native.loadLibrary("slim-curve-1.0-SNAPSHOT", CLibrary.class); 
    191                 s_libraryLoaded = true; 
    192                 s_libraryOnPath = true; 
    193  
    194                 System.out.println("Using JNA"); 
    195             } 
    196             catch (UnsatisfiedLinkError e) { 
    197                 System.out.println("Library not on path " + e.getMessage()); 
    198             } 
    199  
    200             if (!s_libraryLoaded) { 
    201                 // look for library in jar, using JNI 
    202                 s_libraryLoaded = NativeLibraryUtil.loadNativeLibrary(this.getClass(), "slim-curve"); 
    203             } 
    204  
    205             if (!s_libraryLoaded) { 
    206                 IJ.log("Unable to do fit."); 
    207                 return 0; 
    208             } 
     188            synchronized (s_synchObject) { 
     189                // look for library on path 
     190                try { 
     191                    IJ.log("Using JNA"); 
     192                    s_library = (CLibrary) Native.loadLibrary("slim-curve-1.0-SNAPSHOT", CLibrary.class); 
     193                    s_libraryLoaded = true; 
     194                    s_libraryOnPath = true; 
     195                } 
     196                catch (UnsatisfiedLinkError e) { 
     197                    System.out.println("Library not on path " + e.getMessage()); 
     198                    IJ.log("Library not on path " + e.getMessage()); 
     199                } 
     200 
     201                if (!s_libraryLoaded) { 
     202                    // look for library in jar, using JNI 
     203                    IJ.log("Using JNI"); 
     204                    s_libraryLoaded = NativeLibraryUtil.loadNativeLibrary(this.getClass(), "slim-curve"); 
     205                } 
     206            } 
     207 
     208        } 
     209        if (!s_libraryLoaded) { 
     210            IJ.log("Unable to do fit."); 
     211            return 0; 
    209212        } 
    210213 
Note: See TracChangeset for help on using the changeset viewer.