Misc changes throughout the codebase during testing.

This commit is contained in:
Jordan Bancino 2022-10-31 08:12:42 -04:00
parent b24ab05e8b
commit fd50fd83fb
4 changed files with 43 additions and 5 deletions

View file

@ -31,12 +31,19 @@ struct Db
{ {
const char *dir; const char *dir;
size_t cacheSize; size_t cacheSize;
size_t maxCache;
pthread_mutex_t lock; pthread_mutex_t lock;
HashMap *cache;
}; };
struct DbRef struct DbRef
{ {
HashMap *json;
pthread_mutex_t lock; pthread_mutex_t lock;
unsigned long ts;
char *file;
}; };
Db * Db *
@ -56,13 +63,17 @@ DbOpen(const char *dir, size_t cache)
} }
db->dir = dir; db->dir = dir;
db->cacheSize = cache; db->maxCache = cache;
pthread_mutex_init(&db->lock, NULL); pthread_mutex_init(&db->lock, NULL);
if (db->cacheSize) if (db->maxCache)
{ {
db->cache = HashMapCreate();
if (!db->cache)
{
return NULL;
}
} }
return db; return db;
@ -76,29 +87,54 @@ DbClose(Db * db)
return; return;
} }
pthread_mutex_destroy(&db->lock);
HashMapFree(db->cache);
Free(db); Free(db);
} }
DbRef * DbRef *
DbCreate(Db * db, char *prefix, char *key) DbCreate(Db * db, char *prefix, char *key)
{ {
if (!db || !prefix || !key)
{
return NULL;
}
return NULL; return NULL;
} }
DbRef * DbRef *
DbLock(Db * db, char *prefix, char *key) DbLock(Db * db, char *prefix, char *key)
{ {
if (!db || !prefix || !key)
{
return NULL;
}
pthread_mutex_lock(&db->lock);
pthread_mutex_unlock(&db->lock);
return NULL; return NULL;
} }
void void
DbUnlock(Db * db, DbRef * ref) DbUnlock(Db * db, DbRef * ref)
{ {
if (!db || !ref)
{
return;
}
pthread_mutex_lock(&db->lock);
pthread_mutex_unlock(&db->lock);
return; return;
} }
HashMap * HashMap *
DbJson(DbRef * ref) DbJson(DbRef * ref)
{ {
return NULL; return ref ? ref->json : NULL;
} }

View file

@ -122,6 +122,7 @@ HttpServerContextFree(HttpServerContext * c)
while (HashMapIterate(c->requestHeaders, &key, &val)) while (HashMapIterate(c->requestHeaders, &key, &val))
{ {
/* Since we create these, we know they're always on the heap */
Free(key); Free(key);
Free(val); Free(val);
} }

View file

@ -645,6 +645,7 @@ JsonFree(HashMap * object)
while (HashMapIterate(object, &key, (void **) &value)) while (HashMapIterate(object, &key, (void **) &value))
{ {
Free(key);
JsonValueFree(value); JsonValueFree(value);
} }

View file

@ -58,7 +58,7 @@ TelodendriaMemoryHook(MemoryAction a, MemoryInfo * i, void *args)
action = "Freed"; action = "Freed";
break; break;
case MEMORY_BAD_POINTER: case MEMORY_BAD_POINTER:
Log(lc, LOG_WARNING, "Bad pointer passed into a memory function."); Log(lc, LOG_WARNING, "Bad pointer passed into a memory function: %p", (void *) i);
return; return;
default: default:
action = "Unknown operation on"; action = "Unknown operation on";