Merge pull request #2 from folkertvanheusden/virtual-func

virtual function called error fix
This commit is contained in:
folkertvanheusden 2022-03-22 22:39:21 +01:00 committed by GitHub
commit cd35192950
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 36 additions and 19 deletions

View file

@ -27,8 +27,8 @@ add_executable(
include(CheckIPOSupported) include(CheckIPOSupported)
check_ipo_supported(RESULT supported) check_ipo_supported(RESULT supported)
set(CMAKE_BUILD_TYPE RelWithDebInfo) #set(CMAKE_BUILD_TYPE RelWithDebInfo)
#set(CMAKE_BUILD_TYPE Debug) set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE) set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE) set(THREADS_PREFER_PTHREAD_FLAG TRUE)

View file

@ -8,10 +8,16 @@
console_esp32::console_esp32(std::atomic_bool *const terminate) : console(terminate) console_esp32::console_esp32(std::atomic_bool *const terminate) : console(terminate)
{ {
th = new std::thread(std::ref(*this));
} }
console_esp32::~console_esp32() console_esp32::~console_esp32()
{ {
if (th) {
th->join();
delete th;
}
} }
int console_esp32::wait_for_char(const int timeout) int console_esp32::wait_for_char(const int timeout)

View file

@ -12,17 +12,10 @@ console::console(std::atomic_bool *const terminate) :
terminate(terminate) terminate(terminate)
{ {
memset(screen_buffer, ' ', sizeof screen_buffer); memset(screen_buffer, ' ', sizeof screen_buffer);
th = new std::thread(std::ref(*this));
} }
console::~console() console::~console()
{ {
if (th) {
th->join();
delete th;
}
} }
bool console::poll_char() bool console::poll_char()

View file

@ -13,8 +13,6 @@ class console
private: private:
std::atomic_bool *const terminate { nullptr }; std::atomic_bool *const terminate { nullptr };
std::thread *th { nullptr };
std::vector<char> input_buffer; std::vector<char> input_buffer;
char screen_buffer[t_height][t_width]; char screen_buffer[t_height][t_width];
@ -22,6 +20,8 @@ private:
uint8_t ty { 0 }; uint8_t ty { 0 };
protected: protected:
std::thread *th { nullptr };
virtual int wait_for_char(const int timeout) = 0; virtual int wait_for_char(const int timeout) = 0;
virtual void put_char_ll(const char c) = 0; virtual void put_char_ll(const char c) = 0;

View file

@ -12,10 +12,18 @@ console_ncurses::console_ncurses(std::atomic_bool *const terminate) : console(te
init_ncurses(true); init_ncurses(true);
resize_terminal(); resize_terminal();
th = new std::thread(std::ref(*this));
} }
console_ncurses::~console_ncurses() console_ncurses::~console_ncurses()
{ {
if (th) {
th->join();
delete th;
}
wprintw(w_main->win, "\n\n *** PRESS ENTER TO TERMINATE ***\n"); wprintw(w_main->win, "\n\n *** PRESS ENTER TO TERMINATE ***\n");
mydoupdate(); mydoupdate();

View file

@ -17,12 +17,21 @@ console_posix::console_posix(std::atomic_bool *const terminate) : console(termin
if (tcsetattr(STDIN_FILENO, TCSANOW, &tty_opts_raw) == -1) if (tcsetattr(STDIN_FILENO, TCSANOW, &tty_opts_raw) == -1)
error_exit(true, "console_posix: tcsetattr failed"); error_exit(true, "console_posix: tcsetattr failed");
th = new std::thread(std::ref(*this));
} }
console_posix::~console_posix() console_posix::~console_posix()
{ {
if (th) {
th->join();
delete th;
}
if (tcsetattr(STDIN_FILENO, TCSANOW, &org_tty_opts) == -1) if (tcsetattr(STDIN_FILENO, TCSANOW, &org_tty_opts) == -1)
error_exit(true, "~console_posix: tcsetattr failed"); error_exit(true, "~console_posix: tcsetattr failed");
} }
int console_posix::wait_for_char(const int timeout) int console_posix::wait_for_char(const int timeout)

View file

@ -6,21 +6,22 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "memory.h" #include "error.h"
#include "console_ncurses.h" #include "console_ncurses.h"
#include "console_posix.h" #include "console_posix.h"
#include "cpu.h" #include "cpu.h"
#include "gen.h"
#include "memory.h"
#include "terminal.h"
#include "tests.h"
#include "tty.h" #include "tty.h"
#include "utils.h" #include "utils.h"
#include "tests.h"
#include "terminal.h"
#include "error.h"
bool withUI { false }; bool withUI { false };
uint32_t event { 0 }; uint32_t event { 0 };
std::atomic_bool terminate { false }; std::atomic_bool terminate { false };
void loadbin(bus *const b, uint16_t base, const char *const file) void loadbin(bus *const b, uint16_t base, const char *const file)
{ {
FILE *fh = fopen(file, "rb"); FILE *fh = fopen(file, "rb");
@ -288,7 +289,7 @@ int main(int argc, char *argv[])
else if (refresh_interval > pdp_11_70_mips) else if (refresh_interval > pdp_11_70_mips)
refresh_interval = pdp_11_70_mips; refresh_interval = pdp_11_70_mips;
fprintf(stderr, "instructions_executed: %u, took_ms: %lu, new refresh_interval: %u\n", icount, took_ms, refresh_interval); D(fprintf(stderr, "instructions_executed: %u, took_ms: %lu, new refresh_interval: %u\n", icount, took_ms, refresh_interval);)
// if (withUI) { // if (withUI) {
// mvwprintw(w_main_b -> win, 0, 24, "%.1f/s ", icount * 1000.0 / took_ms); // mvwprintw(w_main_b -> win, 0, 24, "%.1f/s ", icount * 1000.0 / took_ms);
@ -306,11 +307,11 @@ int main(int argc, char *argv[])
terminate = true; terminate = true;
delete b;
delete cnsl; delete cnsl;
fprintf(stderr, "Instructions per second: %.3f\n\n", icount * 1000.0 / (get_ms() - start)); fprintf(stderr, "Instructions per second: %.3f\n\n", icount * 1000.0 / (get_ms() - start));
delete b;
return 0; return 0;
} }