Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
2fec78bd
Commit
2fec78bd
authored
4 months ago
by
Deucе
Browse files
Options
Downloads
Patches
Plain Diff
Put assert()s around all the locking in bitmap_con.c
parent
c25141c9
No related branches found
No related tags found
No related merge requests found
Pipeline
#7746
passed
4 months ago
Stage: build
Stage: test
Stage: cleanup
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/conio/bitmap_con.c
+74
-58
74 additions, 58 deletions
src/conio/bitmap_con.c
with
74 additions
and
58 deletions
src/conio/bitmap_con.c
+
74
−
58
View file @
2fec78bd
...
...
@@ -67,6 +67,24 @@ static int dbg_pthread_mutex_trylock(pthread_mutex_t *lptr, unsigned line)
#define pthread_mutex_unlock(a) dbg_pthread_mutex_unlock(a, __LINE__)
#define pthread_mutex_trylock(a) dbg_pthread_trymutex_lock(a, __LINE__)
#else
#ifndef NDEBUG
#define pthread_mutex_lock(a) assert(pthread_mutex_lock(a) == 0)
#define pthread_mutex_unlock(a) assert(pthread_mutex_unlock(a) == 0)
#define pthread_mutex_trylock(a) assert(pthread_mutex_trylock(a) == 0)
#endif
#endif
#ifdef NDEBUG
#define do_rwlock_rdlock(lk) rwlock_rdlock(lk)
#define do_rwlock_wrlock(lk) rwlock_wrlock(lk)
#define do_rwlock_unlock(lk) rwlock_unlock(lk)
#define do_rwlock_init(lk) rwlock_init(lk)
#else
#define do_rwlock_rdlock(lk) assert(rwlock_rdlock(lk))
#define do_rwlock_wrlock(lk) assert(rwlock_wrlock(lk))
#define do_rwlock_unlock(lk) assert(rwlock_unlock(lk))
#define do_rwlock_init(lk) assert(rwlock_init(lk))
#endif
/* Structs */
...
...
@@ -390,7 +408,7 @@ static void cb_drawrect(struct rectlist *data)
* 4) If vstat.curs_blinks is false, the cursor does not blink.
* 5) When blinking, the cursor is shown when vstat.blink is true.
*/
rwlock_rdlock
(
&
vstatlock
);
do_
rwlock_rdlock
(
&
vstatlock
);
curs_start
=
vstat
.
curs_start
;
curs_end
=
vstat
.
curs_end
;
curs_row
=
vstat
.
curs_row
;
...
...
@@ -398,7 +416,7 @@ static void cb_drawrect(struct rectlist *data)
charheight
=
vstat
.
charheight
;
charwidth
=
vstat
.
charwidth
;
if
(
cursor_visible_locked
())
{
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
cv
=
color_value
(
ciolib_fg
);
for
(
y
=
curs_start
;
y
<=
curs_end
;
y
++
)
{
pixel
=
&
data
->
data
[((
curs_row
-
1
)
*
charheight
+
y
)
*
data
->
rect
.
width
+
(
curs_col
-
1
)
*
charwidth
];
...
...
@@ -408,7 +426,7 @@ static void cb_drawrect(struct rectlist *data)
}
}
else
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
pthread_mutex_lock
(
&
callbacks
.
lock
);
callbacks
.
drawrect
(
data
);
callbacks
.
rects
++
;
...
...
@@ -422,9 +440,9 @@ static void request_redraw_locked(void)
static
void
request_redraw
(
void
)
{
rwlock_wrlock
(
&
vstatlock
);
do_
rwlock_wrlock
(
&
vstatlock
);
request_redraw_locked
();
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
}
/*
...
...
@@ -908,10 +926,10 @@ static int check_redraw(void)
{
int
ret
;
rwlock_wrlock
(
&
vstatlock
);
do_
rwlock_wrlock
(
&
vstatlock
);
ret
=
force_redraws
;
force_redraws
=
0
;
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
return
ret
;
}
...
...
@@ -936,7 +954,7 @@ bpid = pthread_self();
SLEEP
(
10
);
count
++
;
rwlock_wrlock
(
&
vstatlock
);
do_
rwlock_wrlock
(
&
vstatlock
);
if
(
count
==
25
)
{
curs_changed
=
cursor_visible_locked
();
if
(
vstat
.
curs_blink
)
...
...
@@ -962,7 +980,7 @@ bpid = pthread_self();
lfc
=
force_cursor
;
force_cursor
=
0
;
blink
=
vstat
.
blink
;
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
if
(
check_redraw
())
{
if
(
update_from_vmem
(
TRUE
))
...
...
@@ -1081,15 +1099,15 @@ static int update_from_vmem(int force)
if
(
!
bitmap_initialized
)
return
(
-
1
);
rwlock_wrlock
(
&
vstatlock
);
do_
rwlock_wrlock
(
&
vstatlock
);
if
(
vstat
.
vmem
==
NULL
)
{
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
return
-
1
;
}
if
(
vstat
.
vmem
->
vmem
==
NULL
)
{
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
return
-
1
;
}
...
...
@@ -1100,7 +1118,7 @@ static int update_from_vmem(int force)
vs
.
cols
=
0
;
vs
.
rows
=
0
;
free
(
bitmap_drawn
);
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
return
-
1
;
}
bitmap_drawn
=
newl
;
...
...
@@ -1165,7 +1183,7 @@ static int update_from_vmem(int force)
}
release_vmem
(
vmem_ptr
);
vs
=
vstat
;
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
return
(
0
);
}
...
...
@@ -1197,7 +1215,7 @@ int bitmap_puttext(int sx, int sy, int ex, int ey, void *fill)
return
(
0
);
}
rwlock_wrlock
(
&
vstatlock
);
do_
rwlock_wrlock
(
&
vstatlock
);
vmem_ptr
=
get_vmem
(
&
vstat
);
for
(
y
=
sy
-
1
;
y
<
ey
;
y
++
)
{
for
(
x
=
sx
-
1
;
x
<
ex
;
x
++
)
{
...
...
@@ -1205,7 +1223,7 @@ int bitmap_puttext(int sx, int sy, int ex, int ey, void *fill)
}
}
release_vmem
(
vmem_ptr
);
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
return
ret
;
}
...
...
@@ -1214,9 +1232,9 @@ bitmap_vmem_puttext(int sx, int sy, int ex, int ey, struct vmem_cell *fill)
{
int
ret
;
rwlock_wrlock
(
&
vstatlock
);
do_
rwlock_wrlock
(
&
vstatlock
);
ret
=
bitmap_vmem_puttext_locked
(
sx
,
sy
,
ex
,
ey
,
fill
);
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
return
ret
;
}
...
...
@@ -1240,7 +1258,7 @@ int bitmap_vmem_gettext(int sx, int sy, int ex, int ey, struct vmem_cell *fill)
return
(
0
);
}
rwlock_rdlock
(
&
vstatlock
);
do_
rwlock_rdlock
(
&
vstatlock
);
vmem_ptr
=
get_vmem
(
&
vstat
);
for
(
y
=
sy
-
1
;
y
<
ey
;
y
++
)
{
struct
vmem_cell
*
vc
=
vmem_cell_ptr
(
vmem_ptr
,
sx
-
1
,
y
);
...
...
@@ -1250,7 +1268,7 @@ int bitmap_vmem_gettext(int sx, int sy, int ex, int ey, struct vmem_cell *fill)
}
}
release_vmem
(
vmem_ptr
);
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
return
(
1
);
}
...
...
@@ -1259,7 +1277,7 @@ void bitmap_gotoxy(int x, int y)
if
(
!
bitmap_initialized
)
return
;
/* Move cursor location */
rwlock_wrlock
(
&
vstatlock
);
do_
rwlock_wrlock
(
&
vstatlock
);
if
(
vstat
.
curs_col
!=
x
+
cio_textinfo
.
winleft
-
1
||
vstat
.
curs_row
!=
y
+
cio_textinfo
.
wintop
-
1
)
{
cio_textinfo
.
curx
=
x
;
cio_textinfo
.
cury
=
y
;
...
...
@@ -1268,14 +1286,14 @@ void bitmap_gotoxy(int x, int y)
if
(
cursor_visible_locked
())
force_cursor
=
1
;
}
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
}
void
bitmap_setcursortype
(
int
type
)
{
if
(
!
bitmap_initialized
)
return
;
rwlock_wrlock
(
&
vstatlock
);
do_
rwlock_wrlock
(
&
vstatlock
);
switch
(
type
)
{
case
_NOCURSOR
:
vstat
.
curs_start
=
0xff
;
...
...
@@ -1292,7 +1310,7 @@ void bitmap_setcursortype(int type)
force_cursor
=
1
;
break
;
}
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
}
int
bitmap_setfont
(
int
font
,
int
force
,
int
font_num
)
...
...
@@ -1320,7 +1338,7 @@ int bitmap_setfont(int font, int force, int font_num)
else
if
(
conio_fontdata
[
font
].
eight_by_eight
!=
NULL
)
newmode
=
C80X50
;
rwlock_wrlock
(
&
vstatlock
);
do_
rwlock_wrlock
(
&
vstatlock
);
switch
(
vstat
.
charheight
)
{
case
8
:
if
(
conio_fontdata
[
font
].
eight_by_eight
==
NULL
)
{
...
...
@@ -1378,7 +1396,7 @@ int bitmap_setfont(int font, int force, int font_num)
new
=
malloc
(
ti
.
screenwidth
*
ti
.
screenheight
*
sizeof
(
*
new
));
if
(
!
new
)
{
free
(
old
);
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
return
0
;
}
pold
=
old
;
...
...
@@ -1424,11 +1442,11 @@ int bitmap_setfont(int font, int force, int font_num)
}
}
bitmap_loadfont_locked
(
NULL
);
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
return
(
1
);
error_return:
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
return
(
0
);
}
...
...
@@ -1450,9 +1468,9 @@ int bitmap_loadfont(const char *filename)
{
int
ret
;
rwlock_wrlock
(
&
vstatlock
);
do_
rwlock_wrlock
(
&
vstatlock
);
ret
=
bitmap_loadfont_locked
(
filename
);
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
return
ret
;
}
...
...
@@ -1556,7 +1574,7 @@ int bitmap_movetext(int x, int y, int ex, int ey, int tox, int toy)
int
oheight
=
height
;
bool
oscrolldown
=
scrolldown
;
rwlock_wrlock
(
&
vstatlock
);
do_
rwlock_wrlock
(
&
vstatlock
);
vmem_ptr
=
get_vmem
(
&
vstat
);
if
(
width
==
vstat
.
cols
&&
height
>
vstat
.
rows
/
2
&&
toy
==
1
)
{
vmem_ptr
->
top_row
+=
(
y
-
toy
);
...
...
@@ -1594,7 +1612,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
);
release_vmem
(
vmem_ptr
);
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
return
(
1
);
}
...
...
@@ -1610,13 +1628,13 @@ void bitmap_clreol(void)
return
;
row
=
cio_textinfo
.
cury
+
cio_textinfo
.
wintop
-
1
;
rwlock_wrlock
(
&
vstatlock
);
do_
rwlock_wrlock
(
&
vstatlock
);
vmem_ptr
=
get_vmem
(
&
vstat
);
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
);
}
release_vmem
(
vmem_ptr
);
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
}
void
bitmap_clrscr
(
void
)
...
...
@@ -1628,7 +1646,7 @@ void bitmap_clrscr(void)
if
(
!
bitmap_initialized
)
return
;
rwlock_wrlock
(
&
vstatlock
);
do_
rwlock_wrlock
(
&
vstatlock
);
vmem_ptr
=
get_vmem
(
&
vstat
);
rows
=
vstat
.
rows
;
cols
=
vstat
.
cols
;
...
...
@@ -1638,12 +1656,12 @@ void bitmap_clrscr(void)
}
}
release_vmem
(
vmem_ptr
);
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
}
void
bitmap_getcustomcursor
(
int
*
s
,
int
*
e
,
int
*
r
,
int
*
b
,
int
*
v
)
{
rwlock_rdlock
(
&
vstatlock
);
do_
rwlock_rdlock
(
&
vstatlock
);
if
(
s
)
*
s
=
vstat
.
curs_start
;
if
(
e
)
...
...
@@ -1654,14 +1672,14 @@ void bitmap_getcustomcursor(int *s, int *e, int *r, int *b, int *v)
*
b
=
vstat
.
curs_blinks
;
if
(
v
)
*
v
=
vstat
.
curs_visible
;
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
}
void
bitmap_setcustomcursor
(
int
s
,
int
e
,
int
r
,
int
b
,
int
v
)
{
double
ratio
;
rwlock_wrlock
(
&
vstatlock
);
do_
rwlock_wrlock
(
&
vstatlock
);
if
(
r
==
0
)
ratio
=
0
;
else
...
...
@@ -1675,7 +1693,7 @@ void bitmap_setcustomcursor(int s, int e, int r, int b, int v)
if
(
v
>=
0
)
vstat
.
curs_visible
=
v
;
force_cursor
=
1
;
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
}
static
void
...
...
@@ -1698,14 +1716,12 @@ setvideoflags_from_vstat(void)
int
bitmap_getvideoflags
(
void
)
{
int
flags
=
0
;
return
protected_int32_value
(
videoflags
);
}
void
bitmap_setvideoflags
(
int
flags
)
{
rwlock_wrlock
(
&
vstatlock
);
do_
rwlock_wrlock
(
&
vstatlock
);
protected_int32_set
(
&
videoflags
,
flags
);
if
(
flags
&
CIOLIB_VIDEO_BGBRIGHT
)
vstat
.
bright_background
=
1
;
...
...
@@ -1731,16 +1747,16 @@ void bitmap_setvideoflags(int flags)
vstat
.
blink_altcharset
=
1
;
else
vstat
.
blink_altcharset
=
0
;
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
}
int
bitmap_attr2palette
(
uint8_t
attr
,
uint32_t
*
fgp
,
uint32_t
*
bgp
)
{
int
ret
;
rwlock_rdlock
(
&
vstatlock
);
do_
rwlock_rdlock
(
&
vstatlock
);
ret
=
bitmap_attr2palette_locked
(
attr
,
fgp
,
bgp
);
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
return
ret
;
}
...
...
@@ -1748,7 +1764,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
)
{
update_from_vmem
(
FALSE
);
rwlock_wrlock
(
&
vstatlock
);
do_
rwlock_wrlock
(
&
vstatlock
);
struct
vstat_vmem
*
vmem_ptr
=
get_vmem
(
&
vstat
);
struct
vmem_cell
*
vc
=
vmem_cell_ptr
(
vmem_ptr
,
x
/
vstat
.
charwidth
,
y
/
vstat
.
charheight
);
vc
->
bg
|=
0x04000000
;
...
...
@@ -1769,7 +1785,7 @@ int bitmap_setpixel(uint32_t x, uint32_t y, uint32_t colour)
}
}
pthread_mutex_unlock
(
&
screenlock
);
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
return
1
;
}
...
...
@@ -1806,12 +1822,12 @@ int bitmap_setpixels(uint32_t sx, uint32_t sy, uint32_t ex, uint32_t ey, uint32_
}
update_from_vmem
(
FALSE
);
rwlock_wrlock
(
&
vstatlock
);
do_
rwlock_wrlock
(
&
vstatlock
);
struct
vstat_vmem
*
vmem_ptr
=
get_vmem
(
&
vstat
);
pthread_mutex_lock
(
&
screenlock
);
if
(
ex
>
screena
.
screenwidth
||
ey
>
screena
.
screenheight
)
{
pthread_mutex_unlock
(
&
screenlock
);
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
return
0
;
}
...
...
@@ -1875,7 +1891,7 @@ int bitmap_setpixels(uint32_t sx, uint32_t sy, uint32_t ex, uint32_t ey, uint32_
}
pthread_mutex_unlock
(
&
screenlock
);
release_vmem
(
vmem_ptr
);
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
return
1
;
}
...
...
@@ -1936,17 +1952,17 @@ struct ciolib_pixels *bitmap_getpixels(uint32_t sx, uint32_t sy, uint32_t ex, ui
int
bitmap_get_modepalette
(
uint32_t
p
[
16
])
{
rwlock_rdlock
(
&
vstatlock
);
do_
rwlock_rdlock
(
&
vstatlock
);
memcpy
(
p
,
vstat
.
palette
,
sizeof
(
vstat
.
palette
));
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
return
1
;
}
int
bitmap_set_modepalette
(
uint32_t
p
[
16
])
{
rwlock_wrlock
(
&
vstatlock
);
do_
rwlock_wrlock
(
&
vstatlock
);
memcpy
(
vstat
.
palette
,
p
,
sizeof
(
vstat
.
palette
));
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
return
1
;
}
...
...
@@ -2317,17 +2333,17 @@ int bitmap_drv_init(void (*drawrect_cb) (struct rectlist *data)
|
CONIO_OPT_BLOCKY_SCALING
;
protected_int32_init
(
&
videoflags
,
0
);
pthread_mutex_init
(
&
callbacks
.
lock
,
NULL
);
rwlock_init
(
&
vstatlock
);
do_
rwlock_init
(
&
vstatlock
);
pthread_mutex_init
(
&
screenlock
,
NULL
);
pthread_mutex_init
(
&
free_rect_lock
,
NULL
);
rwlock_wrlock
(
&
vstatlock
);
do_
rwlock_wrlock
(
&
vstatlock
);
vstat
.
flags
=
VIDMODES_FLAG_PALETTE_VMEM
;
pthread_mutex_lock
(
&
screenlock
);
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
;
}
pthread_mutex_unlock
(
&
screenlock
);
rwlock_unlock
(
&
vstatlock
);
do_
rwlock_unlock
(
&
vstatlock
);
callbacks
.
drawrect
=
drawrect_cb
;
callbacks
.
flush
=
flush_cb
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment