com.sun.jna.Native.synchronizedLibrary()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(2.2k)|赞(0)|评价(0)|浏览(359)

本文整理了Java中com.sun.jna.Native.synchronizedLibrary()方法的一些代码示例,展示了Native.synchronizedLibrary()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Native.synchronizedLibrary()方法的具体详情如下:
包路径:com.sun.jna.Native
类名称:Native
方法名:synchronizedLibrary

Native.synchronizedLibrary介绍

[英]Returns a synchronized (thread-safe) library backed by the specified library. This wrapping will prevent simultaneous invocations of any functions mapped to a given NativeLibrary. Note that the native library may still be sensitive to being called from different threads.
[中]返回指定库支持的同步(线程安全)库。这种包装将防止同时调用映射到给定NativeLibrary的任何函数。请注意,本机库可能仍然对从不同线程调用敏感。

代码示例

代码示例来源:origin: org.openhab.binding/org.openhab.binding.k8055

protected boolean connect() {
  try {
    if (sysLibrary == null) {
      logger.debug("Loading native code library...");
      sysLibrary = (LibK8055) Native
          .synchronizedLibrary((Library) Native.loadLibrary(
              "k8055", LibK8055.class));
      logger.debug("Done loading native code library");
    }
    if (!connected) {
      if (sysLibrary.OpenDevice(boardNo) == boardNo) {
        connected = true;
        // We don't really know the existing state - so this results
        // in the state of all inputs being republished
        lastDigitalInputs = -1;
        logger.info("K8055: Connect to board: " + boardNo
            + " succeeeded.");
      } else {
        logger.error("K8055: Connect to board: " + boardNo
            + " failed.");
      }
    }
    ;
  } catch (Exception e) {
    logger.error(
        "Failed to load K8055 native library.  Please check the libk8055 and jna native libraries are in the Java library path. ",
        e);
  }
  return connected;
}

代码示例来源:origin: uk.co.caprica/vlcj

/**
 * Run native discovery, if set, and attempt to load the native library.
 *
 * @param discovery native discovery used to find the native library, may be <code>null</code>
 * @return native library
 */
private LibVlc discoverNativeLibrary(NativeDiscovery discovery) {
  if (discovery != null) {
    // The discover method return value is not currently used, since we try and load the native library whether
    // discovery worked or not
    discovery.discover();
  }
  LibVlc nativeLibrary = Native.load(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
  checkVersion(nativeLibrary);
  // A synchronised library is required since there are multiple asynchronous task queues in use that could
  // potentially call into LibVLC concurrently
  return (LibVlc) Native.synchronizedLibrary(nativeLibrary);
}

相关文章

微信公众号

最新文章

更多

Native类方法