@@ -229,7 +229,6 @@ static DltReturnValue dlt_unregister_app_util(bool force_sending_messages);
229
229
static DltReturnValue dlt_user_output_internal_msg (DltLogLevelType loglevel , const char * text , void * params );
230
230
DltTraceLoadSettings * trace_load_settings = NULL ;
231
231
uint32_t trace_load_settings_count = 0 ;
232
- pthread_rwlock_t trace_load_rw_lock = PTHREAD_RWLOCK_INITIALIZER ;
233
232
#endif
234
233
235
234
DltReturnValue dlt_user_check_library_version (const char * user_major_version , const char * user_minor_version )
@@ -513,8 +512,8 @@ DltReturnValue dlt_init(void)
513
512
514
513
#endif
515
514
#ifdef DLT_TRACE_LOAD_CTRL_ENABLE
516
- pthread_rwlock_wrlock (& trace_load_rw_lock );
517
515
516
+ DLT_SEM_LOCK ();
518
517
trace_load_settings = malloc (sizeof (DltTraceLoadSettings ));
519
518
if (trace_load_settings == NULL ) {
520
519
dlt_vlog (LOG_ERR , "Failed to allocate memory for trace load settings\n" );
@@ -526,8 +525,7 @@ DltReturnValue dlt_init(void)
526
525
trace_load_settings [0 ].hard_limit = DLT_TRACE_LOAD_CLIENT_HARD_LIMIT_DEFAULT ;
527
526
strncpy (trace_load_settings [0 ].apid , dlt_user .appID , DLT_ID_SIZE );
528
527
trace_load_settings_count = 1 ;
529
-
530
- pthread_rwlock_unlock (& trace_load_rw_lock );
528
+ DLT_SEM_FREE ();
531
529
532
530
#endif
533
531
#ifdef DLT_LIB_USE_UNIX_SOCKET_IPC
@@ -958,10 +956,6 @@ void dlt_user_atexit_handler(void)
958
956
/* Cleanup */
959
957
/* Ignore return value */
960
958
dlt_free ();
961
-
962
- #ifdef DLT_TRACE_LOAD_CTRL_ENABLE
963
- pthread_rwlock_destroy (& trace_load_rw_lock );
964
- #endif
965
959
}
966
960
967
961
int dlt_user_atexit_blow_out_user_buffer (void )
@@ -1543,8 +1537,20 @@ DltReturnValue dlt_register_context_ll_ts_llccb(DltContext *handle,
1543
1537
1544
1538
dlt_user .dlt_ll_ts_num_entries ++ ;
1545
1539
1546
- DLT_SEM_FREE ();
1540
+ #ifdef DLT_TRACE_LOAD_CTRL_ENABLE
1541
+ DltTraceLoadSettings * settings = dlt_find_runtime_trace_load_settings (
1542
+ trace_load_settings ,
1543
+ trace_load_settings_count ,
1544
+ dlt_user .appID ,
1545
+ ctx_entry -> contextID );
1546
+ if (settings == NULL ) {
1547
+ dlt_vlog (LOG_WARNING , "No trace load settings found for %s.%s\n" , dlt_user .appID , log .handle -> contextID );
1548
+ } else {
1549
+ ctx_entry -> trace_load_settings = settings ;
1550
+ }
1547
1551
1552
+ #endif
1553
+ DLT_SEM_FREE ();
1548
1554
return dlt_user_log_send_register_context (& log );
1549
1555
}
1550
1556
@@ -4169,19 +4175,16 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, const int mtype, int *
4169
4175
/* check trace load before output */
4170
4176
if (!sent_size )
4171
4177
{
4172
- pthread_rwlock_wrlock (& trace_load_rw_lock );
4173
- DltTraceLoadSettings * settings =
4174
- dlt_find_runtime_trace_load_settings (
4175
- trace_load_settings , trace_load_settings_count , dlt_user .appID , log -> handle -> contextID );
4178
+ DLT_SEM_LOCK ();
4176
4179
const bool trace_load_in_limits = dlt_check_trace_load (
4177
- settings ,
4180
+ dlt_user . dlt_ll_ts [ log -> handle -> log_level_pos ]. trace_load_settings ,
4178
4181
log -> log_level , time_stamp ,
4179
4182
sizeof (DltUserHeader )
4180
4183
+ msg .headersize - sizeof (DltStorageHeader )
4181
4184
+ log -> size ,
4182
4185
dlt_user_output_internal_msg ,
4183
4186
NULL );
4184
- pthread_rwlock_unlock ( & trace_load_rw_lock );
4187
+ DLT_SEM_FREE ( );
4185
4188
if (!trace_load_in_limits ){
4186
4189
return DLT_RETURN_LOAD_EXCEEDED ;
4187
4190
}
@@ -4403,7 +4406,6 @@ DltReturnValue dlt_user_log_send_register_context(DltContextData *log)
4403
4406
usercontext .description_length );
4404
4407
4405
4408
return DLT_RETURN_OK ;
4406
-
4407
4409
}
4408
4410
4409
4411
DltReturnValue dlt_user_log_send_unregister_context (DltContextData * log )
@@ -4882,18 +4884,16 @@ DltReturnValue dlt_user_log_check_user_message(void)
4882
4884
trace_load_settings_user_messages =
4883
4885
(DltUserControlMsgTraceSettingMsg * )(receiver -> buf + sizeof (DltUserHeader ) + sizeof (uint32_t ));
4884
4886
4885
- pthread_rwlock_wrlock ( & trace_load_rw_lock );
4887
+ DLT_SEM_LOCK ( );
4886
4888
4887
4889
// Remove the default created at startup
4888
4890
if (trace_load_settings != NULL ) {
4889
4891
free (trace_load_settings );
4890
4892
}
4891
4893
4892
- char msg [255 ];
4893
4894
trace_load_settings_alloc_size = sizeof (DltTraceLoadSettings ) * trace_load_settings_user_messages_count ;
4894
4895
trace_load_settings = malloc (trace_load_settings_alloc_size );
4895
4896
if (trace_load_settings == NULL ) {
4896
- pthread_rwlock_unlock (& trace_load_rw_lock );
4897
4897
dlt_log (LOG_ERR , "Failed to allocate memory for trace load settings\n" );
4898
4898
return DLT_RETURN_ERROR ;
4899
4899
}
@@ -4904,29 +4904,33 @@ DltReturnValue dlt_user_log_check_user_message(void)
4904
4904
trace_load_settings [i ].soft_limit = trace_load_settings_user_messages [i ].soft_limit ;
4905
4905
trace_load_settings [i ].hard_limit = trace_load_settings_user_messages [i ].hard_limit ;
4906
4906
}
4907
+
4907
4908
trace_load_settings_count = trace_load_settings_user_messages_count ;
4908
- pthread_rwlock_unlock (& trace_load_rw_lock );
4909
+ for (i = 0 ; i < dlt_user .dlt_ll_ts_num_entries ; ++ i ) {
4910
+ dlt_ll_ts_type * ctx_entry = & dlt_user .dlt_ll_ts [i ];
4911
+ ctx_entry -> trace_load_settings = dlt_find_runtime_trace_load_settings (
4912
+ trace_load_settings , trace_load_settings_count , dlt_user .appID , ctx_entry -> contextID );
4913
+ }
4914
+ DLT_SEM_FREE ();
4909
4915
4910
- // must be sent with unlocked trace_load_rw_lock
4911
- for (i = 0 ; i < trace_load_settings_user_messages_count ; i ++ ) {
4912
- if (trace_load_settings [i ].ctid [0 ] == '\0' ) {
4913
- snprintf (
4914
- msg , sizeof (msg ),
4915
- "Received trace load settings: apid=%.4s, soft_limit=%u, hard_limit=%u\n" ,
4916
- trace_load_settings [i ].apid ,
4917
- trace_load_settings [i ].soft_limit ,
4918
- trace_load_settings [i ].hard_limit );
4919
- } else {
4920
- snprintf (
4921
- msg , sizeof (msg ),
4922
- "Received trace load settings: apid=%.4s, ctid=%.4s, soft_limit=%u, hard_limit=%u\n" ,
4923
- trace_load_settings [i ].apid ,
4924
- trace_load_settings [i ].ctid ,
4925
- trace_load_settings [i ].soft_limit ,
4926
- trace_load_settings [i ].hard_limit );
4927
- }
4928
- dlt_user_output_internal_msg (DLT_LOG_INFO , msg , NULL );
4916
+ // The log messages only can be produced safely when
4917
+ // the trace load settings are set up fully.
4918
+ char msg [255 ];
4919
+ if (trace_load_settings [i ].ctid [0 ] == '\0' ) {
4920
+ snprintf (msg , sizeof (msg ), "Received trace load settings: apid=%.4s, soft_limit=%u, hard_limit=%u\n" ,
4921
+ trace_load_settings [i ].apid ,
4922
+ trace_load_settings [i ].soft_limit ,
4923
+ trace_load_settings [i ].hard_limit );
4924
+ } else {
4925
+ snprintf (
4926
+ msg , sizeof (msg ),
4927
+ "Received trace load settings: apid=%.4s, ctid=%.4s, soft_limit=%u, hard_limit=%u\n" ,
4928
+ trace_load_settings [i ].apid ,
4929
+ trace_load_settings [i ].ctid ,
4930
+ trace_load_settings [i ].soft_limit ,
4931
+ trace_load_settings [i ].hard_limit );
4929
4932
}
4933
+ dlt_user_output_internal_msg (DLT_LOG_INFO , msg , NULL );
4930
4934
4931
4935
/* keep not read data in buffer */
4932
4936
if (dlt_receiver_remove (receiver , trace_load_settings_user_message_bytes_required )
@@ -5349,9 +5353,6 @@ static void dlt_fork_child_fork_handler()
5349
5353
g_dlt_is_child = 1 ;
5350
5354
dlt_user_init_state = INIT_UNITIALIZED ;
5351
5355
dlt_user .dlt_log_handle = -1 ;
5352
- #ifdef DLT_TRACE_LOAD_CTRL_ENABLE
5353
- pthread_rwlock_unlock (& trace_load_rw_lock );
5354
- #endif
5355
5356
}
5356
5357
5357
5358
0 commit comments