rename filewatcher struct
This commit is contained in:
@@ -32,14 +32,14 @@ typedef struct hiWatchPaths {
|
||||
struct sc_array_watch watches;
|
||||
} hiWatchPaths;
|
||||
|
||||
typedef struct hiFileWatcherContext {
|
||||
typedef struct hiFileWatcher {
|
||||
thrd_t thread;
|
||||
mtx_t mutex;
|
||||
cnd_t cond;
|
||||
int running;
|
||||
struct hiWatchPaths watchpaths;
|
||||
struct hiFileEvents events;
|
||||
} hiFileWatcherContext;
|
||||
} hiFileWatcher;
|
||||
|
||||
/*
|
||||
* 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);
|
||||
hiFileEvent *last = &sc_array_last(&ctx->events.events);
|
||||
hiFileEvent e = *last;
|
||||
@@ -204,11 +204,11 @@ static void watch_paths_destroy(hiWatchPaths *paths) {
|
||||
// Declare the thread func
|
||||
int file_watcher_watch(void *arg);
|
||||
|
||||
hiFileWatcherContext *hi_file_watcher_create() {
|
||||
hiFileWatcher *hi_file_watcher_create() {
|
||||
|
||||
// Allocate context
|
||||
hiFileWatcherContext *context = malloc(sizeof(hiFileWatcherContext));
|
||||
memset(context, 0, sizeof(hiFileWatcherContext));
|
||||
hiFileWatcher *context = malloc(sizeof(hiFileWatcher));
|
||||
memset(context, 0, sizeof(hiFileWatcher));
|
||||
|
||||
if (context) {
|
||||
if (!HILOADRES(watch_paths_init(&context->watchpaths))) {
|
||||
@@ -236,7 +236,7 @@ hiFileWatcherContext *hi_file_watcher_create() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
HiloadResult hi_file_watcher_add(struct hiFileWatcherContext *ctx,
|
||||
HiloadResult hi_file_watcher_add(struct hiFileWatcher *ctx,
|
||||
const char *filename, u32 flags) {
|
||||
if (!ctx) {
|
||||
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;
|
||||
}
|
||||
|
||||
HiloadResult hi_file_watcher_remove(struct hiFileWatcherContext *ctx,
|
||||
HiloadResult hi_file_watcher_remove(struct hiFileWatcher *ctx,
|
||||
const char *filename) {
|
||||
if (!ctx) {
|
||||
return HILOAD_FAIL;
|
||||
@@ -272,13 +272,13 @@ HiloadResult hi_file_watcher_remove(struct hiFileWatcherContext *ctx,
|
||||
return HILOAD_OK;
|
||||
}
|
||||
|
||||
void hi_file_watcher_notify(hiFileWatcherContext *ctx) {
|
||||
void hi_file_watcher_notify(hiFileWatcher *ctx) {
|
||||
if (ctx && ctx->running) {
|
||||
cnd_signal(&ctx->cond);
|
||||
}
|
||||
}
|
||||
|
||||
void hi_file_watcher_destroy(hiFileWatcherContext *ctx) {
|
||||
void hi_file_watcher_destroy(hiFileWatcher *ctx) {
|
||||
if (!ctx)
|
||||
return;
|
||||
|
||||
@@ -293,7 +293,7 @@ void hi_file_watcher_destroy(hiFileWatcherContext *ctx) {
|
||||
}
|
||||
|
||||
int file_watcher_watch(void *arg) {
|
||||
hiFileWatcherContext *ctx = (hiFileWatcherContext *)arg;
|
||||
hiFileWatcher *ctx = (hiFileWatcher *)arg;
|
||||
sc_log_set_thread_name("File Watcher");
|
||||
|
||||
char buf[4096] __attribute__((aligned(__alignof__(struct inotify_event))));
|
||||
|
||||
@@ -24,7 +24,7 @@ typedef struct {
|
||||
HiFileEventType type;
|
||||
} hiFileEvent;
|
||||
|
||||
struct hiFileWatcherContext;
|
||||
struct hiFileWatcher;
|
||||
/**
|
||||
* FileEvents is a thread safe list of events.
|
||||
*
|
||||
@@ -38,13 +38,13 @@ struct hiFileEvents;
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
@@ -52,13 +52,13 @@ void hi_file_watcher_destroy(struct hiFileWatcherContext *context);
|
||||
* @param pathname Absolute path to the file or directory
|
||||
* @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);
|
||||
/**
|
||||
* Can be used to poke file watcher thread to make sure it empties
|
||||
* 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
|
||||
@@ -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
|
||||
* 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.
|
||||
*/
|
||||
|
||||
@@ -30,7 +30,7 @@ typedef struct {
|
||||
typedef struct {
|
||||
struct sc_array_memreg memory_regions;
|
||||
struct sc_array_str enabled_modules;
|
||||
struct hiFileWatcherContext *filewatcher;
|
||||
struct hiFileWatcher *filewatcher;
|
||||
} HiloadContext;
|
||||
|
||||
static HiloadContext context = {0};
|
||||
|
||||
Reference in New Issue
Block a user