rename filewatcher struct

This commit is contained in:
2025-03-29 14:12:40 +02:00
parent 89beab3506
commit c9205336c1
3 changed files with 18 additions and 18 deletions

View File

@@ -32,14 +32,14 @@ typedef struct hiWatchPaths {
struct sc_array_watch watches; struct sc_array_watch watches;
} hiWatchPaths; } hiWatchPaths;
typedef struct hiFileWatcherContext { typedef struct hiFileWatcher {
thrd_t thread; thrd_t thread;
mtx_t mutex; mtx_t mutex;
cnd_t cond; cnd_t cond;
int running; int running;
struct hiWatchPaths watchpaths; struct hiWatchPaths watchpaths;
struct hiFileEvents events; struct hiFileEvents events;
} hiFileWatcherContext; } hiFileWatcher;
/* /*
* File Events * File Events
@@ -80,7 +80,7 @@ void hi_file_event_destroy(hiFileEvent *event) {
} }
} }
hiFileEvent hi_file_event_pop(hiFileWatcherContext *ctx) { hiFileEvent hi_file_event_pop(hiFileWatcher *ctx) {
mtx_lock(&ctx->mutex); mtx_lock(&ctx->mutex);
hiFileEvent *last = &sc_array_last(&ctx->events.events); hiFileEvent *last = &sc_array_last(&ctx->events.events);
hiFileEvent e = *last; hiFileEvent e = *last;
@@ -204,11 +204,11 @@ static void watch_paths_destroy(hiWatchPaths *paths) {
// Declare the thread func // Declare the thread func
int file_watcher_watch(void *arg); int file_watcher_watch(void *arg);
hiFileWatcherContext *hi_file_watcher_create() { hiFileWatcher *hi_file_watcher_create() {
// Allocate context // Allocate context
hiFileWatcherContext *context = malloc(sizeof(hiFileWatcherContext)); hiFileWatcher *context = malloc(sizeof(hiFileWatcher));
memset(context, 0, sizeof(hiFileWatcherContext)); memset(context, 0, sizeof(hiFileWatcher));
if (context) { if (context) {
if (!HILOADRES(watch_paths_init(&context->watchpaths))) { if (!HILOADRES(watch_paths_init(&context->watchpaths))) {
@@ -236,7 +236,7 @@ hiFileWatcherContext *hi_file_watcher_create() {
return NULL; return NULL;
} }
HiloadResult hi_file_watcher_add(struct hiFileWatcherContext *ctx, HiloadResult hi_file_watcher_add(struct hiFileWatcher *ctx,
const char *filename, u32 flags) { const char *filename, u32 flags) {
if (!ctx) { if (!ctx) {
sc_log_error("Attempted to add file watcher for '%s' with null context\n", sc_log_error("Attempted to add file watcher for '%s' with null context\n",
@@ -255,7 +255,7 @@ HiloadResult hi_file_watcher_add(struct hiFileWatcherContext *ctx,
return HILOAD_OK; return HILOAD_OK;
} }
HiloadResult hi_file_watcher_remove(struct hiFileWatcherContext *ctx, HiloadResult hi_file_watcher_remove(struct hiFileWatcher *ctx,
const char *filename) { const char *filename) {
if (!ctx) { if (!ctx) {
return HILOAD_FAIL; return HILOAD_FAIL;
@@ -272,13 +272,13 @@ HiloadResult hi_file_watcher_remove(struct hiFileWatcherContext *ctx,
return HILOAD_OK; return HILOAD_OK;
} }
void hi_file_watcher_notify(hiFileWatcherContext *ctx) { void hi_file_watcher_notify(hiFileWatcher *ctx) {
if (ctx && ctx->running) { if (ctx && ctx->running) {
cnd_signal(&ctx->cond); cnd_signal(&ctx->cond);
} }
} }
void hi_file_watcher_destroy(hiFileWatcherContext *ctx) { void hi_file_watcher_destroy(hiFileWatcher *ctx) {
if (!ctx) if (!ctx)
return; return;
@@ -293,7 +293,7 @@ void hi_file_watcher_destroy(hiFileWatcherContext *ctx) {
} }
int file_watcher_watch(void *arg) { int file_watcher_watch(void *arg) {
hiFileWatcherContext *ctx = (hiFileWatcherContext *)arg; hiFileWatcher *ctx = (hiFileWatcher *)arg;
sc_log_set_thread_name("File Watcher"); sc_log_set_thread_name("File Watcher");
char buf[4096] __attribute__((aligned(__alignof__(struct inotify_event)))); char buf[4096] __attribute__((aligned(__alignof__(struct inotify_event))));

View File

@@ -24,7 +24,7 @@ typedef struct {
HiFileEventType type; HiFileEventType type;
} hiFileEvent; } hiFileEvent;
struct hiFileWatcherContext; struct hiFileWatcher;
/** /**
* FileEvents is a thread safe list of events. * FileEvents is a thread safe list of events.
* *
@@ -38,13 +38,13 @@ struct hiFileEvents;
* *
* Will start the watcher thread immediately. * Will start the watcher thread immediately.
*/ */
struct hiFileWatcherContext *hi_file_watcher_create(void); struct hiFileWatcher *hi_file_watcher_create(void);
/** /**
* Destroy a previously created file watcher context. * Destroy a previously created file watcher context.
* *
* Will join the thread and destroy event stack. * Will join the thread and destroy event stack.
*/ */
void hi_file_watcher_destroy(struct hiFileWatcherContext *context); void hi_file_watcher_destroy(struct hiFileWatcher *context);
/** /**
* Add a file to the watch list of a file watcher. * Add a file to the watch list of a file watcher.
* *
@@ -52,13 +52,13 @@ void hi_file_watcher_destroy(struct hiFileWatcherContext *context);
* @param pathname Absolute path to the file or directory * @param pathname Absolute path to the file or directory
* @param flags The events that will be watched for * @param flags The events that will be watched for
*/ */
HiloadResult hi_file_watcher_add(struct hiFileWatcherContext *context, HiloadResult hi_file_watcher_add(struct hiFileWatcher *context,
const char *pathname, u32 flags); const char *pathname, u32 flags);
/** /**
* Can be used to poke file watcher thread to make sure it empties * Can be used to poke file watcher thread to make sure it empties
* events before doing something, e.g. for shutting it down. * events before doing something, e.g. for shutting it down.
*/ */
void hi_file_watcher_notify(struct hiFileWatcherContext *context); void hi_file_watcher_notify(struct hiFileWatcher *context);
/** /**
* Frees held memory but doesn't zero fields * Frees held memory but doesn't zero fields
@@ -68,7 +68,7 @@ void hi_file_event_free(hiFileEvent *event);
* Pop an event from event stack. Call `hi_file_event_destroy` when done with * Pop an event from event stack. Call `hi_file_event_destroy` when done with
* it. * it.
*/ */
hiFileEvent hi_file_event_pop(struct hiFileWatcherContext *ctx); hiFileEvent hi_file_event_pop(struct hiFileWatcher *ctx);
/** /**
* Free and zero held memory. Call after pop. * Free and zero held memory. Call after pop.
*/ */

View File

@@ -30,7 +30,7 @@ typedef struct {
typedef struct { typedef struct {
struct sc_array_memreg memory_regions; struct sc_array_memreg memory_regions;
struct sc_array_str enabled_modules; struct sc_array_str enabled_modules;
struct hiFileWatcherContext *filewatcher; struct hiFileWatcher *filewatcher;
} HiloadContext; } HiloadContext;
static HiloadContext context = {0}; static HiloadContext context = {0};