From fbc8d8ccc3dbb9eeffa085e7d91b42dfba024ec7 Mon Sep 17 00:00:00 2001 From: roynatech2544 Date: Thu, 10 Nov 2022 11:52:38 +0900 Subject: [PATCH] universal7885: libfm: Use std::atomic for thread stopper --- .../fm/default/libfm_slsi-impl/FMDeviceControl.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/universal7885-common/apps/aidl-support/fm/default/libfm_slsi-impl/FMDeviceControl.cpp b/universal7885-common/apps/aidl-support/fm/default/libfm_slsi-impl/FMDeviceControl.cpp index 016e91c..e9d6b2c 100644 --- a/universal7885-common/apps/aidl-support/fm/default/libfm_slsi-impl/FMDeviceControl.cpp +++ b/universal7885-common/apps/aidl-support/fm/default/libfm_slsi-impl/FMDeviceControl.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -17,7 +18,7 @@ namespace fm_radio_slsi { -static bool FMThread = false; +static atomic_bool kShouldRun; static std::thread *poll_thread = nullptr; constexpr const char *FM_DEV_PATH = "/dev/radio0"; @@ -211,7 +212,7 @@ static void fm_thread(int fd) { unsigned char read_buf[FM_RADIO_RDS_DATA_MAX]; int ret; - while (FMThread) { + while (kShouldRun.load()) { ret = fm_poll(fd, &radio_poll); if (ret < 0) { if (ret < FM_FAILURE) @@ -226,7 +227,7 @@ static void fm_thread(int fd) { } void fm_thread_set(const int fd, const bool enable) { - FMThread = enable; + kShouldRun.store(enable); if (enable) { poll_thread = new std::thread(fm_thread, fd); } else {