Skip to content

Commit

Permalink
trace-load: protect settings with rwlock
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Mohr <[email protected]>
  • Loading branch information
alexmohr committed Sep 12, 2024
1 parent 6aaae63 commit 7906ffc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/daemon/dlt-daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -3978,9 +3978,11 @@ bool trace_load_keep_message(DltDaemonApplication *app,
app->apid, msg->extendedheader->ctid);

if (trace_load_settings != NULL) {
pthread_rwlock_wrlock(&trace_load_rw_lock);
keep_message = dlt_check_trace_load(
trace_load_settings, mtin, msg->headerextra.tmsp, size,
dlt_daemon_output_internal_msg, (void *)(&params));
pthread_rwlock_unlock(&trace_load_rw_lock);
}
else {
dlt_vlog(
Expand Down
14 changes: 6 additions & 8 deletions src/lib/dlt_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ static DltReturnValue dlt_unregister_app_util(bool force_sending_messages);
static DltReturnValue dlt_user_output_internal_msg(DltLogLevelType loglevel, const char *text, void* params);
DltTraceLoadSettings* trace_load_settings = NULL;
uint32_t trace_load_settings_count = 0;
pthread_rwlock_t trace_load_rw_lock;
pthread_rwlock_t trace_load_rw_lock = PTHREAD_RWLOCK_INITIALIZER;
#endif

DltReturnValue dlt_user_check_library_version(const char *user_major_version, const char *user_minor_version)
Expand Down Expand Up @@ -513,9 +513,6 @@ DltReturnValue dlt_init(void)

#endif
#ifdef DLT_TRACE_LOAD_CTRL_ENABLE
/* initialize for trace load check */

pthread_rwlock_init(&trace_load_rw_lock, NULL);
pthread_rwlock_wrlock(&trace_load_rw_lock);

trace_load_settings = malloc(sizeof(DltTraceLoadSettings));
Expand Down Expand Up @@ -4159,19 +4156,20 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, const int mtype, int *
/* check trace load before output */
if (!sent_size)
{
pthread_rwlock_wrlock(&trace_load_rw_lock);
DltTraceLoadSettings* settings =
dlt_find_runtime_trace_load_settings(
trace_load_settings, trace_load_settings_count, dlt_user.appID, log->handle->contextID);

if (!dlt_check_trace_load(
const bool trace_load_in_limits = dlt_check_trace_load(
settings,
log->log_level, time_stamp,
sizeof(DltUserHeader)
+ msg.headersize - sizeof(DltStorageHeader)
+ log->size,
dlt_user_output_internal_msg,
NULL))
{
NULL);
pthread_rwlock_unlock(&trace_load_rw_lock);
if (!trace_load_in_limits){
return DLT_RETURN_LOAD_EXCEEDED;
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/shared/dlt_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -4451,8 +4451,6 @@ bool dlt_check_trace_load(
return false;
}

pthread_rwlock_rdlock(&trace_load_rw_lock);

/* Switch window slot according to timestamp
* If warning messages for hard/soft limit over are sent,
* the message size will be returned.
Expand All @@ -4474,8 +4472,6 @@ bool dlt_check_trace_load(
*/
const bool allow_output = !dlt_is_over_trace_load_hard_limit(tl_settings, size);

pthread_rwlock_unlock(&trace_load_rw_lock);

return allow_output;
}

Expand Down

0 comments on commit 7906ffc

Please sign in to comment.