changeset 260:1b3d9720d724

DIO-26: [i2c] heavy device io can hang Contributed-by: Craig White <cwhite102@gmail.com>
author snazarki
date Tue, 19 Jun 2018 19:15:30 +0300
parents ff88da88dd88
children e9febb974bec
files Makefile src/se/native/com/oracle/dio/dio_common.cpp
diffstat 2 files changed, 23 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Wed Sep 27 14:48:10 2017 +0300
+++ b/Makefile	Tue Jun 19 19:15:30 2018 +0300
@@ -40,8 +40,8 @@
 
 ###########################################################
 # check for required env vars
-ifeq ($(PI_TOOLS),)
-  $(error "PI_TOOLS is not defined. Please set PI_TOOLS to point to the location of the raspberry pi GNU toolchain")
+ifeq ($(CROSS_TOOL),)
+  $(error "CROSS_TOOL is not defined. Please set CROSS_TOOL to point to the location of the raspberry pi GNU toolchain")
 endif
 
 ifeq ($(JAVA_HOME),)
@@ -165,15 +165,15 @@
 
 #######################################################################################################
 # tool and flag setup for arm (rasp pi) build
-TARGET_TOOLCHAIN := $(PI_TOOLS)
-TARGET_CC := $(TARGET_TOOLCHAIN)/bin/gcc
-TARGET_CXX := $(TARGET_TOOLCHAIN)/bin/g++
-TARGET_LD := $(TARGET_TOOLCHAIN)/bin/gcc
+TARGET_TOOLCHAIN := $(CROSS_TOOL)
+TARGET_CC := $(TARGET_TOOLCHAIN)gcc
+TARGET_CXX := $(TARGET_TOOLCHAIN)g++
+TARGET_LD := $(TARGET_TOOLCHAIN)gcc
 JAVAC := $(JAVA_HOME)/bin/javac
 JAR := $(JAVA_HOME)/bin/jar
 MKDIR := mkdir -p
 TARGET_C_FLAGS = $(USER_C_FLAGS) -fPIC -Wno-psabi -DJAVACALL_REPORT_LEVEL=0 -DENABLE_DEVICEACCESS -c -MMD -MF $(NATIVE_OUT_DIR)/$(@).d
-TARGET_INCLUDES = $(foreach d,$(DIO_INCLUDE_DIRS),-I$(d)) -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
+TARGET_INCLUDES = $(foreach d,$(DIO_INCLUDE_DIRS),-I$(d)) -I$(JAVA_TARGET_HOME)/include -I$(JAVA_TARGET_HOME)/include/linux
 TARGET_CXX_FLAGS = $(USER_CXX_FLAGS) -fPIC -Wno-psabi -DJAVACALL_REPORT_LEVEL=4 -DENABLE_DEVICEACCESS -c
 TARGET_LD_FLAGS= $(USER_LD_FLAGS) -Xlinker -z -Xlinker defs -Xlinker -O1 \
           -shared \
--- a/src/se/native/com/oracle/dio/dio_common.cpp	Wed Sep 27 14:48:10 2017 +0300
+++ b/src/se/native/com/oracle/dio/dio_common.cpp	Tue Jun 19 19:15:30 2018 +0300
@@ -278,9 +278,18 @@
         sig = createSignal(signalType, signalTarget);
         if (sig != NULL) {
             javautil_list_add(signals, sig);
-
+            // Need to lock the mutex associated with the condition
+            // otherwise we could miss the signal
+            // This is done while holding the 'master' signalMutex
+            javacall_os_mutex_lock(javacall_os_cond_get_mutex(sig->condition));
+            // Now release the master lock
             javacall_os_mutex_unlock(signalMutex);
+            // Wait on the condition (releases the condition mutex while waiting)
             javacall_os_cond_wait(sig->condition, timeout);
+            // Technically, this should be in a loop for spurious wakes, but
+            // I'm not familiar enough with the code for what the loop would check
+            // Unlock the condition mutex
+            javacall_os_mutex_unlock(javacall_os_cond_get_mutex(sig->condition));
         }
     } else {
         javacall_os_mutex_unlock(signalMutex);
@@ -313,7 +322,13 @@
     signal* sig = findTarget(signalType, signalTarget);
     if (sig != NULL) {
         sig->parameter = signalParameter;
+        // Need to lock the mutex associated with the condition
+        // or waitForSignal could miss the signal
+        javacall_os_mutex_lock( javacall_os_cond_get_mutex(sig->condition));
+
         javacall_os_cond_signal(sig->condition);
+
+        javacall_os_mutex_unlock(javacall_os_cond_get_mutex(sig->condition));
     } else {
         // signal is being sent before wait started
         // create the signal and add it to the list