diff --git a/src/db.zig b/src/db.zig index e28f40f..284a423 100644 --- a/src/db.zig +++ b/src/db.zig @@ -204,7 +204,6 @@ pub const DB = struct { const result = self.tree.get(key); if (result) |dataptr| { - // const entry = result.found; if (value.len == dataptr.size) { return self._inplace_update(value, dataptr); } @@ -294,6 +293,7 @@ pub const DB = struct { } } + /// Calling this function block the database completely. pub fn for_each( self: *DB, allocator: std.mem.Allocator, @@ -301,6 +301,15 @@ pub const DB = struct { ctx_: T, fun: fn (T, []const u8, []const u8) anyerror!bool, ) !void { + try check_is_open(self); + if (!self.deinit_mut.tryLockShared()) { + return error.ClosedDB; + } + defer self.deinit_mut.unlockShared(); + + self.db_mut.lock(); + defer self.db_mut.unlock(); + const ctx_t = struct { db: *DB, allocator: std.mem.Allocator,