Skip to content
Snippets Groups Projects
Commit bd465bf7 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Use a rwlock for vstatlock.

Down to 3.4s now.
parent 2b31a3de
No related branches found
No related tags found
No related merge requests found
Pipeline #7742 failed
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <string.h> #include <string.h>
#include "threadwrap.h" #include "threadwrap.h"
#include "rwlockwrap.h"
#include "semwrap.h" #include "semwrap.h"
#include "gen_defs.h" #include "gen_defs.h"
#include "genwrap.h" #include "genwrap.h"
...@@ -109,7 +110,7 @@ static int outstanding_rects; ...@@ -109,7 +110,7 @@ static int outstanding_rects;
/* Exported globals */ /* Exported globals */
pthread_mutex_t vstatlock; pthread_rwlock_t vstatlock;
/* Forward declarations */ /* Forward declarations */
...@@ -388,7 +389,7 @@ static void cb_drawrect(struct rectlist *data) ...@@ -388,7 +389,7 @@ static void cb_drawrect(struct rectlist *data)
* 4) If vstat.curs_blinks is false, the cursor does not blink. * 4) If vstat.curs_blinks is false, the cursor does not blink.
* 5) When blinking, the cursor is shown when vstat.blink is true. * 5) When blinking, the cursor is shown when vstat.blink is true.
*/ */
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
curs_start = vstat.curs_start; curs_start = vstat.curs_start;
curs_end = vstat.curs_end; curs_end = vstat.curs_end;
curs_row = vstat.curs_row; curs_row = vstat.curs_row;
...@@ -396,7 +397,7 @@ static void cb_drawrect(struct rectlist *data) ...@@ -396,7 +397,7 @@ static void cb_drawrect(struct rectlist *data)
charheight = vstat.charheight; charheight = vstat.charheight;
charwidth = vstat.charwidth; charwidth = vstat.charwidth;
if (cursor_visible_locked()) { if (cursor_visible_locked()) {
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
cv = color_value(ciolib_fg); cv = color_value(ciolib_fg);
for (y = curs_start; y <= curs_end; y++) { for (y = curs_start; y <= curs_end; y++) {
pixel = &data->data[((curs_row - 1) * charheight + y) * data->rect.width + (curs_col - 1) * charwidth]; pixel = &data->data[((curs_row - 1) * charheight + y) * data->rect.width + (curs_col - 1) * charwidth];
...@@ -406,7 +407,7 @@ static void cb_drawrect(struct rectlist *data) ...@@ -406,7 +407,7 @@ static void cb_drawrect(struct rectlist *data)
} }
} }
else else
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
pthread_mutex_lock(&callbacks.lock); pthread_mutex_lock(&callbacks.lock);
callbacks.drawrect(data); callbacks.drawrect(data);
callbacks.rects++; callbacks.rects++;
...@@ -420,9 +421,9 @@ static void request_redraw_locked(void) ...@@ -420,9 +421,9 @@ static void request_redraw_locked(void)
static void request_redraw(void) static void request_redraw(void)
{ {
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
request_redraw_locked(); request_redraw_locked();
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
} }
/* /*
...@@ -906,10 +907,10 @@ static int check_redraw(void) ...@@ -906,10 +907,10 @@ static int check_redraw(void)
{ {
int ret; int ret;
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
ret = force_redraws; ret = force_redraws;
force_redraws = 0; force_redraws = 0;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return ret; return ret;
} }
...@@ -932,7 +933,7 @@ static void blinker_thread(void *data) ...@@ -932,7 +933,7 @@ static void blinker_thread(void *data)
SLEEP(10); SLEEP(10);
count++; count++;
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
if (count==25) { if (count==25) {
curs_changed = cursor_visible_locked(); curs_changed = cursor_visible_locked();
if(vstat.curs_blink) if(vstat.curs_blink)
...@@ -958,7 +959,7 @@ static void blinker_thread(void *data) ...@@ -958,7 +959,7 @@ static void blinker_thread(void *data)
lfc = force_cursor; lfc = force_cursor;
force_cursor = 0; force_cursor = 0;
blink = vstat.blink; blink = vstat.blink;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
if (check_redraw()) { if (check_redraw()) {
if (update_from_vmem(TRUE)) if (update_from_vmem(TRUE))
...@@ -1077,15 +1078,15 @@ static int update_from_vmem(int force) ...@@ -1077,15 +1078,15 @@ static int update_from_vmem(int force)
if(!bitmap_initialized) if(!bitmap_initialized)
return(-1); return(-1);
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
if (vstat.vmem == NULL) { if (vstat.vmem == NULL) {
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return -1; return -1;
} }
if(vstat.vmem->vmem == NULL) { if(vstat.vmem->vmem == NULL) {
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return -1; return -1;
} }
...@@ -1096,7 +1097,7 @@ static int update_from_vmem(int force) ...@@ -1096,7 +1097,7 @@ static int update_from_vmem(int force)
vs.cols = 0; vs.cols = 0;
vs.rows = 0; vs.rows = 0;
free(bitmap_drawn); free(bitmap_drawn);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return -1; return -1;
} }
bitmap_drawn = newl; bitmap_drawn = newl;
...@@ -1161,7 +1162,7 @@ static int update_from_vmem(int force) ...@@ -1161,7 +1162,7 @@ static int update_from_vmem(int force)
} }
release_vmem(vmem_ptr); release_vmem(vmem_ptr);
vs = vstat; vs = vstat;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return(0); return(0);
} }
...@@ -1193,7 +1194,7 @@ int bitmap_puttext(int sx, int sy, int ex, int ey, void *fill) ...@@ -1193,7 +1194,7 @@ int bitmap_puttext(int sx, int sy, int ex, int ey, void *fill)
return(0); return(0);
} }
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
vmem_ptr = get_vmem(&vstat); vmem_ptr = get_vmem(&vstat);
for (y = sy - 1; y < ey; y++) { for (y = sy - 1; y < ey; y++) {
for (x = sx - 1; x < ex; x++) { for (x = sx - 1; x < ex; x++) {
...@@ -1201,7 +1202,7 @@ int bitmap_puttext(int sx, int sy, int ex, int ey, void *fill) ...@@ -1201,7 +1202,7 @@ int bitmap_puttext(int sx, int sy, int ex, int ey, void *fill)
} }
} }
release_vmem(vmem_ptr); release_vmem(vmem_ptr);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return ret; return ret;
} }
...@@ -1210,9 +1211,9 @@ bitmap_vmem_puttext(int sx, int sy, int ex, int ey, struct vmem_cell *fill) ...@@ -1210,9 +1211,9 @@ bitmap_vmem_puttext(int sx, int sy, int ex, int ey, struct vmem_cell *fill)
{ {
int ret; int ret;
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
ret = bitmap_vmem_puttext_locked(sx, sy, ex, ey, fill); ret = bitmap_vmem_puttext_locked(sx, sy, ex, ey, fill);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return ret; return ret;
} }
...@@ -1236,7 +1237,7 @@ int bitmap_vmem_gettext(int sx, int sy, int ex, int ey, struct vmem_cell *fill) ...@@ -1236,7 +1237,7 @@ int bitmap_vmem_gettext(int sx, int sy, int ex, int ey, struct vmem_cell *fill)
return(0); return(0);
} }
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
vmem_ptr = get_vmem(&vstat); vmem_ptr = get_vmem(&vstat);
for(y=sy-1;y<ey;y++) { for(y=sy-1;y<ey;y++) {
struct vmem_cell *vc = vmem_cell_ptr(vmem_ptr, sx - 1, y); struct vmem_cell *vc = vmem_cell_ptr(vmem_ptr, sx - 1, y);
...@@ -1246,7 +1247,7 @@ int bitmap_vmem_gettext(int sx, int sy, int ex, int ey, struct vmem_cell *fill) ...@@ -1246,7 +1247,7 @@ int bitmap_vmem_gettext(int sx, int sy, int ex, int ey, struct vmem_cell *fill)
} }
} }
release_vmem(vmem_ptr); release_vmem(vmem_ptr);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return(1); return(1);
} }
...@@ -1255,7 +1256,7 @@ void bitmap_gotoxy(int x, int y) ...@@ -1255,7 +1256,7 @@ void bitmap_gotoxy(int x, int y)
if(!bitmap_initialized) if(!bitmap_initialized)
return; return;
/* Move cursor location */ /* Move cursor location */
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
if (vstat.curs_col != x + cio_textinfo.winleft - 1 || vstat.curs_row != y + cio_textinfo.wintop - 1) { if (vstat.curs_col != x + cio_textinfo.winleft - 1 || vstat.curs_row != y + cio_textinfo.wintop - 1) {
cio_textinfo.curx=x; cio_textinfo.curx=x;
cio_textinfo.cury=y; cio_textinfo.cury=y;
...@@ -1264,14 +1265,14 @@ void bitmap_gotoxy(int x, int y) ...@@ -1264,14 +1265,14 @@ void bitmap_gotoxy(int x, int y)
if (cursor_visible_locked()) if (cursor_visible_locked())
force_cursor = 1; force_cursor = 1;
} }
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
} }
void bitmap_setcursortype(int type) void bitmap_setcursortype(int type)
{ {
if(!bitmap_initialized) if(!bitmap_initialized)
return; return;
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
switch(type) { switch(type) {
case _NOCURSOR: case _NOCURSOR:
vstat.curs_start=0xff; vstat.curs_start=0xff;
...@@ -1288,7 +1289,7 @@ void bitmap_setcursortype(int type) ...@@ -1288,7 +1289,7 @@ void bitmap_setcursortype(int type)
force_cursor = 1; force_cursor = 1;
break; break;
} }
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
} }
int bitmap_setfont(int font, int force, int font_num) int bitmap_setfont(int font, int force, int font_num)
...@@ -1316,7 +1317,7 @@ int bitmap_setfont(int font, int force, int font_num) ...@@ -1316,7 +1317,7 @@ int bitmap_setfont(int font, int force, int font_num)
else if(conio_fontdata[font].eight_by_eight!=NULL) else if(conio_fontdata[font].eight_by_eight!=NULL)
newmode=C80X50; newmode=C80X50;
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
switch(vstat.charheight) { switch(vstat.charheight) {
case 8: case 8:
if(conio_fontdata[font].eight_by_eight==NULL) { if(conio_fontdata[font].eight_by_eight==NULL) {
...@@ -1374,7 +1375,7 @@ int bitmap_setfont(int font, int force, int font_num) ...@@ -1374,7 +1375,7 @@ int bitmap_setfont(int font, int force, int font_num)
new=malloc(ti.screenwidth*ti.screenheight*sizeof(*new)); new=malloc(ti.screenwidth*ti.screenheight*sizeof(*new));
if(!new) { if(!new) {
free(old); free(old);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return 0; return 0;
} }
pold=old; pold=old;
...@@ -1420,11 +1421,11 @@ int bitmap_setfont(int font, int force, int font_num) ...@@ -1420,11 +1421,11 @@ int bitmap_setfont(int font, int force, int font_num)
} }
} }
bitmap_loadfont_locked(NULL); bitmap_loadfont_locked(NULL);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return(1); return(1);
error_return: error_return:
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return(0); return(0);
} }
...@@ -1446,9 +1447,9 @@ int bitmap_loadfont(const char *filename) ...@@ -1446,9 +1447,9 @@ int bitmap_loadfont(const char *filename)
{ {
int ret; int ret;
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
ret = bitmap_loadfont_locked(filename); ret = bitmap_loadfont_locked(filename);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return ret; return ret;
} }
...@@ -1552,7 +1553,7 @@ int bitmap_movetext(int x, int y, int ex, int ey, int tox, int toy) ...@@ -1552,7 +1553,7 @@ int bitmap_movetext(int x, int y, int ex, int ey, int tox, int toy)
int oheight = height; int oheight = height;
bool oscrolldown = scrolldown; bool oscrolldown = scrolldown;
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
vmem_ptr = get_vmem(&vstat); vmem_ptr = get_vmem(&vstat);
if (width == vstat.cols && height > vstat.rows / 2 && toy == 1) { if (width == vstat.cols && height > vstat.rows / 2 && toy == 1) {
vmem_ptr->top_row += (y - toy); vmem_ptr->top_row += (y - toy);
...@@ -1590,7 +1591,7 @@ int bitmap_movetext(int x, int y, int ex, int ey, int tox, int toy) ...@@ -1590,7 +1591,7 @@ int bitmap_movetext(int x, int y, int ex, int ey, int tox, int toy)
bitmap_movetext_screen(vmem_ptr, x, oy, tox, otoy, oscrolldown ? -1 : 1, oheight, width); bitmap_movetext_screen(vmem_ptr, x, oy, tox, otoy, oscrolldown ? -1 : 1, oheight, width);
release_vmem(vmem_ptr); release_vmem(vmem_ptr);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return(1); return(1);
} }
...@@ -1606,13 +1607,13 @@ void bitmap_clreol(void) ...@@ -1606,13 +1607,13 @@ void bitmap_clreol(void)
return; return;
row = cio_textinfo.cury + cio_textinfo.wintop - 1; row = cio_textinfo.cury + cio_textinfo.wintop - 1;
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
vmem_ptr = get_vmem(&vstat); vmem_ptr = get_vmem(&vstat);
for(x=cio_textinfo.curx+cio_textinfo.winleft-2; x<cio_textinfo.winright; x++) { for(x=cio_textinfo.curx+cio_textinfo.winleft-2; x<cio_textinfo.winright; x++) {
set_vmem_cell(vmem_ptr, x, row - 1, fill, ciolib_fg, ciolib_bg); set_vmem_cell(vmem_ptr, x, row - 1, fill, ciolib_fg, ciolib_bg);
} }
release_vmem(vmem_ptr); release_vmem(vmem_ptr);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
} }
void bitmap_clrscr(void) void bitmap_clrscr(void)
...@@ -1624,7 +1625,7 @@ void bitmap_clrscr(void) ...@@ -1624,7 +1625,7 @@ void bitmap_clrscr(void)
if(!bitmap_initialized) if(!bitmap_initialized)
return; return;
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
vmem_ptr = get_vmem(&vstat); vmem_ptr = get_vmem(&vstat);
rows = vstat.rows; rows = vstat.rows;
cols = vstat.cols; cols = vstat.cols;
...@@ -1634,12 +1635,12 @@ void bitmap_clrscr(void) ...@@ -1634,12 +1635,12 @@ void bitmap_clrscr(void)
} }
} }
release_vmem(vmem_ptr); release_vmem(vmem_ptr);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
} }
void bitmap_getcustomcursor(int *s, int *e, int *r, int *b, int *v) void bitmap_getcustomcursor(int *s, int *e, int *r, int *b, int *v)
{ {
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
if(s) if(s)
*s=vstat.curs_start; *s=vstat.curs_start;
if(e) if(e)
...@@ -1650,14 +1651,14 @@ void bitmap_getcustomcursor(int *s, int *e, int *r, int *b, int *v) ...@@ -1650,14 +1651,14 @@ void bitmap_getcustomcursor(int *s, int *e, int *r, int *b, int *v)
*b=vstat.curs_blinks; *b=vstat.curs_blinks;
if(v) if(v)
*v=vstat.curs_visible; *v=vstat.curs_visible;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
} }
void bitmap_setcustomcursor(int s, int e, int r, int b, int v) void bitmap_setcustomcursor(int s, int e, int r, int b, int v)
{ {
double ratio; double ratio;
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
if(r==0) if(r==0)
ratio=0; ratio=0;
else else
...@@ -1671,14 +1672,14 @@ void bitmap_setcustomcursor(int s, int e, int r, int b, int v) ...@@ -1671,14 +1672,14 @@ void bitmap_setcustomcursor(int s, int e, int r, int b, int v)
if(v>=0) if(v>=0)
vstat.curs_visible=v; vstat.curs_visible=v;
force_cursor = 1; force_cursor = 1;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
} }
int bitmap_getvideoflags(void) int bitmap_getvideoflags(void)
{ {
int flags=0; int flags=0;
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
if(vstat.bright_background) if(vstat.bright_background)
flags |= CIOLIB_VIDEO_BGBRIGHT; flags |= CIOLIB_VIDEO_BGBRIGHT;
if(vstat.no_bright) if(vstat.no_bright)
...@@ -1689,13 +1690,13 @@ int bitmap_getvideoflags(void) ...@@ -1689,13 +1690,13 @@ int bitmap_getvideoflags(void)
flags |= CIOLIB_VIDEO_NOBLINK; flags |= CIOLIB_VIDEO_NOBLINK;
if(vstat.blink_altcharset) if(vstat.blink_altcharset)
flags |= CIOLIB_VIDEO_BLINKALTCHARS; flags |= CIOLIB_VIDEO_BLINKALTCHARS;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return(flags); return(flags);
} }
void bitmap_setvideoflags(int flags) void bitmap_setvideoflags(int flags)
{ {
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
if(flags & CIOLIB_VIDEO_BGBRIGHT) if(flags & CIOLIB_VIDEO_BGBRIGHT)
vstat.bright_background=1; vstat.bright_background=1;
else else
...@@ -1720,16 +1721,16 @@ void bitmap_setvideoflags(int flags) ...@@ -1720,16 +1721,16 @@ void bitmap_setvideoflags(int flags)
vstat.blink_altcharset=1; vstat.blink_altcharset=1;
else else
vstat.blink_altcharset=0; vstat.blink_altcharset=0;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
} }
int bitmap_attr2palette(uint8_t attr, uint32_t *fgp, uint32_t *bgp) int bitmap_attr2palette(uint8_t attr, uint32_t *fgp, uint32_t *bgp)
{ {
int ret; int ret;
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
ret = bitmap_attr2palette_locked(attr, fgp, bgp); ret = bitmap_attr2palette_locked(attr, fgp, bgp);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return ret; return ret;
} }
...@@ -1737,7 +1738,7 @@ int bitmap_attr2palette(uint8_t attr, uint32_t *fgp, uint32_t *bgp) ...@@ -1737,7 +1738,7 @@ int bitmap_attr2palette(uint8_t attr, uint32_t *fgp, uint32_t *bgp)
int bitmap_setpixel(uint32_t x, uint32_t y, uint32_t colour) int bitmap_setpixel(uint32_t x, uint32_t y, uint32_t colour)
{ {
update_from_vmem(FALSE); update_from_vmem(FALSE);
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
struct vstat_vmem *vmem_ptr = get_vmem(&vstat); struct vstat_vmem *vmem_ptr = get_vmem(&vstat);
struct vmem_cell *vc = vmem_cell_ptr(vmem_ptr, x / vstat.charwidth, y / vstat.charheight); struct vmem_cell *vc = vmem_cell_ptr(vmem_ptr, x / vstat.charwidth, y / vstat.charheight);
vc->bg |= 0x04000000; vc->bg |= 0x04000000;
...@@ -1758,7 +1759,7 @@ int bitmap_setpixel(uint32_t x, uint32_t y, uint32_t colour) ...@@ -1758,7 +1759,7 @@ int bitmap_setpixel(uint32_t x, uint32_t y, uint32_t colour)
} }
} }
pthread_mutex_unlock(&screenlock); pthread_mutex_unlock(&screenlock);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return 1; return 1;
} }
...@@ -1795,12 +1796,12 @@ int bitmap_setpixels(uint32_t sx, uint32_t sy, uint32_t ex, uint32_t ey, uint32_ ...@@ -1795,12 +1796,12 @@ int bitmap_setpixels(uint32_t sx, uint32_t sy, uint32_t ex, uint32_t ey, uint32_
} }
update_from_vmem(FALSE); update_from_vmem(FALSE);
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
struct vstat_vmem *vmem_ptr = get_vmem(&vstat); struct vstat_vmem *vmem_ptr = get_vmem(&vstat);
pthread_mutex_lock(&screenlock); pthread_mutex_lock(&screenlock);
if (ex > screena.screenwidth || ey > screena.screenheight) { if (ex > screena.screenwidth || ey > screena.screenheight) {
pthread_mutex_unlock(&screenlock); pthread_mutex_unlock(&screenlock);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return 0; return 0;
} }
...@@ -1864,7 +1865,7 @@ int bitmap_setpixels(uint32_t sx, uint32_t sy, uint32_t ex, uint32_t ey, uint32_ ...@@ -1864,7 +1865,7 @@ int bitmap_setpixels(uint32_t sx, uint32_t sy, uint32_t ex, uint32_t ey, uint32_
} }
pthread_mutex_unlock(&screenlock); pthread_mutex_unlock(&screenlock);
release_vmem(vmem_ptr); release_vmem(vmem_ptr);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return 1; return 1;
} }
...@@ -1925,17 +1926,17 @@ struct ciolib_pixels *bitmap_getpixels(uint32_t sx, uint32_t sy, uint32_t ex, ui ...@@ -1925,17 +1926,17 @@ struct ciolib_pixels *bitmap_getpixels(uint32_t sx, uint32_t sy, uint32_t ex, ui
int bitmap_get_modepalette(uint32_t p[16]) int bitmap_get_modepalette(uint32_t p[16])
{ {
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
memcpy(p, vstat.palette, sizeof(vstat.palette)); memcpy(p, vstat.palette, sizeof(vstat.palette));
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return 1; return 1;
} }
int bitmap_set_modepalette(uint32_t p[16]) int bitmap_set_modepalette(uint32_t p[16])
{ {
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
memcpy(vstat.palette, p, sizeof(vstat.palette)); memcpy(vstat.palette, p, sizeof(vstat.palette));
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return 1; return 1;
} }
...@@ -2304,17 +2305,17 @@ int bitmap_drv_init(void (*drawrect_cb) (struct rectlist *data) ...@@ -2304,17 +2305,17 @@ int bitmap_drv_init(void (*drawrect_cb) (struct rectlist *data)
| CONIO_OPT_FONT_SELECT | CONIO_OPT_EXTENDED_PALETTE | CONIO_OPT_PALETTE_SETTING | CONIO_OPT_FONT_SELECT | CONIO_OPT_EXTENDED_PALETTE | CONIO_OPT_PALETTE_SETTING
| CONIO_OPT_BLOCKY_SCALING; | CONIO_OPT_BLOCKY_SCALING;
pthread_mutex_init(&callbacks.lock, NULL); pthread_mutex_init(&callbacks.lock, NULL);
pthread_mutex_init(&vstatlock, NULL); rwlock_init(&vstatlock);
pthread_mutex_init(&screenlock, NULL); pthread_mutex_init(&screenlock, NULL);
pthread_mutex_init(&free_rect_lock, NULL); pthread_mutex_init(&free_rect_lock, NULL);
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
vstat.flags = VIDMODES_FLAG_PALETTE_VMEM; vstat.flags = VIDMODES_FLAG_PALETTE_VMEM;
pthread_mutex_lock(&screenlock); pthread_mutex_lock(&screenlock);
for (i = 0; i < sizeof(dac_default)/sizeof(struct dac_colors); i++) { for (i = 0; i < sizeof(dac_default)/sizeof(struct dac_colors); i++) {
palette[i] = (0xffU << 24) | (dac_default[i].red << 16) | (dac_default[i].green << 8) | dac_default[i].blue; palette[i] = (0xffU << 24) | (dac_default[i].red << 16) | (dac_default[i].green << 8) | dac_default[i].blue;
} }
pthread_mutex_unlock(&screenlock); pthread_mutex_unlock(&screenlock);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
callbacks.drawrect=drawrect_cb; callbacks.drawrect=drawrect_cb;
callbacks.flush=flush_cb; callbacks.flush=flush_cb;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "vidmodes.h" #include "vidmodes.h"
#include "threadwrap.h" #include "threadwrap.h"
#include "rwlockwrap.h"
struct rectangle { struct rectangle {
int x; int x;
...@@ -21,7 +22,7 @@ struct rectlist { ...@@ -21,7 +22,7 @@ struct rectlist {
}; };
extern struct video_stats vstat; extern struct video_stats vstat;
extern pthread_mutex_t vstatlock; extern rwlock_t vstatlock;
#ifdef BITMAP_CIOLIB_DRIVER #ifdef BITMAP_CIOLIB_DRIVER
/* Called from drivers */ /* Called from drivers */
......
...@@ -370,18 +370,18 @@ static int sdl_init_mode(int mode, bool init) ...@@ -370,18 +370,18 @@ static int sdl_init_mode(int mode, bool init)
int w, h; int w, h;
if (mode != CIOLIB_MODE_CUSTOM) { if (mode != CIOLIB_MODE_CUSTOM) {
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
if (mode == vstat.mode && !init) { if (mode == vstat.mode && !init) {
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return 0; return 0;
} }
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
} }
sdl_user_func(SDL_USEREVENT_FLUSH); sdl_user_func(SDL_USEREVENT_FLUSH);
pthread_mutex_lock(&win_mutex); pthread_mutex_lock(&win_mutex);
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
if (!sdl_get_bounds(&w, &h)) { if (!sdl_get_bounds(&w, &h)) {
w = 0; w = 0;
h = 0; h = 0;
...@@ -395,7 +395,7 @@ static int sdl_init_mode(int mode, bool init) ...@@ -395,7 +395,7 @@ static int sdl_init_mode(int mode, bool init)
pthread_mutex_lock(&sdl_mode_mutex); pthread_mutex_lock(&sdl_mode_mutex);
sdl_mode = true; sdl_mode = true;
pthread_mutex_unlock(&sdl_mode_mutex); pthread_mutex_unlock(&sdl_mode_mutex);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
pthread_mutex_unlock(&win_mutex); pthread_mutex_unlock(&win_mutex);
sdl_user_func_ret(SDL_USEREVENT_SETVIDMODE, vstat.winwidth, vstat.winheight); sdl_user_func_ret(SDL_USEREVENT_SETVIDMODE, vstat.winwidth, vstat.winheight);
...@@ -437,9 +437,9 @@ update_cvstat(struct video_stats *vs) ...@@ -437,9 +437,9 @@ update_cvstat(struct video_stats *vs)
{ {
if (vs != NULL && vs != &vstat) { if (vs != NULL && vs != &vstat) {
vstat.scaling = sdl_getscaling(); vstat.scaling = sdl_getscaling();
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
*vs = vstat; *vs = vstat;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
} }
} }
...@@ -460,7 +460,7 @@ static void internal_setwinsize(struct video_stats *vs, bool force) ...@@ -460,7 +460,7 @@ static void internal_setwinsize(struct video_stats *vs, bool force)
if (h < vs->scrnheight) if (h < vs->scrnheight)
h = vs->scrnheight; h = vs->scrnheight;
pthread_mutex_lock(&win_mutex); pthread_mutex_lock(&win_mutex);
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
if (w == vstat.winwidth && h == vstat.winheight) if (w == vstat.winwidth && h == vstat.winheight)
changed = force; changed = force;
else { else {
...@@ -468,7 +468,7 @@ static void internal_setwinsize(struct video_stats *vs, bool force) ...@@ -468,7 +468,7 @@ static void internal_setwinsize(struct video_stats *vs, bool force)
vs->winheight = vstat.winheight = h; vs->winheight = vstat.winheight = h;
} }
if (changed) { if (changed) {
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
pthread_mutex_unlock(&win_mutex); pthread_mutex_unlock(&win_mutex);
} }
else { else {
...@@ -479,7 +479,7 @@ static void internal_setwinsize(struct video_stats *vs, bool force) ...@@ -479,7 +479,7 @@ static void internal_setwinsize(struct video_stats *vs, bool force)
vs->winheight = h; vs->winheight = h;
changed = true; changed = true;
} }
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
pthread_mutex_unlock(&win_mutex); pthread_mutex_unlock(&win_mutex);
vstat.scaling = sdl_getscaling(); vstat.scaling = sdl_getscaling();
} }
...@@ -509,9 +509,9 @@ void sdl_getwinsize_locked(int *w, int *h) ...@@ -509,9 +509,9 @@ void sdl_getwinsize_locked(int *w, int *h)
void sdl_getwinsize(int *w, int *h) void sdl_getwinsize(int *w, int *h)
{ {
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
sdl_getwinsize_locked(w, h); sdl_getwinsize_locked(w, h);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
} }
/* Called from main thread only */ /* Called from main thread only */
...@@ -597,12 +597,12 @@ int sdl_get_window_info(int *width, int *height, int *xpos, int *ypos) ...@@ -597,12 +597,12 @@ int sdl_get_window_info(int *width, int *height, int *xpos, int *ypos)
} }
if (width || height) { if (width || height) {
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
if(width) if(width)
*width=vstat.winwidth; *width=vstat.winwidth;
if(height) if(height)
*height=vstat.winheight; *height=vstat.winheight;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
} }
return(1); return(1);
...@@ -639,9 +639,9 @@ static void setup_surfaces(struct video_stats *vs) ...@@ -639,9 +639,9 @@ static void setup_surfaces(struct video_stats *vs)
#if (SDL_MINOR_VERSION > 0) || (SDL_PATCHLEVEL >= 1) #if (SDL_MINOR_VERSION > 0) || (SDL_PATCHLEVEL >= 1)
flags |= SDL_WINDOW_ALLOW_HIGHDPI; flags |= SDL_WINDOW_ALLOW_HIGHDPI;
#endif #endif
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
bitmap_get_scaled_win_size(1.0, &idealmw, &idealmh, 0, 0); bitmap_get_scaled_win_size(1.0, &idealmw, &idealmh, 0, 0);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
pthread_mutex_lock(&win_mutex); pthread_mutex_lock(&win_mutex);
idealw = vs->winwidth; idealw = vs->winwidth;
idealh = vs->winheight; idealh = vs->winheight;
...@@ -705,10 +705,10 @@ static void setup_surfaces(struct video_stats *vs) ...@@ -705,10 +705,10 @@ static void setup_surfaces(struct video_stats *vs)
texture = newtexture; texture = newtexture;
} }
if (vs != &vstat) { if (vs != &vstat) {
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
vstat.winwidth = vs->winwidth; vstat.winwidth = vs->winwidth;
vstat.winheight = vs->winheight; vstat.winheight = vs->winheight;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
} }
sdl_bughack_minsize(idealmw, idealmh, new_win); sdl_bughack_minsize(idealmw, idealmh, new_win);
...@@ -1034,9 +1034,9 @@ void sdl_video_event_thread(void *data) ...@@ -1034,9 +1034,9 @@ void sdl_video_event_thread(void *data)
h = 0; h = 0;
} }
pthread_mutex_unlock(&win_mutex); pthread_mutex_unlock(&win_mutex);
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
bitmap_snap(ev.key.keysym.sym == SDLK_RIGHT, w, h); bitmap_snap(ev.key.keysym.sym == SDLK_RIGHT, w, h);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
update_cvstat(&cvstat); update_cvstat(&cvstat);
setup_surfaces(&cvstat); setup_surfaces(&cvstat);
break; break;
...@@ -1175,12 +1175,12 @@ void sdl_video_event_thread(void *data) ...@@ -1175,12 +1175,12 @@ void sdl_video_event_thread(void *data)
return; return;
case SDL_USEREVENT_FLUSH: case SDL_USEREVENT_FLUSH:
update_cvstat(&cvstat); update_cvstat(&cvstat);
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
// Get correct aspect ratio for dst... // Get correct aspect ratio for dst...
int sw = cvstat.scrnwidth; int sw = cvstat.scrnwidth;
int sh = cvstat.scrnheight; int sh = cvstat.scrnheight;
bitmap_get_scaled_win_size(cvstat.scaling, &dst.w, &dst.h, cvstat.winwidth, cvstat.winheight); bitmap_get_scaled_win_size(cvstat.scaling, &dst.w, &dst.h, cvstat.winwidth, cvstat.winheight);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
pthread_mutex_lock(&win_mutex); pthread_mutex_lock(&win_mutex);
if (win != NULL) { if (win != NULL) {
pthread_mutex_unlock(&win_mutex); pthread_mutex_unlock(&win_mutex);
...@@ -1438,9 +1438,9 @@ sdl_getscaling(void) ...@@ -1438,9 +1438,9 @@ sdl_getscaling(void)
double ret; double ret;
// TODO: I hate having nested locks like this. :( // TODO: I hate having nested locks like this. :(
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
ret = bitmap_double_mult_inside(vstat.winwidth, vstat.winheight); ret = bitmap_double_mult_inside(vstat.winwidth, vstat.winheight);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return ret; return ret;
} }
...@@ -1449,9 +1449,9 @@ sdl_setscaling(double newval) ...@@ -1449,9 +1449,9 @@ sdl_setscaling(double newval)
{ {
int w, h; int w, h;
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
bitmap_get_scaled_win_size(newval, &w, &h, 0, 0); bitmap_get_scaled_win_size(newval, &w, &h, 0, 0);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
sdl_setwinsize(w, h); sdl_setwinsize(w, h);
} }
...@@ -1460,9 +1460,9 @@ sdl_getscaling_type(void) ...@@ -1460,9 +1460,9 @@ sdl_getscaling_type(void)
{ {
enum ciolib_scaling ret; enum ciolib_scaling ret;
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
ret = (internal_scaling ? CIOLIB_SCALING_INTERNAL : CIOLIB_SCALING_EXTERNAL); ret = (internal_scaling ? CIOLIB_SCALING_INTERNAL : CIOLIB_SCALING_EXTERNAL);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return ret; return ret;
} }
...@@ -1473,15 +1473,15 @@ sdl_setscaling_type(enum ciolib_scaling newval) ...@@ -1473,15 +1473,15 @@ sdl_setscaling_type(enum ciolib_scaling newval)
int w, h; int w, h;
update_cvstat(&cvstat); update_cvstat(&cvstat);
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
if ((newval == CIOLIB_SCALING_INTERNAL) != internal_scaling) { if ((newval == CIOLIB_SCALING_INTERNAL) != internal_scaling) {
internal_scaling = (newval == CIOLIB_SCALING_INTERNAL); internal_scaling = (newval == CIOLIB_SCALING_INTERNAL);
w = vstat.winwidth; w = vstat.winwidth;
h = vstat.winheight; h = vstat.winheight;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
sdl_user_func_ret(SDL_USEREVENT_SETVIDMODE, w, h); sdl_user_func_ret(SDL_USEREVENT_SETVIDMODE, w, h);
} }
else { else {
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
} }
} }
...@@ -263,7 +263,7 @@ gdi_handle_wm_size(WPARAM wParam, LPARAM lParam) ...@@ -263,7 +263,7 @@ gdi_handle_wm_size(WPARAM wParam, LPARAM lParam)
} }
w = lParam & 0xffff; w = lParam & 0xffff;
h = (lParam >> 16) & 0xffff; h = (lParam >> 16) & 0xffff;
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
vstat.winwidth = w; vstat.winwidth = w;
vstat.winheight = h; vstat.winheight = h;
vstat.scaling = bitmap_double_mult_inside(w, h); vstat.scaling = bitmap_double_mult_inside(w, h);
...@@ -272,7 +272,7 @@ gdi_handle_wm_size(WPARAM wParam, LPARAM lParam) ...@@ -272,7 +272,7 @@ gdi_handle_wm_size(WPARAM wParam, LPARAM lParam)
if (!(fullscreen || maximized)) if (!(fullscreen || maximized))
gdi_setwinsize(w, h); gdi_setwinsize(w, h);
} }
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return 0; return 0;
} }
...@@ -288,10 +288,10 @@ gdi_handle_wm_sizing(WPARAM wParam, RECT *r) ...@@ -288,10 +288,10 @@ gdi_handle_wm_sizing(WPARAM wParam, RECT *r)
UnadjustWindowSize(&ow, &oh); UnadjustWindowSize(&ow, &oh);
nw = ow; nw = ow;
nh = oh; nh = oh;
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
s = bitmap_double_mult_inside(ow, oh); s = bitmap_double_mult_inside(ow, oh);
bitmap_get_scaled_win_size(s, &nw, &nh, 0, 0); bitmap_get_scaled_win_size(s, &nw, &nh, 0, 0);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
if (nw != ow) { if (nw != ow) {
switch (wParam) { switch (wParam) {
...@@ -338,13 +338,13 @@ gdi_handle_wm_paint(HWND hwnd) ...@@ -338,13 +338,13 @@ gdi_handle_wm_paint(HWND hwnd)
void *data; void *data;
enum ciolib_scaling st; enum ciolib_scaling st;
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
w = vstat.winwidth; w = vstat.winwidth;
h = vstat.winheight; h = vstat.winheight;
vsw = vstat.scrnwidth; vsw = vstat.scrnwidth;
vsh = vstat.scrnheight; vsh = vstat.scrnheight;
bitmap_get_scaled_win_size(vstat.scaling, &sw, &sh, vstat.winwidth, vstat.winheight); bitmap_get_scaled_win_size(vstat.scaling, &sw, &sh, vstat.winwidth, vstat.winheight);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
while(true) { while(true) {
list = get_rect(); list = get_rect();
if (list == NULL) if (list == NULL)
...@@ -506,12 +506,12 @@ win_to_pos(LPARAM lParam, struct gdi_mouse_pos *p) ...@@ -506,12 +506,12 @@ win_to_pos(LPARAM lParam, struct gdi_mouse_pos *p)
cx = lParam & 0xffff; cx = lParam & 0xffff;
cy = (lParam >> 16) & 0xffff; cy = (lParam >> 16) & 0xffff;
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
cols = vstat.cols; cols = vstat.cols;
rows = vstat.rows; rows = vstat.rows;
scrnheight = vstat.scrnheight; scrnheight = vstat.scrnheight;
scrnwidth = vstat.scrnwidth; scrnwidth = vstat.scrnwidth;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
cx = lParam & 0xffff; cx = lParam & 0xffff;
pthread_mutex_lock(&off_lock); pthread_mutex_lock(&off_lock);
...@@ -624,11 +624,11 @@ handle_wm_getminmaxinfo(MINMAXINFO *inf) ...@@ -624,11 +624,11 @@ handle_wm_getminmaxinfo(MINMAXINFO *inf)
maxw = monw; maxw = monw;
maxh = monh; maxh = monh;
UnadjustWindowSize(&maxw, &maxh); UnadjustWindowSize(&maxw, &maxh);
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
mult = bitmap_double_mult_inside(maxw, maxh); mult = bitmap_double_mult_inside(maxw, maxh);
bitmap_get_scaled_win_size(mult, &maxw, &maxh, 0, 0); bitmap_get_scaled_win_size(mult, &maxw, &maxh, 0, 0);
bitmap_get_scaled_win_size(1, &minw, &minh, 0, 0); bitmap_get_scaled_win_size(1, &minw, &minh, 0, 0);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
r.top = 0; r.top = 0;
r.left = 0; r.left = 0;
...@@ -658,7 +658,7 @@ gdi_get_windowsize_at_dpi(bool screen, LONG *w, LONG *h, WORD dpi) ...@@ -658,7 +658,7 @@ gdi_get_windowsize_at_dpi(bool screen, LONG *w, LONG *h, WORD dpi)
{ {
RECT r; RECT r;
r.left = r.top = 0; r.left = r.top = 0;
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
// Now make the inside of the window the size we want (sigh) // Now make the inside of the window the size we want (sigh)
if (screen) { if (screen) {
r.right = vstat.scrnwidth - 1; r.right = vstat.scrnwidth - 1;
...@@ -667,7 +667,7 @@ gdi_get_windowsize_at_dpi(bool screen, LONG *w, LONG *h, WORD dpi) ...@@ -667,7 +667,7 @@ gdi_get_windowsize_at_dpi(bool screen, LONG *w, LONG *h, WORD dpi)
r.right = vstat.winwidth - 1; r.right = vstat.winwidth - 1;
r.bottom = vstat.winheight - 1; r.bottom = vstat.winheight - 1;
} }
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
gdiAdjustWindowRect(&r, STYLE, FALSE, dpi); gdiAdjustWindowRect(&r, STYLE, FALSE, dpi);
if (w) if (w)
*w = r.right - r.left + 1; *w = r.right - r.left + 1;
...@@ -811,10 +811,10 @@ gdi_snap(bool grow) ...@@ -811,10 +811,10 @@ gdi_snap(bool grow)
return; return;
get_monitor_size_pos(&mw, &mh, NULL, NULL); get_monitor_size_pos(&mw, &mh, NULL, NULL);
UnadjustWindowSize(&mw, &mh); UnadjustWindowSize(&mw, &mh);
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
bitmap_snap(grow, mw, mh); bitmap_snap(grow, mw, mh);
gdi_setwinsize(vstat.winwidth, vstat.winheight); gdi_setwinsize(vstat.winwidth, vstat.winheight);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
} }
#define WMOD_CTRL 1 #define WMOD_CTRL 1
...@@ -903,9 +903,9 @@ magic_message(MSG msg) ...@@ -903,9 +903,9 @@ magic_message(MSG msg)
window_left = wi.rcWindow.left; window_left = wi.rcWindow.left;
window_top = wi.rcWindow.top; window_top = wi.rcWindow.top;
} }
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
window_scaling = (float)vstat.scaling; window_scaling = (float)vstat.scaling;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
SetWindowLongPtr(win, GWL_STYLE, STYLE); SetWindowLongPtr(win, GWL_STYLE, STYLE);
PostMessageW(win, WM_USER_SETPOS, mi.rcMonitor.left, mi.rcMonitor.top); PostMessageW(win, WM_USER_SETPOS, mi.rcMonitor.left, mi.rcMonitor.top);
PostMessageW(win, WM_USER_SETSIZE, mi.rcMonitor.right - mi.rcMonitor.left + 1, mi.rcMonitor.bottom - mi.rcMonitor.top + 1); PostMessageW(win, WM_USER_SETSIZE, mi.rcMonitor.right - mi.rcMonitor.left + 1, mi.rcMonitor.bottom - mi.rcMonitor.top + 1);
...@@ -991,7 +991,7 @@ gdi_thread(void *arg) ...@@ -991,7 +991,7 @@ gdi_thread(void *arg)
cl = RegisterClassW(&wc); cl = RegisterClassW(&wc);
if (cl == 0) if (cl == 0)
goto fail; goto fail;
pthread_mutex_lock(&vstatlock); rwlock_rwlock(&vstatlock);
if (ciolib_initial_scaling != 0) { if (ciolib_initial_scaling != 0) {
if (ciolib_initial_scaling < 1.0) { if (ciolib_initial_scaling < 1.0) {
if (get_monitor_size_pos(&vstat.winwidth, &vstat.winheight, &wx, &wy)) { if (get_monitor_size_pos(&vstat.winwidth, &vstat.winheight, &wx, &wy)) {
...@@ -1013,7 +1013,7 @@ gdi_thread(void *arg) ...@@ -1013,7 +1013,7 @@ gdi_thread(void *arg)
fullscreen = false; fullscreen = false;
} }
stype = ciolib_initial_scaling_type; stype = ciolib_initial_scaling_type;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
gdi_get_windowsize_at_dpi(false, &w, &h, 0); gdi_get_windowsize_at_dpi(false, &w, &h, 0);
win = CreateWindowW(wc.lpszClassName, L"SyncConsole", STYLE, wx, wy, w, h, NULL, NULL, NULL, NULL); win = CreateWindowW(wc.lpszClassName, L"SyncConsole", STYLE, wx, wy, w, h, NULL, NULL, NULL, NULL);
if (win == NULL) if (win == NULL)
...@@ -1082,15 +1082,15 @@ gdi_textmode(int mode) ...@@ -1082,15 +1082,15 @@ gdi_textmode(int mode)
int mw, mh; int mw, mh;
if (mode != CIOLIB_MODE_CUSTOM) { if (mode != CIOLIB_MODE_CUSTOM) {
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
if (mode == vstat.mode) { if (mode == vstat.mode) {
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return; return;
} }
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
} }
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
get_monitor_size_pos(&mw, &mh, NULL, NULL); get_monitor_size_pos(&mw, &mh, NULL, NULL);
UnadjustWindowSize(&mw, &mh); UnadjustWindowSize(&mw, &mh);
bitmap_drv_init_mode(mode, NULL, NULL, mw, mh); bitmap_drv_init_mode(mode, NULL, NULL, mw, mh);
...@@ -1100,7 +1100,7 @@ gdi_textmode(int mode) ...@@ -1100,7 +1100,7 @@ gdi_textmode(int mode)
vstat.scaling = bitmap_double_mult_inside(mw, mh); vstat.scaling = bitmap_double_mult_inside(mw, mh);
} }
gdi_setwinsize(vstat.winwidth, vstat.winheight); gdi_setwinsize(vstat.winwidth, vstat.winheight);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
bitmap_drv_request_pixels(); bitmap_drv_request_pixels();
return; return;
...@@ -1230,12 +1230,12 @@ gdi_getcliptext(void) ...@@ -1230,12 +1230,12 @@ gdi_getcliptext(void)
int int
gdi_get_window_info(int *width, int *height, int *xpos, int *ypos) gdi_get_window_info(int *width, int *height, int *xpos, int *ypos)
{ {
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
if(width) if(width)
*width=vstat.winwidth; *width=vstat.winwidth;
if(height) if(height)
*height=vstat.winheight; *height=vstat.winheight;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
pthread_mutex_lock(&winpos_lock); pthread_mutex_lock(&winpos_lock);
if(xpos) if(xpos)
*xpos=winxpos; *xpos=winxpos;
...@@ -1405,9 +1405,9 @@ gdi_getscaling(void) ...@@ -1405,9 +1405,9 @@ gdi_getscaling(void)
{ {
double ret; double ret;
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
ret = bitmap_double_mult_inside(vstat.winwidth, vstat.winheight); ret = bitmap_double_mult_inside(vstat.winwidth, vstat.winheight);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return ret; return ret;
} }
...@@ -1420,9 +1420,9 @@ gdi_setscaling(double newval) ...@@ -1420,9 +1420,9 @@ gdi_setscaling(double newval)
window_scaling = (float)newval; window_scaling = (float)newval;
} }
else { else {
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
bitmap_get_scaled_win_size(newval, &w, &h, 0, 0); bitmap_get_scaled_win_size(newval, &w, &h, 0, 0);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
gdi_setwinsize(w, h); gdi_setwinsize(w, h);
} }
} }
......
...@@ -776,9 +776,9 @@ double x_getscaling(void) ...@@ -776,9 +776,9 @@ double x_getscaling(void)
{ {
double ret; double ret;
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
ret = vstat.scaling; ret = vstat.scaling;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return ret; return ret;
} }
......
...@@ -619,12 +619,12 @@ x11_get_maxsize(int *w, int *h) ...@@ -619,12 +619,12 @@ x11_get_maxsize(int *w, int *h)
if (dpy == NULL) if (dpy == NULL)
return false; return false;
if (fullscreen) { if (fullscreen) {
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
if (w) if (w)
*w = vstat.winwidth; *w = vstat.winwidth;
if (h) if (h)
*h = vstat.winheight; *h = vstat.winheight;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return true; return true;
} }
else { else {
...@@ -715,9 +715,9 @@ resize_pictures(void) ...@@ -715,9 +715,9 @@ resize_pictures(void)
xrender_src_pict = x11.XRenderCreatePicture(dpy, xrender_pm, xrender_pf, 0, &pa); xrender_src_pict = x11.XRenderCreatePicture(dpy, xrender_pm, xrender_pf, 0, &pa);
xrender_dst_pict = x11.XRenderCreatePicture(dpy, win, xrender_pf, 0, &pa); xrender_dst_pict = x11.XRenderCreatePicture(dpy, win, xrender_pf, 0, &pa);
x11.XRenderSetPictureFilter(dpy, xrender_src_pict, "best", NULL, 0); x11.XRenderSetPictureFilter(dpy, xrender_src_pict, "best", NULL, 0);
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
bitmap_get_scaled_win_size(vstat.scaling, &iw, &ih, 0, 0); bitmap_get_scaled_win_size(vstat.scaling, &iw, &ih, 0, 0);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
XTransform transform_matrix = {{ XTransform transform_matrix = {{
{XDoubleToFixed((double)vstat.scrnwidth / iw), XDoubleToFixed(0), XDoubleToFixed(0)}, {XDoubleToFixed((double)vstat.scrnwidth / iw), XDoubleToFixed(0), XDoubleToFixed(0)},
{XDoubleToFixed(0), XDoubleToFixed((double)vstat.scrnheight / ih), XDoubleToFixed(0)}, {XDoubleToFixed(0), XDoubleToFixed((double)vstat.scrnheight / ih), XDoubleToFixed(0)},
...@@ -743,9 +743,9 @@ static void resize_xim(void) ...@@ -743,9 +743,9 @@ static void resize_xim(void)
resize_pictures(); resize_pictures();
if (x_internal_scaling) { if (x_internal_scaling) {
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
bitmap_get_scaled_win_size(x_cvstat.scaling, &width, &height, 0, 0); bitmap_get_scaled_win_size(x_cvstat.scaling, &width, &height, 0, 0);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
} }
else { else {
width = x_cvstat.scrnwidth; width = x_cvstat.scrnwidth;
...@@ -806,11 +806,11 @@ map_window(bool mp) ...@@ -806,11 +806,11 @@ map_window(bool mp)
if (!fullscreen && !fullscreen_pending) { if (!fullscreen && !fullscreen_pending) {
if (x11_get_maxsize(&sh->max_width,&sh->max_height)) { if (x11_get_maxsize(&sh->max_width,&sh->max_height)) {
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
bitmap_get_scaled_win_size(bitmap_double_mult_inside(sh->max_width, sh->max_height), &sh->max_width, &sh->max_height, sh->max_width, sh->max_height); bitmap_get_scaled_win_size(bitmap_double_mult_inside(sh->max_width, sh->max_height), &sh->max_width, &sh->max_height, sh->max_width, sh->max_height);
} }
else { else {
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
bitmap_get_scaled_win_size(7.0, &sh->max_width, &sh->max_height, 0, 0); bitmap_get_scaled_win_size(7.0, &sh->max_width, &sh->max_height, 0, 0);
} }
if (sh->max_width != last_maxw) if (sh->max_width != last_maxw)
...@@ -829,7 +829,7 @@ map_window(bool mp) ...@@ -829,7 +829,7 @@ map_window(bool mp)
sh->flags |= PSize; sh->flags |= PSize;
} }
else else
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
bitmap_get_scaled_win_size(1.0, &sh->min_width, &sh->min_height, 0, 0); bitmap_get_scaled_win_size(1.0, &sh->min_width, &sh->min_height, 0, 0);
if (sh->min_width != last_minw) if (sh->min_width != last_minw)
...@@ -840,7 +840,7 @@ map_window(bool mp) ...@@ -840,7 +840,7 @@ map_window(bool mp)
last_minh = sh->min_height; last_minh = sh->min_height;
sh->flags |= PMinSize; sh->flags |= PMinSize;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
if (x_cvstat.aspect_width != 0 && x_cvstat.aspect_height != 0) { if (x_cvstat.aspect_width != 0 && x_cvstat.aspect_height != 0) {
sh->min_aspect.x = sh->max_aspect.x = x_cvstat.aspect_width; sh->min_aspect.x = sh->max_aspect.x = x_cvstat.aspect_width;
...@@ -869,9 +869,9 @@ map_window(bool mp) ...@@ -869,9 +869,9 @@ map_window(bool mp)
*/ */
if (extents_changed || mp) if (extents_changed || mp)
x11.XSetWMNormalHints(dpy, win, sh); x11.XSetWMNormalHints(dpy, win, sh);
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
vstat.scaling = x_cvstat.scaling; vstat.scaling = x_cvstat.scaling;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
if (mp) if (mp)
x11.XMapWindow(dpy, win); x11.XMapWindow(dpy, win);
...@@ -1052,12 +1052,12 @@ static int init_window() ...@@ -1052,12 +1052,12 @@ static int init_window()
wa.background_pixel = black; wa.background_pixel = black;
wa.border_pixel = black; wa.border_pixel = black;
x11_get_maxsize(&mw, &mh); x11_get_maxsize(&mw, &mh);
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
bitmap_get_scaled_win_size(x_cvstat.scaling, &w, &h, mw, mh); bitmap_get_scaled_win_size(x_cvstat.scaling, &w, &h, mw, mh);
vstat.winwidth = x_cvstat.winwidth = w; vstat.winwidth = x_cvstat.winwidth = w;
vstat.winheight = x_cvstat.winheight = h; vstat.winheight = x_cvstat.winheight = h;
vstat.scaling = x_cvstat.scaling = bitmap_double_mult_inside(w, h); vstat.scaling = x_cvstat.scaling = bitmap_double_mult_inside(w, h);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
win = x11.XCreateWindow(dpy, parent, 0, 0, win = x11.XCreateWindow(dpy, parent, 0, 0,
w, h, 2, depth, InputOutput, visual, CWColormap | CWBorderPixel | CWBackPixel, &wa); w, h, 2, depth, InputOutput, visual, CWColormap | CWBorderPixel | CWBackPixel, &wa);
...@@ -1166,11 +1166,11 @@ send_fullscreen(bool set, int x, int y) ...@@ -1166,11 +1166,11 @@ send_fullscreen(bool set, int x, int y)
saved_xpos -= l; saved_xpos -= l;
saved_ypos -= t; saved_ypos -= t;
} }
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
saved_width = vstat.winwidth; saved_width = vstat.winwidth;
saved_height = vstat.winheight; saved_height = vstat.winheight;
saved_scaling = vstat.scaling; saved_scaling = vstat.scaling;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
} }
ret = x11.XSendEvent(dpy, root, False, SubstructureNotifyMask | SubstructureRedirectMask, &ev) != 0; ret = x11.XSendEvent(dpy, root, False, SubstructureNotifyMask | SubstructureRedirectMask, &ev) != 0;
if (ret) { if (ret) {
...@@ -1199,7 +1199,8 @@ static void resize_window() ...@@ -1199,7 +1199,8 @@ static void resize_window()
*/ */
if (fullscreen || fullscreen_pending) if (fullscreen || fullscreen_pending)
return; return;
pthread_mutex_lock(&vstatlock); // We can lokely use a rdlock() here, but there's no reason to risk it.
rwlock_wrlock(&vstatlock);
cio_api.mode = CIOLIB_MODE_X; cio_api.mode = CIOLIB_MODE_X;
new_scaling = x_cvstat.scaling; new_scaling = x_cvstat.scaling;
bitmap_get_scaled_win_size(new_scaling, &width, &height, 0, 0); bitmap_get_scaled_win_size(new_scaling, &width, &height, 0, 0);
...@@ -1213,26 +1214,26 @@ static void resize_window() ...@@ -1213,26 +1214,26 @@ static void resize_window()
if (width == vstat.winwidth && height == vstat.winheight) { if (width == vstat.winwidth && height == vstat.winheight) {
if (new_scaling != vstat.scaling) { if (new_scaling != vstat.scaling) {
vstat.scaling = x_cvstat.scaling = new_scaling; vstat.scaling = x_cvstat.scaling = new_scaling;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
resize_xim(); resize_xim();
} }
else else
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return; return;
} }
bitmap_get_scaled_win_size(new_scaling, &width, &height, 0, 0); bitmap_get_scaled_win_size(new_scaling, &width, &height, 0, 0);
resize = new_scaling != vstat.scaling || width != vstat.winwidth || height != vstat.winheight; resize = new_scaling != vstat.scaling || width != vstat.winwidth || height != vstat.winheight;
x_cvstat.scaling = vstat.scaling; x_cvstat.scaling = vstat.scaling;
if (resize) { if (resize) {
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
map_window(map_pending); map_window(map_pending);
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
x11.XResizeWindow(dpy, win, width, height); x11.XResizeWindow(dpy, win, width, height);
x_cvstat.winwidth = vstat.winwidth = width; x_cvstat.winwidth = vstat.winwidth = width;
x_cvstat.winheight = vstat.winheight = height; x_cvstat.winheight = vstat.winheight = height;
vstat.scaling = x_cvstat.scaling = bitmap_double_mult_inside(width, height); vstat.scaling = x_cvstat.scaling = bitmap_double_mult_inside(width, height);
} }
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
resize_xim(); resize_xim();
return; return;
...@@ -1245,7 +1246,7 @@ static void init_mode_internal(int mode) ...@@ -1245,7 +1246,7 @@ static void init_mode_internal(int mode)
x11_get_maxsize(&mw, &mh); x11_get_maxsize(&mw, &mh);
free_last(); free_last();
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
double os = vstat.scaling; double os = vstat.scaling;
int ow = vstat.winwidth; int ow = vstat.winwidth;
int oh = vstat.winheight; int oh = vstat.winheight;
...@@ -1255,29 +1256,29 @@ static void init_mode_internal(int mode) ...@@ -1255,29 +1256,29 @@ static void init_mode_internal(int mode)
vstat.scaling = os; vstat.scaling = os;
vstat.winwidth = ow; vstat.winwidth = ow;
vstat.winheight = oh; vstat.winheight = oh;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
resize_window(); resize_window();
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
x_cvstat = vstat; x_cvstat = vstat;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
resize_xim(); resize_xim();
map_window(map_pending); map_window(map_pending);
} }
static void check_scaling(void) static void check_scaling(void)
{ {
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
pthread_mutex_lock(&scalinglock); pthread_mutex_lock(&scalinglock);
if (newscaling != 0) { if (newscaling != 0) {
x_cvstat.scaling = newscaling; x_cvstat.scaling = newscaling;
newscaling = 0.0; newscaling = 0.0;
pthread_mutex_unlock(&scalinglock); pthread_mutex_unlock(&scalinglock);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
resize_window(); resize_window();
} }
else { else {
pthread_mutex_unlock(&scalinglock); pthread_mutex_unlock(&scalinglock);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
} }
} }
...@@ -1294,7 +1295,7 @@ static int video_init() ...@@ -1294,7 +1295,7 @@ static int video_init()
{ {
int w, h; int w, h;
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
x_internal_scaling = (ciolib_initial_scaling_type == CIOLIB_SCALING_INTERNAL); x_internal_scaling = (ciolib_initial_scaling_type == CIOLIB_SCALING_INTERNAL);
if (ciolib_initial_scaling != 0.0) { if (ciolib_initial_scaling != 0.0) {
if (ciolib_initial_scaling < 1.0) { if (ciolib_initial_scaling < 1.0) {
...@@ -1310,11 +1311,11 @@ static int video_init() ...@@ -1310,11 +1311,11 @@ static int video_init()
if (x_cvstat.scaling < 1.0 || vstat.scaling < 1.0) if (x_cvstat.scaling < 1.0 || vstat.scaling < 1.0)
x_cvstat.scaling = vstat.scaling = 1.0; x_cvstat.scaling = vstat.scaling = 1.0;
if(load_vmode(&vstat, ciolib_initial_mode)) { if(load_vmode(&vstat, ciolib_initial_mode)) {
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
return(-1); return(-1);
} }
x_cvstat = vstat; x_cvstat = vstat;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
if(init_window()) if(init_window())
return(-1); return(-1);
bitmap_drv_init(x11_drawrect, x11_flush); bitmap_drv_init(x11_drawrect, x11_flush);
...@@ -1347,14 +1348,14 @@ local_draw_rect(struct rectlist *rect) ...@@ -1347,14 +1348,14 @@ local_draw_rect(struct rectlist *rect)
} }
// Scale... // Scale...
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
if (x_cvstat.winwidth != vstat.winwidth || x_cvstat.winheight != vstat.winheight) { if (x_cvstat.winwidth != vstat.winwidth || x_cvstat.winheight != vstat.winheight) {
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
bitmap_drv_free_rect(rect); bitmap_drv_free_rect(rect);
return; return;
} }
bitmap_get_scaled_win_size(vstat.scaling, &w, &h, vstat.winwidth, vstat.winheight); bitmap_get_scaled_win_size(vstat.scaling, &w, &h, vstat.winwidth, vstat.winheight);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
if (w < rect->rect.width || h < rect->rect.height) { if (w < rect->rect.width || h < rect->rect.height) {
bitmap_drv_free_rect(rect); bitmap_drv_free_rect(rect);
return; return;
...@@ -1379,10 +1380,10 @@ local_draw_rect(struct rectlist *rect) ...@@ -1379,10 +1380,10 @@ local_draw_rect(struct rectlist *rect)
dh = rect->rect.height; dh = rect->rect.height;
} }
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
w = vstat.winwidth; w = vstat.winwidth;
h = vstat.winheight; h = vstat.winheight;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
xoff = (w - cleft) / 2; xoff = (w - cleft) / 2;
if (xoff < 0) if (xoff < 0)
xoff = 0; xoff = 0;
...@@ -1505,21 +1506,21 @@ local_draw_rect(struct rectlist *rect) ...@@ -1505,21 +1506,21 @@ local_draw_rect(struct rectlist *rect)
static void handle_resize_event(int width, int height, bool map) static void handle_resize_event(int width, int height, bool map)
{ {
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
x_cvstat.winwidth = vstat.winwidth = width; x_cvstat.winwidth = vstat.winwidth = width;
x_cvstat.winheight = vstat.winheight = height; x_cvstat.winheight = vstat.winheight = height;
vstat.scaling = x_cvstat.scaling = bitmap_double_mult_inside(width, height); vstat.scaling = x_cvstat.scaling = bitmap_double_mult_inside(width, height);
if (vstat.scaling > 16) if (vstat.scaling > 16)
vstat.scaling = 16; vstat.scaling = 16;
x_cvstat.scaling = vstat.scaling; x_cvstat.scaling = vstat.scaling;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
resize_xim(); resize_xim();
bitmap_drv_request_pixels(); bitmap_drv_request_pixels();
if (!got_first_resize) { if (!got_first_resize) {
if (!fullscreen) { if (!fullscreen) {
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
vstat.scaling = bitmap_double_mult_inside(width, height); vstat.scaling = bitmap_double_mult_inside(width, height);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
resize_window(); resize_window();
} }
} }
...@@ -1536,12 +1537,12 @@ static void expose_rect(int x, int y, int width, int height) ...@@ -1536,12 +1537,12 @@ static void expose_rect(int x, int y, int width, int height)
fprintf(stderr, "Exposing NULL xim!\n"); fprintf(stderr, "Exposing NULL xim!\n");
return; return;
} }
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
w = vstat.winwidth; w = vstat.winwidth;
h = vstat.winheight; h = vstat.winheight;
s = vstat.scaling; s = vstat.scaling;
bitmap_get_scaled_win_size(s, &sw, &sh, 0, 0); bitmap_get_scaled_win_size(s, &sw, &sh, 0, 0);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
xoff = (w - sw) / 2; xoff = (w - sw) / 2;
if (xoff < 0) if (xoff < 0)
xoff = 0; xoff = 0;
...@@ -1565,7 +1566,7 @@ xlat_mouse_xy(int *x, int *y) ...@@ -1565,7 +1566,7 @@ xlat_mouse_xy(int *x, int *y)
int xoff, yoff; int xoff, yoff;
int xw, xh; int xw, xh;
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
bitmap_get_scaled_win_size(vstat.scaling, &xw, &xh, 0, 0); bitmap_get_scaled_win_size(vstat.scaling, &xw, &xh, 0, 0);
xoff = (vstat.winwidth - xw) / 2; xoff = (vstat.winwidth - xw) / 2;
if (xoff < 0) if (xoff < 0)
...@@ -1573,7 +1574,7 @@ xlat_mouse_xy(int *x, int *y) ...@@ -1573,7 +1574,7 @@ xlat_mouse_xy(int *x, int *y)
yoff = (vstat.winheight - xh) / 2; yoff = (vstat.winheight - xh) / 2;
if (yoff < 0) if (yoff < 0)
yoff = 0; yoff = 0;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
if (*x < xoff) if (*x < xoff)
*x = xoff; *x = xoff;
...@@ -1656,10 +1657,10 @@ handle_configuration(int w, int h, bool map, bool se) ...@@ -1656,10 +1657,10 @@ handle_configuration(int w, int h, bool map, bool se)
{ {
bool resize = false; bool resize = false;
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
if (w != vstat.winwidth || h != vstat.winheight) if (w != vstat.winwidth || h != vstat.winheight)
resize = true; resize = true;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
if (resize) if (resize)
handle_resize_event(w, h, map); handle_resize_event(w, h, map);
if (w && h && !se) if (w && h && !se)
...@@ -1749,7 +1750,7 @@ x11_event(XEvent *ev) ...@@ -1749,7 +1750,7 @@ x11_event(XEvent *ev)
resize = false; resize = false;
if (fullscreen) { if (fullscreen) {
fullscreen = false; fullscreen = false;
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
x_cvstat.scaling = saved_scaling; x_cvstat.scaling = saved_scaling;
/* /*
* Mode may have changed while in fullscreen... recalculate scaling to * Mode may have changed while in fullscreen... recalculate scaling to
...@@ -1758,7 +1759,7 @@ x11_event(XEvent *ev) ...@@ -1758,7 +1759,7 @@ x11_event(XEvent *ev)
bitmap_get_scaled_win_size(saved_scaling, &w, &h, saved_width, saved_height); bitmap_get_scaled_win_size(saved_scaling, &w, &h, saved_width, saved_height);
if (w != vstat.winwidth || h != vstat.winheight) if (w != vstat.winwidth || h != vstat.winheight)
resize = true; resize = true;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
x_cvstat.winwidth = w; x_cvstat.winwidth = w;
x_cvstat.winheight = h; x_cvstat.winheight = h;
x_cvstat.scaling = bitmap_double_mult_inside(w, h); x_cvstat.scaling = bitmap_double_mult_inside(w, h);
...@@ -2200,9 +2201,9 @@ x11_event(XEvent *ev) ...@@ -2200,9 +2201,9 @@ x11_event(XEvent *ev)
if (ival < 7.0) { if (ival < 7.0) {
int mw, mh, ms; int mw, mh, ms;
x11_get_maxsize(&mw,&mh); x11_get_maxsize(&mw,&mh);
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
ms = bitmap_largest_mult_inside(mw, mh); ms = bitmap_largest_mult_inside(mw, mh);
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
if (ival + 1 <= ms) if (ival + 1 <= ms)
x_setscaling(ival + 1); x_setscaling(ival + 1);
} }
......
...@@ -7833,10 +7833,10 @@ rv_reset(const char * const var, const void * const data) ...@@ -7833,10 +7833,10 @@ rv_reset(const char * const var, const void * const data)
   
// TODO: Figure out what all gets reset here... // TODO: Figure out what all gets reset here...
rip.color = 0; rip.color = 0;
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
rip.x_max = vstat.scrnwidth; rip.x_max = vstat.scrnwidth;
rip.y_max = vstat.scrnheight; rip.y_max = vstat.scrnheight;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
rip.x_dim = 640; rip.x_dim = 640;
rip.y_dim = 350; rip.y_dim = 350;
if (rip.x_max > rip.x_dim) if (rip.x_max > rip.x_dim)
...@@ -8095,10 +8095,10 @@ rv_termset(const char * const var, const void * const data) ...@@ -8095,10 +8095,10 @@ rv_termset(const char * const var, const void * const data)
case 'M': case 'M':
rip.x_dim = 640; rip.x_dim = 640;
rip.y_dim = 350; rip.y_dim = 350;
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
rip.x_max = vstat.scrnwidth; rip.x_max = vstat.scrnwidth;
rip.y_max = vstat.scrnheight; rip.y_max = vstat.scrnheight;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
if (rip.x_max > rip.x_dim) if (rip.x_max > rip.x_dim)
rip.x_max = rip.x_dim; rip.x_max = rip.x_dim;
if (rip.y_max > rip.y_dim) if (rip.y_max > rip.y_dim)
...@@ -8154,11 +8154,11 @@ rv_termset(const char * const var, const void * const data) ...@@ -8154,11 +8154,11 @@ rv_termset(const char * const var, const void * const data)
int width; int width;
int height; int height;
   
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
font = vstat.forced_font; font = vstat.forced_font;
width = vstat.charwidth; width = vstat.charwidth;
height = vstat.charheight; height = vstat.charheight;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
switch (var[5]) { switch (var[5]) {
case 'F': case 'F':
gettextinfo(&ti); gettextinfo(&ti);
...@@ -10130,7 +10130,7 @@ reinit_screen(uint8_t *font, int fx, int fy) ...@@ -10130,7 +10130,7 @@ reinit_screen(uint8_t *font, int fx, int fy)
cols = 91; cols = 91;
if (font == ripfnt16x14) if (font == ripfnt16x14)
cols = 40; cols = 40;
pthread_mutex_lock(&vstatlock); rwlock_wrlock(&vstatlock);
fh_change = fy != vstat.charheight; fh_change = fy != vstat.charheight;
rows = vstat.scrnheight / fy; rows = vstat.scrnheight / fy;
if ((font != vstat.forced_font) || (fx != vstat.charwidth) || (fy != vstat.charheight)) { if ((font != vstat.forced_font) || (fx != vstat.charwidth) || (fy != vstat.charheight)) {
...@@ -10165,7 +10165,7 @@ reinit_screen(uint8_t *font, int fx, int fy) ...@@ -10165,7 +10165,7 @@ reinit_screen(uint8_t *font, int fx, int fy)
// And use it. // And use it.
vstat.vmem->vmem = nvmem; vstat.vmem->vmem = nvmem;
} }
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
   
// Initialize it... // Initialize it...
clrscr(); clrscr();
...@@ -10856,7 +10856,7 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs) ...@@ -10856,7 +10856,7 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
break; break;
GET_XY2(); GET_XY2();
arg1 = parse_mega(&args[8], 2); arg1 = parse_mega(&args[8], 2);
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
if ((vstat.scrnwidth == 640) && (vstat.scrnheight == 350)) { if ((vstat.scrnwidth == 640) && (vstat.scrnheight == 350)) {
// Detect EGA mode and use the same value as RIPterm // Detect EGA mode and use the same value as RIPterm
// did. // did.
...@@ -10868,7 +10868,7 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs) ...@@ -10868,7 +10868,7 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
/ ((double)vstat.aspect_width / ((double)vstat.aspect_width
/ vstat.aspect_height); / vstat.aspect_height);
} }
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
full_ellipse(x1, y1, x2, y2, arg1, arg3, false, full_ellipse(x1, y1, x2, y2, arg1, arg3, false,
map_rip_color(rip.color)); map_rip_color(rip.color));
break; break;
...@@ -10917,7 +10917,7 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs) ...@@ -10917,7 +10917,7 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
break; break;
GET_XY(); GET_XY();
arg1 = parse_mega(&args[4], 2); arg1 = parse_mega(&args[4], 2);
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
if ((vstat.scrnwidth == 640) && (vstat.scrnheight == 350)) { if ((vstat.scrnwidth == 640) && (vstat.scrnheight == 350)) {
// Detect EGA mode and use the same value as RIPterm // Detect EGA mode and use the same value as RIPterm
// did. // did.
...@@ -10929,7 +10929,7 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs) ...@@ -10929,7 +10929,7 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
/ ((double)vstat.aspect_width / ((double)vstat.aspect_width
/ vstat.aspect_height); / vstat.aspect_height);
} }
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
if (arg1 == 1) if (arg1 == 1)
arg3 = 1; arg3 = 1;
full_ellipse(x1, y1, 0, 360, arg1, arg3, false, full_ellipse(x1, y1, 0, 360, arg1, arg3, false,
...@@ -10982,10 +10982,10 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs) ...@@ -10982,10 +10982,10 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
if ((arg1 < 0) || (arg1 > 255)) if ((arg1 < 0) || (arg1 > 255))
break; break;
arg2 = rip.viewport.ey; arg2 = rip.viewport.ey;
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
if (rip.viewport.ey >= vstat.scrnheight) if (rip.viewport.ey >= vstat.scrnheight)
arg2 = vstat.scrnheight - 1; arg2 = vstat.scrnheight - 1;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
   
struct ciolib_pixels *pix = getpixels(rip.viewport.sx, struct ciolib_pixels *pix = getpixels(rip.viewport.sx,
rip.viewport.sy, rip.viewport.sy,
...@@ -11071,7 +11071,7 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs) ...@@ -11071,7 +11071,7 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
break; break;
GET_XY2(); GET_XY2();
arg1 = parse_mega(&args[8], 2); arg1 = parse_mega(&args[8], 2);
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
if ((vstat.scrnwidth == 640) && (vstat.scrnheight == 350)) { if ((vstat.scrnwidth == 640) && (vstat.scrnheight == 350)) {
// Detect EGA mode and use the same value as RIPterm // Detect EGA mode and use the same value as RIPterm
// did. // did.
...@@ -11083,7 +11083,7 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs) ...@@ -11083,7 +11083,7 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
/ ((double)vstat.aspect_width / ((double)vstat.aspect_width
/ vstat.aspect_height); / vstat.aspect_height);
} }
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
fg = map_rip_color(rip.color) | 0x40000000; fg = map_rip_color(rip.color) | 0x40000000;
full_ellipse(x1, y1, x2, y2, arg1, arg3, false, fg); full_ellipse(x1, y1, x2, y2, arg1, arg3, false, fg);
   
...@@ -11758,10 +11758,10 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs) ...@@ -11758,10 +11758,10 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
GET_XY(); GET_XY();
rip.x_dim = x1; rip.x_dim = x1;
rip.y_dim = y1; rip.y_dim = y1;
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
rip.x_max = vstat.scrnwidth; rip.x_max = vstat.scrnwidth;
rip.y_max = vstat.scrnheight; rip.y_max = vstat.scrnheight;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
if (rip.x_max > rip.x_dim) if (rip.x_max > rip.x_dim)
rip.x_max = rip.x_dim; rip.x_max = rip.x_dim;
if (rip.y_max > rip.y_dim) if (rip.y_max > rip.y_dim)
...@@ -12340,16 +12340,16 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs) ...@@ -12340,16 +12340,16 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
cterm->extattr |= CTERM_EXTATTR_AUTOWRAP; cterm->extattr |= CTERM_EXTATTR_AUTOWRAP;
else else
cterm->extattr &= ~CTERM_EXTATTR_AUTOWRAP; cterm->extattr &= ~CTERM_EXTATTR_AUTOWRAP;
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
if ((x1 == cterm->left_margin - 1) if ((x1 == cterm->left_margin - 1)
&& (x2 == cterm->right_margin - 1) && (x2 == cterm->right_margin - 1)
&& (y1 == cterm->top_margin - 1) && (y1 == cterm->top_margin - 1)
&& (y2 == cterm->bottom_margin - 1) && (y2 == cterm->bottom_margin - 1)
&& (arg2 == vstat.charwidth)) { && (arg2 == vstat.charwidth)) {
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
break; break;
} }
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
switch (arg2) { switch (arg2) {
case 0: case 0:
reinit_screen( reinit_screen(
...@@ -14104,10 +14104,10 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs) ...@@ -14104,10 +14104,10 @@ do_rip_command(int level, int sublevel, int cmd, const char *rawargs)
   
int bline = y1 + rip.viewport.sy int bline = y1 + rip.viewport.sy
+ rip.clipboard->height - 1; + rip.clipboard->height - 1;
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
if (bline >= vstat.scrnheight) if (bline >= vstat.scrnheight)
bline = vstat.scrnheight - 1; bline = vstat.scrnheight - 1;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
if (x1 + rip.viewport.sx + rip.clipboard->width - 1 if (x1 + rip.viewport.sx + rip.clipboard->width - 1
> rip.viewport.ex) > rip.viewport.ex)
break; break;
...@@ -16224,10 +16224,10 @@ init_rip(struct bbslist *bbs) ...@@ -16224,10 +16224,10 @@ init_rip(struct bbslist *bbs)
rip.line_width = 1; rip.line_width = 1;
rip.x_dim = 640; rip.x_dim = 640;
if (cio_api.options & CONIO_OPT_SET_PIXEL) { if (cio_api.options & CONIO_OPT_SET_PIXEL) {
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
rip.x_max = vstat.scrnwidth; rip.x_max = vstat.scrnwidth;
rip.y_max = vstat.scrnheight; rip.y_max = vstat.scrnheight;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
if (rip.x_max > rip.x_dim) if (rip.x_max > rip.x_dim)
rip.x_max = rip.x_dim; rip.x_max = rip.x_dim;
rip.y_dim = 350; rip.y_dim = 350;
...@@ -16249,11 +16249,11 @@ init_rip(struct bbslist *bbs) ...@@ -16249,11 +16249,11 @@ init_rip(struct bbslist *bbs)
* members being set inside the lock as * members being set inside the lock as
* an indication that they must be. * an indication that they must be.
*/ */
pthread_mutex_lock(&vstatlock); rwlock_rdlock(&vstatlock);
void *tmp_font = vstat.forced_font; void *tmp_font = vstat.forced_font;
int tmp_width = vstat.charwidth; int tmp_width = vstat.charwidth;
int tmp_height = vstat.charheight; int tmp_height = vstat.charheight;
pthread_mutex_unlock(&vstatlock); rwlock_unlock(&vstatlock);
rip.default_font = tmp_font; rip.default_font = tmp_font;
rip.default_font_width = tmp_width; rip.default_font_width = tmp_width;
rip.default_font_height = tmp_height; rip.default_font_height = tmp_height;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment