fix(flush,tick): use atomics instead of volatile for synchronization (#3965)

This commit is contained in:
Fabian
2023-02-14 10:06:58 +01:00
committed by GitHub
parent 56e26f8d4e
commit fc659cdecc
3 changed files with 34 additions and 8 deletions
+16 -6
View File
@@ -23,6 +23,11 @@ extern "C" {
#include "../misc/lv_area.h"
#include "../misc/lv_ll.h"
#include "../misc/lv_timer.h"
#include "../misc/lv_types.h"
#if LV_USE_ATOMICS == 1
#include <stdatomic.h>
#endif
/*********************
* DEFINES
@@ -47,6 +52,11 @@ struct _lv_disp_t;
struct _lv_disp_drv_t;
struct _lv_theme_t;
#if LV_USE_ATOMICS == 1
#define FLUSHING_TYPE atomic_int
#else
#define FLUSHING_TYPE volatile int
#endif
/**
* Structure for holding display buffer information.
*/
@@ -57,13 +67,13 @@ typedef struct _lv_disp_draw_buf_t {
/*Internal, used by the library*/
void * buf_act;
uint32_t size; /*In pixel count*/
/*1: flushing is in progress. (It can't be a bit field because when it's cleared from IRQ Read-Modify-Write issue might occur)*/
volatile int flushing;
/*1: It was the last chunk to flush. (It can't be a bit field because when it's cleared from IRQ Read-Modify-Write issue might occur)*/
volatile int flushing_last;
volatile uint32_t last_area : 1; /*1: the last area is being rendered*/
volatile uint32_t last_part : 1; /*1: the last part of the current area is being rendered*/
FLUSHING_TYPE flushing;
/*It was the last chunk to flush. (It can't be a bit field because when it's cleared from IRQ Read-Modify-Write issue might occur)*/
FLUSHING_TYPE flushing_last;
uint32_t last_area : 1; /*1: the last area is being rendered*/
uint32_t last_part : 1; /*1: the last part of the current area is being rendered*/
} lv_disp_draw_buf_t;
#undef FLUSHING_TYPE
typedef enum {
LV_DISP_ROT_NONE = 0,
+9 -2
View File
@@ -7,6 +7,8 @@
* INCLUDES
*********************/
#include "lv_hal_tick.h"
#include "../misc/lv_types.h"
#include <stdatomic.h>
#include <stddef.h>
#if LV_TICK_CUSTOM == 1
@@ -29,8 +31,13 @@
* STATIC VARIABLES
**********************/
#if !LV_TICK_CUSTOM
static uint32_t sys_time = 0;
static volatile uint8_t tick_irq_flag;
#if LV_USE_ATOMICS == 1
static _Atomic(uint32_t) sys_time = 0;
static atomic_int tick_irq_flag;
#else
static volatile uint32_t sys_time = 0;
static volatile int tick_irq_flag;
#endif
#endif
/**********************
+9
View File
@@ -32,6 +32,15 @@ extern "C" {
#endif
/*Use atomics instead of volatile variables for state which is potentially shared between threads, as long as
*the compiler supports it.*/
#if (defined(__cplusplus) && __cplusplus >= 201103L)\
|| (__STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__))
#define LV_USE_ATOMICS 1
#else
#define LV_USE_ATOMICS 0
#endif
/**********************
* TYPEDEFS
**********************/