Skip to content

Commit

Permalink
Simplify and reduce number of threads (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
Loomeh authored Mar 20, 2024
2 parents 1375ffc + aa898f6 commit 89db601
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 34 deletions.
12 changes: 0 additions & 12 deletions src/auto-splitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,3 @@ void run_auto_splitter()

lua_close(L);
}

void *last_auto_splitter()
{
while (true)
{
if (atomic_load(&auto_splitter_enabled) && auto_splitter_file[0] != '\0')
{
run_auto_splitter();
}
usleep(1000000); // Wait for 1 second before checking again
}
}
4 changes: 2 additions & 2 deletions src/auto-splitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ extern atomic_bool call_reset;
extern char auto_splitter_file[PATH_MAX];

void check_directories();
void *last_auto_splitter();
void run_auto_splitter();

#endif /* __AUTO_SPLITTER_H__ */
#endif /* __AUTO_SPLITTER_H__ */
35 changes: 15 additions & 20 deletions src/last-gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1160,31 +1160,26 @@ static void last_app_class_init(LASTAppClass *class)
G_APPLICATION_CLASS(class)->open = last_app_open;
}

struct ThreadArgs {
int argc;
char** argv;
};

void* run_application(void* args) {
struct ThreadArgs* threadArgs = (struct ThreadArgs*)args;
int argc = threadArgs->argc;
char** argv = threadArgs->argv;
g_application_run(G_APPLICATION(last_app_new()), argc, argv);
static void *last_auto_splitter()
{
while (1) {
if (atomic_load(&auto_splitter_enabled) && auto_splitter_file[0] != '\0')
{
run_auto_splitter();
}
usleep(50000);
}
return NULL;
}

int main(int argc, char *argv[]) {
int main(int argc, char *argv[])
{
check_directories();

pthread_t t1, t2;
struct ThreadArgs threadArgs;
threadArgs.argc = argc;
threadArgs.argv = argv;
pthread_create(&t1, NULL, &run_application, (void*)&threadArgs);
pthread_create(&t2, NULL, &last_auto_splitter, NULL);

pthread_t t1;
pthread_create(&t1, NULL, &last_auto_splitter, NULL);
g_application_run(G_APPLICATION(last_app_new()), argc, argv);
pthread_join(t1, NULL);
pthread_join(t2, NULL);

return 0;
}
}

0 comments on commit 89db601

Please sign in to comment.