added mutexes and defers to idb

This commit is contained in:
2025-08-09 21:44:06 +03:00
parent 9396f33288
commit b08ec27629
4 changed files with 207 additions and 152 deletions

View File

@@ -2,42 +2,15 @@
#include "tlibc/errors.h"
#include "tlibc/string/str.h"
#include "tlibc/collections/Array.h"
#include "tlibc/collections/HashMap.h"
typedef struct IncrementalDB IncrementalDB;
typedef struct Table Table;
typedef union Magic32 {
u32 n;
u8 bytes[4];
} Magic32;
typedef struct TableHeader {
Magic32 magic;
u16 version;
bool _dirty_bit;
u32 row_size;
} __attribute__((aligned(256))) TableHeader;
typedef struct Table {
TableHeader header;
IncrementalDB* db;
str name;
str table_file_path;
str changes_file_path;
FILE* table_file;
FILE* changes_file;
u64 row_count;
} Table;
typedef struct IncrementalDB {
str db_dir;
HashMap(Table**) tables_map;
} IncrementalDB;
Result(IncrementalDB*) idb_open(str db_dir);
void idb_close(IncrementalDB* db);
Result(Table*) idb_getOrCreateTable(IncrementalDB* db, str _table_name, u32 row_size);
Result(void) idb_getRows(Table* t, u64 id, void* dst, u64 count);
@@ -48,3 +21,5 @@ Result(u64) idb_pushRows(Table* t, const void* src, u64 count);
Result(void) idb_updateRows(Table* t, u64 id, const void* src, u64 count);
#define idb_updateRow(T, ID, SRC) idb_updateRows(T, ID, SRC, 1)
Result(u64) idb_getRowCount(Table* t);