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

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

本文整理了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

  1. protected boolean connect() {
  2. try {
  3. if (sysLibrary == null) {
  4. logger.debug("Loading native code library...");
  5. sysLibrary = (LibK8055) Native
  6. .synchronizedLibrary((Library) Native.loadLibrary(
  7. "k8055", LibK8055.class));
  8. logger.debug("Done loading native code library");
  9. }
  10. if (!connected) {
  11. if (sysLibrary.OpenDevice(boardNo) == boardNo) {
  12. connected = true;
  13. // We don't really know the existing state - so this results
  14. // in the state of all inputs being republished
  15. lastDigitalInputs = -1;
  16. logger.info("K8055: Connect to board: " + boardNo
  17. + " succeeeded.");
  18. } else {
  19. logger.error("K8055: Connect to board: " + boardNo
  20. + " failed.");
  21. }
  22. }
  23. ;
  24. } catch (Exception e) {
  25. logger.error(
  26. "Failed to load K8055 native library. Please check the libk8055 and jna native libraries are in the Java library path. ",
  27. e);
  28. }
  29. return connected;
  30. }

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

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

相关文章

Native类方法