From eb60a1a27066a289437c541b605da103dc5b71e4 Mon Sep 17 00:00:00 2001
From: Recolic Keghart <root@recolic.net>
Date: Wed, 1 Jan 2020 18:49:20 -0800
Subject: [PATCH] Temporarily disable async

---
 nemu/src/device/device.cc | 11 ++++++++---
 nemu/src/device/vga.cc    |  5 ++++-
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/nemu/src/device/device.cc b/nemu/src/device/device.cc
index b36ae40..667f0c9 100644
--- a/nemu/src/device/device.cc
+++ b/nemu/src/device/device.cc
@@ -40,9 +40,12 @@ static void timer_sig_handler(int signum) {
   Assert(ret == 0, "Can not set timer");
 }
 
-void device_update() {} // Now an independent thread will do it.
-
 void device_update_impl() {
+    // async
+    if(device_update_flag)
+        device_update_flag = false;
+    else
+        return;
   if (update_screen_flag) {
     update_screen();
     update_screen_flag = false;
@@ -72,6 +75,8 @@ void device_update_impl() {
   }
 }
 
+void device_update() {device_update_impl();}
+
 static void device_update_thread_daemon() {
   while(true) {
     if(device_update_flag.exchange(false)) {
@@ -104,7 +109,7 @@ void init_device() {
   ret = setitimer(ITIMER_VIRTUAL, &it, NULL);
   Assert(ret == 0, "Can not set timer");
 
-  std::thread(device_update_thread_daemon).detach();
+  // std::thread(device_update_thread_daemon).detach();
 }
 #else
 
diff --git a/nemu/src/device/vga.cc b/nemu/src/device/vga.cc
index 8095b78..4529e8e 100644
--- a/nemu/src/device/vga.cc
+++ b/nemu/src/device/vga.cc
@@ -19,9 +19,11 @@ static uint32_t (*vmem) [SCREEN_W];
 static uint32_t *screensize_port_base;
 
 inline void SDL_ErrorCheck(int ret) {
+#ifdef DEBUG
   if(ret != 0) {
     rlib::println("SDL_Error: ret=", ret, ", GETERR=", SDL_GetError());
   }
+#endif
 }
 
 static void init_vga_impl() {
@@ -38,7 +40,7 @@ static void init_vga_impl() {
 
 void update_screen() {
 #ifndef DISABLE_MMIO
-  if(window == nullptr) init_vga_impl();
+  // if(window == nullptr) init_vga_impl();
   SDL_ErrorCheck(SDL_UpdateTexture(texture, NULL, vmem, SCREEN_W * sizeof(vmem[0][0])));
   SDL_ErrorCheck(SDL_RenderClear(renderer));
   SDL_ErrorCheck(SDL_RenderCopy(renderer, texture, NULL, NULL));
@@ -49,6 +51,7 @@ void update_screen() {
 void init_vga() {
   // Because of fucking SDL design, vga_init should be done in updating thread.
   // Do nothing in main thread.
+  init_vga_impl();
 }
 
 #endif	/* HAS_IOE */
-- 
GitLab