Use ubsan and tsan

This commit is contained in:
blankie 2023-01-17 23:22:12 +07:00
parent 6f5fa39b04
commit 277c9500f9
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
4 changed files with 15 additions and 8 deletions

View File

@ -23,7 +23,7 @@ OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
UNAME_S := $(shell uname -s) UNAME_S := $(shell uname -s)
LINUX_GL_LIBS = -lGL LINUX_GL_LIBS = -lGL
CXXFLAGS += -std=c++20 -I$(IMGUI_DIR) -I$(IMGUI_DIR)/misc/cpp -I$(IMGUI_DIR)/backends -D'IMGUI_USER_CONFIG="../myimconfig.h"' CXXFLAGS += -fsanitize=undefined,thread -std=c++20 -I$(IMGUI_DIR) -I$(IMGUI_DIR)/misc/cpp -I$(IMGUI_DIR)/backends -D'IMGUI_USER_CONFIG="../myimconfig.h"'
# https://t.me/NightShadowsHangout/670691 # https://t.me/NightShadowsHangout/670691
CXXFLAGS += -g -Werror -Wall -Wextra -Wshadow -Wpedantic -Wno-gnu-anonymous-struct -fno-rtti -fPIC -Wconversion -Wno-unused-parameter -Wimplicit-fallthrough CXXFLAGS += -g -Werror -Wall -Wextra -Wshadow -Wpedantic -Wno-gnu-anonymous-struct -fno-rtti -fPIC -Wconversion -Wno-unused-parameter -Wimplicit-fallthrough
LIBS = LIBS =

View File

@ -21,7 +21,7 @@ static void mark_nonblock(int fd) {
} }
LogcatThread::LogcatThread(bool* run_event_loop) { LogcatThread::LogcatThread() {
int fds[2]; int fds[2];
struct epoll_event event = {.events = EPOLLIN | EPOLLET}; struct epoll_event event = {.events = EPOLLIN | EPOLLET};
@ -72,7 +72,7 @@ LogcatThread::LogcatThread(bool* run_event_loop) {
throw_system_error(errsv, "epoll_ctl() for stderr"); throw_system_error(errsv, "epoll_ctl() for stderr");
} }
this->_thread = std::thread(&LogcatThread::_run, this, run_event_loop); this->_thread = std::thread(&LogcatThread::_run, this, this->_stop_source.get_token());
} }
LogcatThread::~LogcatThread() { LogcatThread::~LogcatThread() {
@ -93,14 +93,18 @@ LogcatThread::~LogcatThread() {
} }
} }
void LogcatThread::request_stop() {
this->_stop_source.request_stop();
}
void LogcatThread::join() { void LogcatThread::join() {
this->_thread.join(); this->_thread.join();
} }
void LogcatThread::_run(bool* run_event_loop) { void LogcatThread::_run(std::stop_token stoken) {
struct epoll_event events[EPOLL_MAX_EVENTS]; struct epoll_event events[EPOLL_MAX_EVENTS];
while (*run_event_loop) { while (!stoken.stop_requested()) {
printf("(boop)\n"); printf("(boop)\n");
int ready_fds = epoll_wait(this->_epoll_fd, events, EPOLL_MAX_EVENTS, 1000); int ready_fds = epoll_wait(this->_epoll_fd, events, EPOLL_MAX_EVENTS, 1000);
if (ready_fds == -1) { if (ready_fds == -1) {

View File

@ -8,17 +8,19 @@ public:
LogcatThread(const LogcatThread&) = delete; LogcatThread(const LogcatThread&) = delete;
LogcatThread& operator=(const LogcatThread&) = delete; LogcatThread& operator=(const LogcatThread&) = delete;
LogcatThread(bool* run_event_loop); LogcatThread();
~LogcatThread(); ~LogcatThread();
void request_stop();
void join(); void join();
private: private:
void _run(bool* run_event_loop); void _run(std::stop_token stoken);
int _epoll_fd = -1; int _epoll_fd = -1;
int _stdout_read_fd = -1; int _stdout_read_fd = -1;
int _stdout_write_fd = -1; int _stdout_write_fd = -1;
int _stderr_read_fd = -1; int _stderr_read_fd = -1;
int _stderr_write_fd = -1; int _stderr_write_fd = -1;
std::stop_source _stop_source;
std::thread _thread; std::thread _thread;
}; };

View File

@ -133,7 +133,7 @@ int main(int, char**) {
float config_write_timer = 0.0f; float config_write_timer = 0.0f;
LogcatThread logcat_thread = [&]() { LogcatThread logcat_thread = [&]() {
try { try {
return LogcatThread(&run_event_loop); return LogcatThread();
} catch (const std::exception& e) { } catch (const std::exception& e) {
fprintf(stderr, "Failed to spawn logcat thread: %s\n", e.what()); fprintf(stderr, "Failed to spawn logcat thread: %s\n", e.what());
exit(1); exit(1);
@ -189,6 +189,7 @@ int main(int, char**) {
return 1; return 1;
} }
} }
logcat_thread.request_stop();
logcat_thread.join(); logcat_thread.join();
return 0; return 0;