RIL: Added log locks
authorPaul Kocialkowski <contact@paulk.fr>
Wed, 25 Jul 2012 22:44:22 +0000 (00:44 +0200)
committerPaul Kocialkowski <contact@paulk.fr>
Wed, 25 Jul 2012 22:44:22 +0000 (00:44 +0200)
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
at.c
device.c
hayes-ril.h
utils.c

diff --git a/at.c b/at.c
index f189474..3b77b63 100644 (file)
--- a/at.c
+++ b/at.c
@@ -921,8 +921,10 @@ int at_request_send(struct at_request *request)
        memcpy(string + offset_separator_end, separator, length_separator_end);
 
        // Log request
-       ril_send_log(request);
+       RIL_LOG_LOCK();
        ril_data_log(string, length);
+       ril_send_log(request);
+       RIL_LOG_UNLOCK();
 
        ril_device_send(ril_device, string, length);
 
index 74b5707..0723e87 100644 (file)
--- a/device.c
+++ b/device.c
@@ -398,10 +398,17 @@ int ril_device_recv_loop(struct ril_device *ril_device_p)
 
                        responses_count = at_responses_process(&responses, data, length);
 
+                       // Log response
+                       RIL_LOG_LOCK();
+                       ril_data_log(data, length);
+                       RIL_LOG_UNLOCK();
+
                        // Good way to give the recv loop some sleep: call at_send_expect_status
                        for(j=0 ; j < responses_count ; j++) {
                                // Log response
+                               RIL_LOG_LOCK();
                                ril_recv_log(responses[j]);
+                               RIL_LOG_UNLOCK();
 
                                rc = at_response_expect_status(responses[j]);
                                if(rc < 0) {
@@ -413,9 +420,6 @@ int ril_device_recv_loop(struct ril_device *ril_device_p)
                                }
                        }
 
-                       // Log response
-                       ril_data_log(data, length);
-
                        free(data);
                }
 
index 04b99d2..b4fbd3d 100644 (file)
@@ -27,6 +27,8 @@
 
 #define RIL_DEVICE_LOCK(ril_device_p) pthread_mutex_lock(&(ril_device_p->handlers->transport->mutex));
 #define RIL_DEVICE_UNLOCK(ril_device_p) pthread_mutex_unlock(&(ril_device_p->handlers->transport->mutex));
+#define RIL_LOG_LOCK() pthread_mutex_lock(&(ril_globals.log_mutex));
+#define RIL_LOG_UNLOCK() pthread_mutex_unlock(&(ril_globals.log_mutex));
 
 #define DEV_GSM                RIL_DEVICE_TYPE_GSM
 #define DEV_CDMA       RIL_DEVICE_TYPE_CDMA
@@ -87,6 +89,7 @@ struct ril_device {
 };
 
 extern struct ril_device *ril_device;
+extern struct ril_globals ril_globals;
 
 // RIL
 struct ril_dispatch_unsol {
@@ -99,6 +102,9 @@ struct ril_globals {
        pthread_t dispatch_thread;
        struct ril_dispatch_unsol *dispatch_unsol;
        int dispatch_unsol_count;
+
+       // Log
+       pthread_mutex_t log_mutex;
 };
 
 /*
diff --git a/utils.c b/utils.c
index 1cfbb61..c817d82 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -85,7 +85,6 @@ void ril_recv_log(struct at_response *response)
        if(data_string)
                free(data_string);
 
-       LOGD("\n");
        LOGD("%s", string);
        free(string);
 }
@@ -104,7 +103,6 @@ void ril_send_log(struct at_request *request)
        else
                asprintf(&string, "%s: AT SEND [\"%s\"]", ril_device->tag, request->command);
 
-       LOGD("\n");
        LOGD("%s", string);
        free(string);
 }
@@ -165,6 +163,7 @@ void hex_dump(void *data, int size)
 
 void ril_data_log(char *data, int length)
 {
+       LOGD("\n");
        LOGD("%s: ==== DATA DUMP: %d BYTES ====", ril_device->tag, length);
        hex_dump(data, length);
 }