changeset 149:0dea0345520e

8076629: DIO UART read_start method may return before read mutex release Reviewed-by: snazarki Contributed-by: alexey.karaksin@oracle.com
author amironov
date Fri, 03 Apr 2015 10:00:48 +0300
parents a772e993b618
children c004adba7229
files src/share/linux/native/com/oracle/dio/uart/uart.c
diffstat 1 files changed, 13 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/linux/native/com/oracle/dio/uart/uart.c	Mon Apr 06 17:38:57 2015 +0300
+++ b/src/share/linux/native/com/oracle/dio/uart/uart.c	Fri Apr 03 10:00:48 2015 +0300
@@ -120,24 +120,27 @@
         void **pContext) {
 
     int bytesAvailable;
+    javacall_dio_result res;
 
     pthread_mutex_lock( &((serial_handle)handle)->lock );
 
     if (JAVACALL_FAIL == jc_serial_read_common((serial_handle)handle, buffer, size, bytesRead, &bytesAvailable)){
         JAVACALL_REPORT_INFO(JC_SERIAL, "javacall_serial_read_start: cannot read from the internal buffer");
-        return JAVACALL_DIO_FAIL;
+        res = JAVACALL_DIO_FAIL;
+    }else{
+
+        ((uart_handle)handle)->notifiedEvents &= ~SERIAL_IN_AVAILABLE;
+        if(bytesAvailable > 0){
+        ((serial_handle)handle)->new_data_avail_cb((serial_handle)handle, bytesAvailable, JAVACALL_DIO_OK);
+        }
+        /*  read from the internal buffer complete, buffer may overrun again
+        */
+        ((uart_handle)handle)->notifiedEvents &= ~SERIAL_IN_OVERRUN;
+        res = JAVACALL_DIO_OK;
     }
-
-    ((uart_handle)handle)->notifiedEvents &= ~SERIAL_IN_AVAILABLE;
-    if(bytesAvailable > 0){
-        ((serial_handle)handle)->new_data_avail_cb((serial_handle)handle, bytesAvailable, JAVACALL_DIO_OK);
-    }
-    /*  read from the internal buffer complete, buffer may overrun again
-    */
-    ((uart_handle)handle)->notifiedEvents &= ~SERIAL_IN_OVERRUN;
     pthread_mutex_unlock( &((serial_handle)handle)->lock );
 
-    return JAVACALL_DIO_OK;
+    return res;
 }