diff options
author | Andreas Eversberg <jolly@eversberg.eu> | 2021-12-30 01:40:01 +0100 |
---|---|---|
committer | Andreas Eversberg <jolly@eversberg.eu> | 2021-12-30 23:34:45 +0100 |
commit | f613bfcc37b2813b88fa4b3abf367d511bf58181 (patch) | |
tree | a0600adb2c2e8779ee5918a445cef7ce8f2cd791 /src/libdisplay | |
parent | 2ddf33837e65cf881b23a559941b74c3bab52d83 (diff) |
Added locking functions to libdebug, to avoid printf race conditions
Diffstat (limited to 'src/libdisplay')
-rw-r--r-- | src/libdisplay/display_iq.c | 6 | ||||
-rw-r--r-- | src/libdisplay/display_measurements.c | 4 | ||||
-rw-r--r-- | src/libdisplay/display_spectrum.c | 6 | ||||
-rw-r--r-- | src/libdisplay/display_status.c | 2 | ||||
-rw-r--r-- | src/libdisplay/display_wave.c | 6 |
5 files changed, 24 insertions, 0 deletions
diff --git a/src/libdisplay/display_iq.c b/src/libdisplay/display_iq.c index a16594f..83cec6e 100644 --- a/src/libdisplay/display_iq.c +++ b/src/libdisplay/display_iq.c @@ -60,12 +60,14 @@ void display_iq_on(int on) if (iq_on) { memset(&screen, ' ', sizeof(screen)); memset(&screen_history, 0, sizeof(screen_history)); + lock_debug(); printf("\0337\033[H"); for (j = 0; j < SIZE; j++) { screen[j][w] = '\0'; puts(screen[j]); } printf("\0338"); fflush(stdout); + unlock_debug(); } if (on < 0) { @@ -114,6 +116,8 @@ void display_iq(float *samples, int length) if (!iq_on) return; + lock_debug(); + get_win_size(&width, &h); if (width > MAX_DISPLAY_WIDTH - 1) width = MAX_DISPLAY_WIDTH - 1; @@ -271,6 +275,8 @@ cont: } disp.interval_pos = pos; + + unlock_debug(); } diff --git a/src/libdisplay/display_measurements.c b/src/libdisplay/display_measurements.c index c25fb44..e2c2f0f 100644 --- a/src/libdisplay/display_measurements.c +++ b/src/libdisplay/display_measurements.c @@ -110,6 +110,8 @@ static void print_measurements(int on) if (bar_width < 1) return; + lock_debug(); + lines_total = 0; color = -1; printf("\0337\033[H"); @@ -252,6 +254,8 @@ static void print_measurements(int on) printf("\033[0;39m\0338"); fflush(stdout); debug_limit_scroll = lines_total; + + unlock_debug(); } void display_measurements_on(int on) diff --git a/src/libdisplay/display_spectrum.c b/src/libdisplay/display_spectrum.c index a85da76..b0f30f4 100644 --- a/src/libdisplay/display_spectrum.c +++ b/src/libdisplay/display_spectrum.c @@ -101,12 +101,14 @@ void display_spectrum_on(int on) if (spectrum_on) { memset(&screen, ' ', sizeof(screen)); memset(&buffer_hold, 0, sizeof(buffer_hold)); + lock_debug(); printf("\0337\033[H"); for (j = 0; j < HEIGHT; j++) { screen[j][w] = '\0'; puts(screen[j]); } printf("\0338"); fflush(stdout); + unlock_debug(); } if (on < 0) { @@ -140,6 +142,8 @@ void display_spectrum(float *samples, int length) if (!spectrum_on) return; + lock_debug(); + get_win_size(&width, &h); if (width > MAX_DISPLAY_WIDTH - 1) width = MAX_DISPLAY_WIDTH - 1; @@ -403,6 +407,8 @@ void display_spectrum(float *samples, int length) } disp.interval_pos = pos; + + unlock_debug(); } diff --git a/src/libdisplay/display_status.c b/src/libdisplay/display_status.c index 5205159..de38c9e 100644 --- a/src/libdisplay/display_status.c +++ b/src/libdisplay/display_status.c @@ -46,6 +46,7 @@ static void print_status(int on) if (h > lines_total) h = lines_total; + lock_debug(); printf("\0337\033[H\033[1;37m"); for (i = 0; i < h; i++) { j = 0; @@ -59,6 +60,7 @@ static void print_status(int on) putchar('\n'); } printf("\0338"); fflush(stdout); + unlock_debug(); } void display_status_on(int on) diff --git a/src/libdisplay/display_wave.c b/src/libdisplay/display_wave.c index 8932960..713873f 100644 --- a/src/libdisplay/display_wave.c +++ b/src/libdisplay/display_wave.c @@ -52,6 +52,7 @@ void display_wave_on(int on) if (wave_on) { memset(&screen, ' ', sizeof(screen)); + lock_debug(); printf("\0337\033[H"); for (i = 0; i < num_sender; i++) { for (j = 0; j < HEIGHT; j++) { @@ -60,6 +61,7 @@ void display_wave_on(int on) } } printf("\0338"); fflush(stdout); + unlock_debug(); } if (on < 0) @@ -102,6 +104,8 @@ void display_wave(dispwav_t *disp, sample_t *samples, int length, double range) if (!wave_on) return; + lock_debug(); + get_win_size(&width, &h); if (width > MAX_DISPLAY_WIDTH - 1) width = MAX_DISPLAY_WIDTH - 1; @@ -241,6 +245,8 @@ void display_wave(dispwav_t *disp, sample_t *samples, int length, double range) } disp->interval_pos = pos; + + unlock_debug(); } |