Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
recolic-hust
hust-x86-simulator
Commits
a6c4f29f
Verified
Commit
a6c4f29f
authored
Dec 29, 2019
by
Recolic Keghart
Browse files
async device update
parent
e568ce53
Pipeline
#800
passed with stages
in 2 minutes and 13 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
nemu/Makefile
View file @
a6c4f29f
...
...
@@ -53,7 +53,7 @@ NEMU_EXEC := $(BINARY) $(ARGS)
$(BINARY)
:
$(OBJS)
$(
call
git_commit,
"compile"
)
@
echo
+ LD
$@
@
$(LD)
-O2
-rdynamic
$(SO_LDLAGS)
-o
$@
$^
-lSDL2
-lreadline
-ldl
@
$(LD)
-O2
-rdynamic
$(SO_LDLAGS)
-o
$@
$^
-lSDL2
-lreadline
-ldl
-pthread
run
:
$(BINARY)
$(
call
git_commit,
"run"
)
...
...
nemu/src/device/device.cc
View file @
a6c4f29f
...
...
@@ -6,13 +6,16 @@
#include
<signal.h>
#include
<SDL2/SDL.h>
#include
<thread>
#include
<atomic>
#define TIMER_HZ 100
#define VGA_HZ 50
static
uint64_t
jiffy
=
0
;
static
struct
itimerval
it
;
static
int
device_update_flag
=
false
;
static
int
update_screen_flag
=
false
;
static
std
::
atomic
<
bool
>
device_update_flag
(
false
)
;
static
std
::
atomic
<
bool
>
update_screen_flag
(
false
)
;
void
init_serial
();
void
init_timer
();
...
...
@@ -37,12 +40,9 @@ static void timer_sig_handler(int signum) {
Assert
(
ret
==
0
,
"Can not set timer"
);
}
void
device_update
()
{
if
(
!
device_update_flag
)
{
return
;
}
device_update_flag
=
false
;
void
device_update
()
{}
// Now an independent thread will do it.
void
device_update_impl
()
{
if
(
update_screen_flag
)
{
update_screen
();
update_screen_flag
=
false
;
...
...
@@ -72,6 +72,16 @@ void device_update() {
}
}
static
void
device_update_thread_daemon
()
{
while
(
true
)
{
if
(
device_update_flag
.
exchange
(
false
))
{
device_update_impl
();
}
// At most, 1000FPS
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
1
));
}
}
void
sdl_clear_event_queue
()
{
SDL_Event
event
;
while
(
SDL_PollEvent
(
&
event
));
...
...
@@ -93,6 +103,8 @@ void init_device() {
it
.
it_value
.
tv_usec
=
1000000
/
TIMER_HZ
;
ret
=
setitimer
(
ITIMER_VIRTUAL
,
&
it
,
NULL
);
Assert
(
ret
==
0
,
"Can not set timer"
);
std
::
thread
(
device_update_thread_daemon
).
detach
();
}
#else
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment