[tsdb] add the locker in iterator.

This commit is contained in:
朱天龙 (Armink) 2022-08-27 13:49:08 +08:00
parent 33385f4051
commit ee634fec10
1 changed files with 16 additions and 5 deletions

View File

@ -458,6 +458,7 @@ void fdb_tsl_iter(fdb_tsdb_t db, fdb_tsl_cb cb, void *arg)
}
sec_addr = db->oldest_addr;
db_lock(db);
/* search all sectors */
do {
traversed_len += db_sec_size(db);
@ -476,11 +477,13 @@ void fdb_tsl_iter(fdb_tsdb_t db, fdb_tsl_cb cb, void *arg)
read_tsl(db, &tsl);
/* iterator is interrupted when callback return true */
if (cb(&tsl, arg)) {
db_unlock(db);
return;
}
} while ((tsl.addr.index = get_next_tsl_addr(&sector, &tsl)) != FAILED_ADDR);
}
} while ((sec_addr = get_next_sector_addr(db, &sector, traversed_len)) != FAILED_ADDR);
db_unlock(db);
}
/**
@ -505,6 +508,7 @@ void fdb_tsl_iter_reverse(fdb_tsdb_t db, fdb_tsl_cb cb, void *cb_arg)
}
sec_addr = db->cur_sec.addr;
db_lock(db);
/* search all sectors */
do {
traversed_len += db_sec_size(db);
@ -523,12 +527,15 @@ void fdb_tsl_iter_reverse(fdb_tsdb_t db, fdb_tsl_cb cb, void *cb_arg)
read_tsl(db, &tsl);
/* iterator is interrupted when callback return true */
if (cb(&tsl, cb_arg)) {
return;
goto __exit;
}
} while ((tsl.addr.index = get_last_tsl_addr(&sector, &tsl)) != FAILED_ADDR);
} else if (sector.status == FDB_SECTOR_STORE_EMPTY || sector.status == FDB_SECTOR_STORE_UNUSED)
return;
goto __exit;
} while ((sec_addr = get_last_sector_addr(db, &sector, traversed_len)) != FAILED_ADDR);
__exit:
db_unlock(db);
}
/*
@ -603,6 +610,7 @@ void fdb_tsl_iter_by_time(fdb_tsdb_t db, fdb_time_t from, fdb_time_t to, fdb_tsl
}
sec_addr = start_addr;
db_lock(db);
/* search all sectors */
do {
traversed_len += db_sec_size(db);
@ -633,18 +641,21 @@ void fdb_tsl_iter_by_time(fdb_tsdb_t db, fdb_time_t from, fdb_time_t to, fdb_tsl
|| (from > to && tsl.time <= from && tsl.time >= to)) {
/* iterator is interrupted when callback return true */
if (cb(&tsl, cb_arg)) {
return;
goto __exit;
}
} else {
return;
goto __exit;
}
}
} while ((tsl.addr.index = get_tsl_addr(&sector, &tsl)) != FAILED_ADDR);
}
} else if (sector.status == FDB_SECTOR_STORE_EMPTY) {
return;
goto __exit;
}
} while ((sec_addr = get_sector_addr(db, &sector, traversed_len)) != FAILED_ADDR);
__exit:
db_unlock(db);
}
static bool query_count_cb(fdb_tsl_t tsl, void *arg)