Reduce usage of SEM_LOCK in application library and reset pointers.
authorAlexander Wenzel <Alexander.AW.Wenzel@bmw.de>
Thu, 28 Nov 2013 06:49:56 +0000 (07:49 +0100)
committerAlexander Wenzel <Alexander.AW.Wenzel@bmw.de>
Fri, 10 Jan 2014 06:15:36 +0000 (07:15 +0100)
Signed-off-by: Alexander Wenzel <Alexander.AW.Wenzel@bmw.de>
include/dlt/dlt_user.h
include/dlt/dlt_user_macros.h
src/lib/dlt_user.c

index 1317112..d09adae 100644 (file)
@@ -161,6 +161,8 @@ typedef struct
 {
        char contextID[4];                            /**< context id */
        int32_t log_level_pos;                        /**< offset in user-application context field */
+       int8_t *log_level_ptr;                        /**< pointer to the log level */
+       int8_t *trace_status_ptr;                     /**< pointer to the trace status */
        uint8_t mcnt;                                 /**< message counter */
 } DltContext;
 
@@ -191,7 +193,9 @@ typedef struct
 {
     char contextID[DLT_ID_SIZE];      /**< Context ID */
     int8_t log_level;                 /**< Log level */
+    int8_t *log_level_ptr;             /**< Ptr to the log level */
     int8_t trace_status;              /**< Trace status */
+    int8_t *trace_status_ptr;             /**< Ptr to the trace status */
     char *context_description;        /**< description of context */
     DltUserInjectionCallback *injection_table; /**< Table with pointer to injection functions and service ids */
     uint32_t nrcallbacks;
index bd4d5fc..3b6bb06 100644 (file)
@@ -160,11 +160,14 @@ extern DltContext CONTEXT;
 #else
 #define DLT_LOG(CONTEXT,LOGLEVEL,ARGS...) \
        do { \
-               DltContextData log; \
-               if (dlt_user_log_write_start(&CONTEXT,&log,LOGLEVEL)>0) \
+               if((CONTEXT).log_level_ptr && ((LOGLEVEL)<=(int)*((CONTEXT).log_level_ptr) ) && ((LOGLEVEL)!=0)) \
                { \
-            ARGS; \
-            dlt_user_log_write_finish(&log); \
+                       DltContextData log; \
+                       if (dlt_user_log_write_start(&CONTEXT,&log,LOGLEVEL)>0) \
+                       { \
+                               ARGS; \
+                               dlt_user_log_write_finish(&log); \
+                       } \
                } \
        } while(0)
 #endif
@@ -184,11 +187,14 @@ extern DltContext CONTEXT;
 #else
 #define DLT_LOG_ID(CONTEXT,LOGLEVEL,MSGID,ARGS...) \
        do { \
-               DltContextData log; \
-               if (dlt_user_log_write_start_id(&CONTEXT,&log,LOGLEVEL,MSGID)>0) \
+               if((CONTEXT).log_level_ptr && ((LOGLEVEL)<=(int)*((CONTEXT).log_level_ptr) ) && ((LOGLEVEL)!=0)) \
                { \
-            ARGS; \
-            dlt_user_log_write_finish(&log); \
+                       DltContextData log; \
+                       if (dlt_user_log_write_start_id(&CONTEXT,&log,LOGLEVEL,MSGID)>0) \
+                       { \
+                               ARGS; \
+                               dlt_user_log_write_finish(&log); \
+                       } \
                } \
        } while(0)
 #endif
@@ -285,7 +291,10 @@ extern DltContext CONTEXT;
  */
 #define DLT_TRACE_NETWORK(CONTEXT,TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD) \
     do { \
-        dlt_user_trace_network(&(CONTEXT),TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD); \
+       if ((CONTEXT).trace_status_ptr && *((CONTEXT).trace_status_ptr)==DLT_TRACE_STATUS_ON) \
+       { \
+               dlt_user_trace_network(&(CONTEXT),TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD); \
+               } \
     }while(0)
 
 /**
@@ -299,7 +308,10 @@ extern DltContext CONTEXT;
  */
 #define DLT_TRACE_NETWORK_TRUNCATED(CONTEXT,TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD) \
     do { \
-        dlt_user_trace_network_truncated(&(CONTEXT),TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD, 1); \
+       if ((CONTEXT).trace_status_ptr && *((CONTEXT).trace_status_ptr)==DLT_TRACE_STATUS_ON) \
+       { \
+               dlt_user_trace_network_truncated(&(CONTEXT),TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD, 1); \
+               } \
     }while(0)
 
 /**
@@ -313,7 +325,10 @@ extern DltContext CONTEXT;
  */
 #define DLT_TRACE_NETWORK_SEGMENTED(CONTEXT,TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD) \
     do { \
-        dlt_user_trace_network_segmented(&(CONTEXT),TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD); \
+       if ((CONTEXT).trace_status_ptr && *((CONTEXT).trace_status_ptr)==DLT_TRACE_STATUS_ON) \
+       { \
+               dlt_user_trace_network_segmented(&(CONTEXT),TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD); \
+       } \
     }while(0)
 
 /**
@@ -324,7 +339,10 @@ extern DltContext CONTEXT;
  */
 #define DLT_LOG_STRING(CONTEXT,LOGLEVEL,TEXT) \
     do { \
-        dlt_log_string(&(CONTEXT), LOGLEVEL, TEXT); \
+               if((CONTEXT).log_level_ptr && ((LOGLEVEL)<=(int)*((CONTEXT).log_level_ptr) ) && ((LOGLEVEL)!=0)) \
+               { \
+                       dlt_log_string(&(CONTEXT), LOGLEVEL, TEXT); \
+               } \
     } while(0)
 
 /**
@@ -336,7 +354,10 @@ extern DltContext CONTEXT;
  */
 #define DLT_LOG_STRING_INT(CONTEXT,LOGLEVEL,TEXT,INT_VAR) \
        do { \
-        dlt_log_string_int(&(CONTEXT), LOGLEVEL, TEXT, INT_VAR); \
+               if((CONTEXT).log_level_ptr && ((LOGLEVEL)<=(int)*((CONTEXT).log_level_ptr) ) && ((LOGLEVEL)!=0)) \
+               { \
+                       dlt_log_string_int(&(CONTEXT), LOGLEVEL, TEXT, INT_VAR); \
+               } \
        } while(0)
 
 /**
@@ -348,7 +369,10 @@ extern DltContext CONTEXT;
  */
 #define DLT_LOG_STRING_UINT(CONTEXT,LOGLEVEL,TEXT,UINT_VAR) \
        do { \
-               dlt_log_string_uint(&(CONTEXT),LOGLEVEL,TEXT,UINT_VAR); \
+               if((CONTEXT).log_level_ptr && ((LOGLEVEL)<=(int)*((CONTEXT).log_level_ptr) ) && ((LOGLEVEL)!=0)) \
+               { \
+                       dlt_log_string_uint(&(CONTEXT),LOGLEVEL,TEXT,UINT_VAR); \
+               } \
        } while(0)
 
 /**
@@ -359,7 +383,10 @@ extern DltContext CONTEXT;
  */
 #define DLT_LOG_UINT(CONTEXT,LOGLEVEL,UINT_VAR) \
        do { \
-               dlt_log_uint(&(CONTEXT),LOGLEVEL,UINT_VAR); \
+               if((CONTEXT).log_level_ptr && ((LOGLEVEL)<=(int)*((CONTEXT).log_level_ptr) ) && ((LOGLEVEL)!=0)) \
+               { \
+                       dlt_log_uint(&(CONTEXT),LOGLEVEL,UINT_VAR); \
+               } \
        } while(0)
 
 /**
@@ -370,7 +397,10 @@ extern DltContext CONTEXT;
  */
 #define DLT_LOG_INT(CONTEXT,LOGLEVEL,INT_VAR) \
        do { \
-               dlt_log_int(&(CONTEXT),LOGLEVEL,INT_VAR); \
+               if((CONTEXT).log_level_ptr && ((LOGLEVEL)<=(int)*((CONTEXT).log_level_ptr) ) && ((LOGLEVEL)!=0)) \
+               { \
+                       dlt_log_int(&(CONTEXT),LOGLEVEL,INT_VAR); \
+               } \
        } while(0)
 
 /**
@@ -382,7 +412,10 @@ extern DltContext CONTEXT;
  */
 #define DLT_LOG_RAW(CONTEXT,LOGLEVEL,BUF,LEN) \
        do { \
-               dlt_log_raw(&(CONTEXT),LOGLEVEL,BUF,LEN); \
+               if((CONTEXT).log_level_ptr && ((LOGLEVEL)<=(int)*((CONTEXT).log_level_ptr) ) && ((LOGLEVEL)!=0)) \
+               { \
+                       dlt_log_raw(&(CONTEXT),LOGLEVEL,BUF,LEN); \
+               } \
        } while(0)
 
 /**
index 36dac77..e4368f7 100644 (file)
@@ -788,6 +788,9 @@ int dlt_register_context_ll_ts(DltContext *handle, const char *contextid, const
                 dlt_user.dlt_ll_ts[i].log_level    = DLT_USER_INITIAL_LOG_LEVEL;
                 dlt_user.dlt_ll_ts[i].trace_status = DLT_USER_INITIAL_TRACE_STATUS;
 
+                dlt_user.dlt_ll_ts[i].log_level_ptr    = 0;
+                dlt_user.dlt_ll_ts[i].trace_status_ptr = 0;
+
                 dlt_user.dlt_ll_ts[i].context_description = 0;
 
                 dlt_user.dlt_ll_ts[i].injection_table = 0;
@@ -829,6 +832,9 @@ int dlt_register_context_ll_ts(DltContext *handle, const char *contextid, const
                     dlt_user.dlt_ll_ts[i].log_level    = DLT_USER_INITIAL_LOG_LEVEL;
                     dlt_user.dlt_ll_ts[i].trace_status = DLT_USER_INITIAL_TRACE_STATUS;
 
+                    dlt_user.dlt_ll_ts[i].log_level_ptr    = 0;
+                    dlt_user.dlt_ll_ts[i].trace_status_ptr = 0;
+
                     dlt_user.dlt_ll_ts[i].context_description = 0;
 
                     dlt_user.dlt_ll_ts[i].injection_table = 0;
@@ -863,6 +869,25 @@ int dlt_register_context_ll_ts(DltContext *handle, const char *contextid, const
             dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description[desc_len]='\0';
         }
 
+        if(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr == 0)
+        {
+               dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr = malloc(sizeof(int8_t));
+               if(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr == 0)
+               {
+               DLT_SEM_FREE();
+               return -1;
+               }
+        }
+        if(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr == 0)
+        {
+               dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr = malloc(sizeof(int8_t));
+               if(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr == 0)
+               {
+               DLT_SEM_FREE();
+               return -1;
+               }
+        }
+
         if (loglevel!=DLT_USER_LOG_LEVEL_NOT_SET)
         {
             dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level = loglevel;
@@ -878,8 +903,14 @@ int dlt_register_context_ll_ts(DltContext *handle, const char *contextid, const
         dlt_set_id(handle->contextID, contextid);
         handle->log_level_pos = dlt_user.dlt_ll_ts_num_entries;
 
+        handle->log_level_ptr = dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr;
+        handle->trace_status_ptr = dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr;
+
         log.context_description = dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description;
 
+        *(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr) = dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level;
+        *(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr) = dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status = tracestatus;
+
         if (loglevel!=DLT_USER_LOG_LEVEL_NOT_SET)
         {
             log.log_level = loglevel;
@@ -960,6 +991,9 @@ int dlt_unregister_context(DltContext *handle)
 
     DLT_SEM_LOCK();
 
+    handle->log_level_ptr = 0;
+    handle->trace_status_ptr = 0;
+
     if (dlt_user.dlt_ll_ts)
     {
         /* Clear and free local stored context information */
@@ -973,6 +1007,18 @@ int dlt_unregister_context(DltContext *handle)
             free(dlt_user.dlt_ll_ts[handle->log_level_pos].context_description);
         }
 
+        if (dlt_user.dlt_ll_ts[handle->log_level_pos].log_level_ptr!=0)
+        {
+            free(dlt_user.dlt_ll_ts[handle->log_level_pos].log_level_ptr);
+            dlt_user.dlt_ll_ts[handle->log_level_pos].log_level_ptr = 0;
+        }
+
+        if (dlt_user.dlt_ll_ts[handle->log_level_pos].trace_status_ptr!=0)
+        {
+            free(dlt_user.dlt_ll_ts[handle->log_level_pos].trace_status_ptr);
+            dlt_user.dlt_ll_ts[handle->log_level_pos].trace_status_ptr = 0;
+        }
+
         dlt_user.dlt_ll_ts[handle->log_level_pos].context_description = 0;
 
         if (dlt_user.dlt_ll_ts[handle->log_level_pos].injection_table)
@@ -1031,6 +1077,10 @@ int dlt_set_application_ll_ts_limit(DltLogLevelType loglevel, DltTraceStatusType
     {
         dlt_user.dlt_ll_ts[i].log_level = loglevel;
         dlt_user.dlt_ll_ts[i].trace_status = tracestatus;
+        if(dlt_user.dlt_ll_ts[i].log_level_ptr)
+               *(dlt_user.dlt_ll_ts[i].log_level_ptr) = loglevel;
+        if(dlt_user.dlt_ll_ts[i].trace_status_ptr)
+               *(dlt_user.dlt_ll_ts[i].trace_status_ptr) = tracestatus;
     }
 
     DLT_SEM_FREE();
@@ -1196,11 +1246,8 @@ int dlt_user_log_write_start_id(DltContext *handle, DltContextData *log,DltLogLe
         return -1;
     }
 
-    DLT_SEM_LOCK();
-
-    if ((loglevel<=(int)(dlt_user.dlt_ll_ts[handle->log_level_pos].log_level) ) && (loglevel!=0))
+    if (handle->log_level_ptr && (loglevel<=(int)*(handle->log_level_ptr) ) && (loglevel!=0))
     {
-        DLT_SEM_FREE();
                log->args_num = 0;
        log->log_level = loglevel;
 
@@ -1221,11 +1268,6 @@ int dlt_user_log_write_start_id(DltContext *handle, DltContextData *log,DltLogLe
         else log->size=0;
         return 1;
     }
-    else
-    {
-        DLT_SEM_FREE();
-        return 0;
-    }
 
     return -1;
 }
@@ -1973,17 +2015,14 @@ int dlt_user_trace_network_segmented_start(uint16_t *id, DltContext *handle, Dlt
                return -1;
     }
 
-    DLT_SEM_LOCK();
 
     if (dlt_user.dlt_ll_ts==0)
     {
-        DLT_SEM_FREE();
         return -1;
     }
 
-    if (dlt_user.dlt_ll_ts[handle->log_level_pos].trace_status==DLT_TRACE_STATUS_ON)
+    if (handle->trace_status_ptr && *(handle->trace_status_ptr)==DLT_TRACE_STATUS_ON)
     {
-        DLT_SEM_FREE();
 
         log.args_num = 0;
         log.trace_status = nw_trace_type;
@@ -2039,10 +2078,6 @@ int dlt_user_trace_network_segmented_start(uint16_t *id, DltContext *handle, Dlt
         /* Send log */
         return dlt_user_log_send_log(&log, DLT_TYPE_NW_TRACE);
     }
-    else
-    {
-        DLT_SEM_FREE();
-    }
     return 0;
 }
 
@@ -2066,17 +2101,13 @@ int dlt_user_trace_network_segmented_segment(uint16_t id, DltContext *handle, Dl
                return -1;
     }
 
-    DLT_SEM_LOCK();
-
     if (dlt_user.dlt_ll_ts==0)
     {
-        DLT_SEM_FREE();
         return -1;
     }
 
-    if (dlt_user.dlt_ll_ts[handle->log_level_pos].trace_status==DLT_TRACE_STATUS_ON)
+    if (handle->trace_status_ptr && *(handle->trace_status_ptr)==DLT_TRACE_STATUS_ON)
     {
-        DLT_SEM_FREE();
 
         log.args_num = 0;
         log.trace_status = nw_trace_type;
@@ -2109,10 +2140,6 @@ int dlt_user_trace_network_segmented_segment(uint16_t id, DltContext *handle, Dl
         /* Send log */
         return dlt_user_log_send_log(&log, DLT_TYPE_NW_TRACE);
     }
-    else
-    {
-        DLT_SEM_FREE();
-    }
 
     /* Allow other threads to log between chunks */
        pthread_yield();
@@ -2135,17 +2162,13 @@ int dlt_user_trace_network_segmented_end(uint16_t id, DltContext *handle, DltNet
 
 
 
-    DLT_SEM_LOCK();
-
     if (dlt_user.dlt_ll_ts==0)
     {
-        DLT_SEM_FREE();
         return -1;
     }
 
-    if (dlt_user.dlt_ll_ts[handle->log_level_pos].trace_status==DLT_TRACE_STATUS_ON)
+    if (handle->trace_status_ptr && *(handle->trace_status_ptr)==DLT_TRACE_STATUS_ON)
     {
-        DLT_SEM_FREE();
 
         log.args_num = 0;
         log.trace_status = nw_trace_type;
@@ -2166,10 +2189,6 @@ int dlt_user_trace_network_segmented_end(uint16_t id, DltContext *handle, DltNet
         /* Send log */
         return dlt_user_log_send_log(&log, DLT_TYPE_NW_TRACE);
     }
-    else
-    {
-        DLT_SEM_FREE();
-    }
     return 0;
 }
 
@@ -2389,17 +2408,13 @@ int dlt_user_trace_network_truncated(DltContext *handle, DltNetworkTraceType nw_
 
     */
 
-    DLT_SEM_LOCK();
-
     if (dlt_user.dlt_ll_ts==0)
     {
-        DLT_SEM_FREE();
         return -1;
     }
 
-    if (dlt_user.dlt_ll_ts[handle->log_level_pos].trace_status==DLT_TRACE_STATUS_ON)
+    if (handle->trace_status_ptr && *(handle->trace_status_ptr)==DLT_TRACE_STATUS_ON)
     {
-        DLT_SEM_FREE();
 
         log.args_num = 0;
         log.trace_status = nw_trace_type;
@@ -2467,10 +2482,6 @@ int dlt_user_trace_network_truncated(DltContext *handle, DltNetworkTraceType nw_
         /* Send log */
         return dlt_user_log_send_log(&log, DLT_TYPE_NW_TRACE);
     }
-    else
-    {
-        DLT_SEM_FREE();
-    }
 
     return 0;
 }
@@ -3526,6 +3537,10 @@ int dlt_user_log_check_user_message(void)
                             {
                                 dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level = usercontextll->log_level;
                                 dlt_user.dlt_ll_ts[usercontextll->log_level_pos].trace_status = usercontextll->trace_status;
+                                if(dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level_ptr)
+                                       *(dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level_ptr) = usercontextll->log_level;
+                                if(dlt_user.dlt_ll_ts[usercontextll->log_level_pos].trace_status_ptr)
+                                       *(dlt_user.dlt_ll_ts[usercontextll->log_level_pos].trace_status_ptr) = usercontextll->trace_status;
                             }
                         }