1-修改中控串口数据分析线程操作逻辑为双队列

2-数据库线程添加连续1000调用强制关闭一次数据库以清理内存
This commit is contained in:
sc committed 2026-01-09 01:56:50 +08:00
1 parent efc78addd9
commit 4096b49a15
4 files changed
+31 -27

No files matched your search

+17 -4
View File
@@ -276,6 +276,8 @@ static void db_sqlite(void *parameter) {
// 默认启用数据库
db_enabled = RT_TRUE;
static rt_bool_t first_wait_done = RT_FALSE;
//连续链接次数
rt_int16_t op_link=0;
while (1)
{
// 接收命令
@@ -284,12 +286,23 @@ static void db_sqlite(void *parameter) {
if (first_wait_done)
{
first_wait_done = RT_FALSE;
//sqlite3_exec(g_db, "PRAGMA shrink_memory;", 0, 0, 0);
sqlite3_exec(g_db, "PRAGMA shrink_memory;", 0, 0, 0);
sqlite3_close(g_db);
g_db=RT_NULL;
op_link=0;
}
continue;
}else{first_wait_done = RT_TRUE;}
}else{
if(op_link>1000)
{//连续操作数据库1000次后强制关闭防止内存占用
sqlite3_close(g_db);
g_db=RT_NULL;
op_link=0;
}
op_link++;
first_wait_done = RT_TRUE;
}
//检查排队超时
rt_tick_t now = rt_tick_get();
@@ -328,8 +341,8 @@ static void db_sqlite(void *parameter) {
return_disabled(&cmd);
continue;
} else {
//限制缓存大小 (100KB)
//sqlite3_exec(g_db, "PRAGMA cache_size = -50;", 0, 0, 0);
//限制缓存大小 (KB)
sqlite3_exec(g_db, "PRAGMA cache_size = 8;", 0, 0, 0);
//设置临时存储为文件模式 (节省内存)
//sqlite3_exec(g_db, "PRAGMA temp_store = FILE;", 0, 0, 0);
//rt_kprintf("Opened database: %s\n", DB_NAME);