[config] loop in the notifier thread and reload configuration file if it is changed

pull/93/head
jackun 4 years ago
parent 341aa21b87
commit 34184abf2e
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

@ -10,19 +10,24 @@ pthread_t fileChange;
#define EVENT_BUF_LEN ( 1024 * ( EVENT_SIZE + 16 ) )
void *fileChanged(void *params_void){
overlay_params *params = reinterpret_cast<overlay_params *>(params_void);
notify_thread *nt = reinterpret_cast<notify_thread *>(params_void);
int length, i = 0;
int fd;
int wd;
char buffer[EVENT_BUF_LEN];
fd = inotify_init();
wd = inotify_add_watch( fd, config_file_path.c_str(), IN_MODIFY);
length = read( fd, buffer, EVENT_BUF_LEN );
while (i < length) {
struct inotify_event *event =
(struct inotify_event *) &buffer[i];
i += EVENT_SIZE + event->len;
wd = inotify_add_watch( fd, nt->params->config_file_path.c_str(), IN_MODIFY);
while (!nt->quit) {
length = read( fd, buffer, EVENT_BUF_LEN );
while (i < length) {
struct inotify_event *event =
(struct inotify_event *) &buffer[i];
i += EVENT_SIZE + event->len;
if (event->mask & IN_MODIFY)
parse_overlay_config(nt->params, getenv("MANGOHUD_CONFIG"));
}
i = 0;
printf("File Changed\n");
}
printf("File Changed\n");
return NULL;
}

@ -1,5 +1,11 @@
#include <thread>
#include "overlay_params.h"
struct notify_thread
{
overlay_params *params = nullptr;
bool quit = false;
};
extern pthread_t fileChange;
extern void *fileChanged(void *params_void);

@ -83,6 +83,8 @@ struct instance_data {
/* Dumping of frame stats to a file has been enabled and started. */
bool capture_started;
notify_thread notifier;
};
/* Mapped from VkDevice */
@ -2612,7 +2614,8 @@ static VkResult overlay_CreateInstance(
instance_data_map_physical_devices(instance_data, true);
parse_overlay_config(&instance_data->params, getenv("MANGOHUD_CONFIG"));
pthread_create(&fileChange, NULL, &fileChanged, &instance_data->params);
instance_data->notifier.params = &instance_data->params;
pthread_create(&fileChange, NULL, &fileChanged, &instance_data->notifier);
init_cpu_stats(instance_data->params);
@ -2635,6 +2638,7 @@ static void overlay_DestroyInstance(
struct instance_data *instance_data = FIND(struct instance_data, instance);
instance_data_map_physical_devices(instance_data, false);
instance_data->vtable.DestroyInstance(instance, pAllocator);
instance_data->notifier.quit = true;
destroy_instance_data(instance_data);
}

Loading…
Cancel
Save