From 36ff54038e432e2aacfecd65ae56d2c598d5d361 Mon Sep 17 00:00:00 2001 From: nova Date: Tue, 24 Jun 2025 00:18:53 +0200 Subject: [PATCH] improvenments to threading --- main.c | 26 +++++++++++--------------- threading.c | 6 +----- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/main.c b/main.c index 7f54371..8a23c01 100644 --- a/main.c +++ b/main.c @@ -53,27 +53,23 @@ int main(){ temp_width = terminal_width; temp_heigth = terminal_height; } - if (status & STATUS_RUN_BACKEND || threading) { + if (status & STATUS_RUN_BACKEND) { if (threading) { - /* temporary comment, somehow stops timing related crashes pthread_cancel(thread_t); - pthread_cancel(thread_b); pthread_cancel(thread_l); pthread_cancel(thread_m); pthread_cancel(thread_r); - */ + pthread_cancel(thread_b); threading = 0; - status &= ~STATUS_RUN_BACKEND; - status &= ~STATUS_RELOAD_DIRECTORY; - status |= STATUS_UPDATE_SCREEN_0; - } else { - pthread_create(&thread_t, NULL, thread_top, win_t); /*top bar*/ - pthread_create(&thread_b, NULL, thread_btm, win_b); /*bottom bar*/ - pthread_create(&thread_m, NULL, thread_mid, win_m); /*parent_content slash win_l*/ - pthread_create(&thread_l, NULL, thread_lft, win_l); /*current_content slash win_m*/ - pthread_create(&thread_r, NULL, thread_rgt, win_r); /*child_content slash win_r*/ - threading = 1; - } + } + pthread_create(&thread_t, NULL, thread_top, win_t); /*top bar*/ + pthread_create(&thread_l, NULL, thread_lft, win_l); /*current_content slash win_m*/ + pthread_create(&thread_m, NULL, thread_mid, win_m); /*parent_content slash win_l*/ + pthread_create(&thread_r, NULL, thread_rgt, win_r); /*child_content slash win_r*/ + pthread_create(&thread_b, NULL, thread_btm, win_b); /*bottom bar*/ + threading = 1; + status &= ~(STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY); + status |= STATUS_UPDATE_SCREEN_0; } if ((input = getch())) { user_interactions(&input, win_b); diff --git a/threading.c b/threading.c index ecfac71..2506dec 100644 --- a/threading.c +++ b/threading.c @@ -71,13 +71,13 @@ void *thread_mid(void *data){ mid_content[selected_file_last].status &= ~FILE_STATUS_HOVER; } selected_file_last = selected_file_current; - pthread_mutex_unlock(&mutex_selection); file_current.file_name = malloc(mid_content[selected_file_current].file_name_width + 1); strcpy(file_current.file_name, mid_content[selected_file_current].file_name); file_current.file_name_width = mid_content[selected_file_current].file_name_width; file_current.file_size_bytes = mid_content[selected_file_current].file_size_bytes; file_current.file_type = mid_content[selected_file_current].file_type; + pthread_mutex_unlock(&mutex_selection); } free(path); @@ -86,9 +86,6 @@ void *thread_mid(void *data){ } void *thread_lft(void *data){ pthread_mutex_lock(&mutex_lft); - /*{{{*/ - - char *path; if((path=getcwd(NULL, 0)) == NULL) { @@ -112,7 +109,6 @@ void *thread_lft(void *data){ } free(path); pthread_mutex_unlock(&mutex_lft); - /*}}}*/ pthread_exit(NULL);