From 38e7d99d2f40d77e4dfcab8f80b0951d73b4f9f5 Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Wed, 27 May 2020 00:59:49 +0800 Subject: [PATCH] change light_sensor to atomic variable (#1560) old-commit-hash: b3ab7ae3921e19c237284ec02683e739e68387f3 --- selfdrive/ui/ui.cc | 5 ++--- selfdrive/ui/ui.hpp | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index 29c866cab0..b573c3f42f 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -208,8 +208,7 @@ static void update_offroad_layout_timeout(UIState *s, int* timeout) { } static void ui_init(UIState *s) { - memset(s, 0, sizeof(UIState)); - + pthread_mutex_init(&s->lock, NULL); s->sm = new SubMaster({"model", "controlsState", "uiLayoutState", "liveCalibration", "radarState", "thermal", "health", "ubloxGnss", "driverState", "dMonitoringState", "offroadLayout" @@ -810,7 +809,7 @@ int main(int argc, char* argv[]) { zsys_handler_set(NULL); signal(SIGINT, (sighandler_t)set_do_exit); - UIState uistate; + UIState uistate = {}; UIState *s = &uistate; ui_init(s); enable_event_processing(true); diff --git a/selfdrive/ui/ui.hpp b/selfdrive/ui/ui.hpp index 9d3f15fa33..3cab8ee668 100644 --- a/selfdrive/ui/ui.hpp +++ b/selfdrive/ui/ui.hpp @@ -13,7 +13,7 @@ #define NANOVG_GLES3_IMPLEMENTATION #define nvgCreate nvgCreateGLES3 #endif - +#include #include #include "nanovg.h" @@ -269,7 +269,7 @@ typedef struct UIState { bool thermal_started, preview_started; bool vision_seen; - float light_sensor; + std::atomic light_sensor; int touch_fd;