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)
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
CXXFLAGS += -g -Werror -Wall -Wextra -Wshadow -Wpedantic -Wno-gnu-anonymous-struct -fno-rtti -fPIC -Wconversion -Wno-unused-parameter -Wimplicit-fallthrough
LIBS =

View File

@ -21,7 +21,7 @@ static void mark_nonblock(int fd) {
}
LogcatThread::LogcatThread(bool* run_event_loop) {
LogcatThread::LogcatThread() {
int fds[2];
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");
}
this->_thread = std::thread(&LogcatThread::_run, this, run_event_loop);
this->_thread = std::thread(&LogcatThread::_run, this, this->_stop_source.get_token());
}
LogcatThread::~LogcatThread() {
@ -93,14 +93,18 @@ LogcatThread::~LogcatThread() {
}
}
void LogcatThread::request_stop() {
this->_stop_source.request_stop();
}
void LogcatThread::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];
while (*run_event_loop) {
while (!stoken.stop_requested()) {
printf("(boop)\n");
int ready_fds = epoll_wait(this->_epoll_fd, events, EPOLL_MAX_EVENTS, 1000);
if (ready_fds == -1) {

View File

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

View File

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