From c25141c910a97a69f3a9c29c024ba454a22e7896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deuc=D0=B5?= <shurd@sasktel.net> Date: Sun, 12 Jan 2025 12:37:47 -0500 Subject: [PATCH] Move video flags out from under vstatlock. This is a heavily accessed value that is rarely changed and was causing a lot of contention on vstatlock. Down to 2.9 seconds. --- src/conio/bitmap_con.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/conio/bitmap_con.c b/src/conio/bitmap_con.c index 8384b3ce1a..890e248cd2 100644 --- a/src/conio/bitmap_con.c +++ b/src/conio/bitmap_con.c @@ -107,6 +107,7 @@ static struct vmem_cell *bitmap_drawn; static int outstanding_rects; // win32gdi requires two rects... #define MAX_OUTSTANDING 2 +static protected_int32_t videoflags; /* Exported globals */ @@ -914,6 +915,7 @@ static int check_redraw(void) return ret; } +pthread_t bpid; /* Blinker Thread */ static void blinker_thread(void *data) { @@ -926,6 +928,7 @@ static void blinker_thread(void *data) int lfc; int blink; +bpid = pthread_self(); SetThreadName("Blinker"); while(1) { curs_changed = 0; @@ -1675,11 +1678,11 @@ void bitmap_setcustomcursor(int s, int e, int r, int b, int v) rwlock_unlock(&vstatlock); } -int bitmap_getvideoflags(void) +static void +setvideoflags_from_vstat(void) { - int flags=0; + int flags = 0; - rwlock_rdlock(&vstatlock); if(vstat.bright_background) flags |= CIOLIB_VIDEO_BGBRIGHT; if(vstat.no_bright) @@ -1690,13 +1693,20 @@ int bitmap_getvideoflags(void) flags |= CIOLIB_VIDEO_NOBLINK; if(vstat.blink_altcharset) flags |= CIOLIB_VIDEO_BLINKALTCHARS; - rwlock_unlock(&vstatlock); - return(flags); + protected_int32_set(&videoflags, flags); +} + +int bitmap_getvideoflags(void) +{ + int flags=0; + + return protected_int32_value(videoflags); } void bitmap_setvideoflags(int flags) { rwlock_wrlock(&vstatlock); + protected_int32_set(&videoflags, flags); if(flags & CIOLIB_VIDEO_BGBRIGHT) vstat.bright_background=1; else @@ -2205,6 +2215,7 @@ int bitmap_drv_init_mode(int mode, int *width, int *height, int maxwidth, int ma if(load_vmode(&vstat, mode)) { return(-1); } + setvideoflags_from_vstat(); // Save the old diagonal (no point is sqrting here) os = ((int64_t)vstat.winwidth * vstat.winwidth) + ((int64_t)vstat.winheight * vstat.winheight); @@ -2304,6 +2315,7 @@ int bitmap_drv_init(void (*drawrect_cb) (struct rectlist *data) | CONIO_OPT_SET_PIXEL | CONIO_OPT_CUSTOM_CURSOR | CONIO_OPT_FONT_SELECT | CONIO_OPT_EXTENDED_PALETTE | CONIO_OPT_PALETTE_SETTING | CONIO_OPT_BLOCKY_SCALING; + protected_int32_init(&videoflags, 0); pthread_mutex_init(&callbacks.lock, NULL); rwlock_init(&vstatlock); pthread_mutex_init(&screenlock, NULL); -- GitLab