Skip to content

Commit

Permalink
Shrink critical section in iperf_err().
Browse files Browse the repository at this point in the history
This is similar to what was done for iperf_errexit() in a previous commit.
  • Loading branch information
bmah888 committed Apr 26, 2024
1 parent 9632f93 commit 4058461
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/iperf_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ iperf_err(struct iperf_test *test, const char *format, ...)
struct tm *ltm = NULL;
char *ct = NULL;

if (pthread_mutex_lock(&(test->print_mutex)) != 0) {
perror("iperf_err: pthread_mutex_lock");
}

/* Timestamp if requested */
if (test != NULL && test->timestamps) {
time(&now);
Expand All @@ -64,6 +60,10 @@ iperf_err(struct iperf_test *test, const char *format, ...)
if (test != NULL && test->json_output && test->json_top != NULL)
cJSON_AddStringToObject(test->json_top, "error", str);
else {
if (pthread_mutex_lock(&(test->print_mutex)) != 0) {
perror("iperf_err: pthread_mutex_lock");
}

if (test && test->outfile && test->outfile != stdout) {
if (ct) {
fprintf(test->outfile, "%s", ct);
Expand All @@ -76,12 +76,13 @@ iperf_err(struct iperf_test *test, const char *format, ...)
}
fprintf(stderr, "iperf3: %s\n", str);
}
}
va_end(argp);

if (pthread_mutex_unlock(&(test->print_mutex)) != 0) {
perror("iperf_err: pthread_mutex_unlock");
if (pthread_mutex_unlock(&(test->print_mutex)) != 0) {
perror("iperf_err: pthread_mutex_unlock");
}

}
va_end(argp);
}

/* Do a printf to stderr or log file as appropriate, then exit. */
Expand Down

0 comments on commit 4058461

Please sign in to comment.