Skip to content

Commit

Permalink
fix: 修改fix lock issue to fix block on first run (armink#295)的实现
Browse files Browse the repository at this point in the history
虽然#295的实现可以解决首次调用fdb_kvdb_init死锁的问题,但先unlock再lock没有必要,原因如下:因为fdb_kvdb_init中加锁,其调用的_fdb_kv_load中的fdb_kv_set_default中又加锁,如果不用嵌套互斥锁会发生死锁,而fdb_kv_set_default函数只在_fdb_kv_load中调用,因此将其加减锁代码删除即可
  • Loading branch information
wangtao committed May 20, 2024
1 parent 60675db commit 725b23a
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/fdb_kvdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@ fdb_err_t fdb_kv_set_default(fdb_kvdb_t db)
struct kvdb_sec_info sector;

/* lock the KV cache */
db_lock(db);
// db_lock(db);

#ifdef FDB_KV_USING_CACHE
for (i = 0; i < FDB_KV_CACHE_TABLE_SIZE; i++) {
Expand Down Expand Up @@ -1430,7 +1430,7 @@ fdb_err_t fdb_kv_set_default(fdb_kvdb_t db)
__exit:
db_oldest_addr(db) = 0;
/* unlock the KV cache */
db_unlock(db);
// db_unlock(db);

return result;
}
Expand Down Expand Up @@ -1798,11 +1798,9 @@ fdb_err_t fdb_kvdb_init(fdb_kvdb_t db, const char *name, const char *path, struc
#endif /* FDB_KV_USING_CACHE */

FDB_DEBUG("KVDB size is %" PRIu32 " bytes.\n", db_max_size(db));
db_unlock(db);


result = _fdb_kv_load(db);

db_lock(db);

#ifdef FDB_KV_AUTO_UPDATE
if (result == FDB_NO_ERR) {
kv_auto_update(db);
Expand Down

0 comments on commit 725b23a

Please sign in to comment.