From b32848ad3dc4ac2e76b9d17033d8d25d2ad3950a Mon Sep 17 00:00:00 2001 From: nova Date: Mon, 29 Sep 2025 21:40:35 +0200 Subject: [PATCH] accounted for some race conditions --- interactions.c | 43 +++++++++++++++++++++++++++++++++++-------- threading.c | 1 + 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/interactions.c b/interactions.c index 9d58ccc..49fc027 100644 --- a/interactions.c +++ b/interactions.c @@ -17,6 +17,7 @@ extern unsigned int file_modifiers; extern pthread_mutex_t mutex_selection; extern pthread_mutex_t mutex_rgt; extern pthread_mutex_t mutex_mid; +extern pthread_mutex_t mutex_btm; extern pthread_cond_t cond_rgt; extern file *mid_content; extern file *lft_content; @@ -329,6 +330,8 @@ void jump_top(){ } void open_with(){ + pthread_mutex_lock(&mutex_btm); + btm_buffer = concat("open \"", mid_content[selected_file_current].file_name); btm_buffer = concat(btm_buffer, "\" with:"); @@ -372,6 +375,7 @@ void open_with(){ } void rename_hovered(){ + pthread_mutex_lock(&mutex_btm); btm_buffer = concat("rename \"", mid_content[selected_file_current].file_name); btm_buffer = concat(btm_buffer, "\" to:"); @@ -411,7 +415,8 @@ void rename_hovered(){ } void delete(){ - + pthread_mutex_lock(&mutex_btm); + unsigned int i = 0; unsigned int hits = 0; char *file_str = " "; @@ -440,8 +445,9 @@ void delete(){ mvwin(win_b, terminal_height-6, 0); wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/ + pthread_mutex_unlock(&mutex_btm); render_pass(); - + pthread_mutex_lock(&mutex_btm); timeout(-1); /* negative numbers block until enter is pressed */ /* TODO(2025-06-22T01:24:30) fix fixed buffer size */ @@ -480,15 +486,22 @@ void delete(){ if (hits) { free(file_str); } + pthread_mutex_unlock(&mutex_btm); } void makedir(){ - btm_buffer = "create dir: "; - status |= STATUS_UPDATE_SCREEN_0; + pthread_mutex_lock(&mutex_btm); + werase(win_b); mvwin(win_b, terminal_height-6, 0); wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/ + memset(btm_buffer, ' ', terminal_width); + memcpy(btm_buffer, "create dir: ", strlen("create dir: ")); + status |= STATUS_UPDATE_SCREEN_0; + + pthread_mutex_unlock(&mutex_btm); render_pass(); + pthread_mutex_lock(&mutex_btm); unsigned long local_height; local_height = getmaxy(win_b); @@ -505,14 +518,20 @@ void makedir(){ } free(str); status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL); + pthread_mutex_unlock(&mutex_btm); } void makefile(){ - btm_buffer = "create file: "; + pthread_mutex_lock(&mutex_btm); + + memcpy(btm_buffer, "create file: ", strlen("create file: ")); status |= STATUS_UPDATE_SCREEN_0; werase(win_b); mvwin(win_b, terminal_height-6, 0); wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/ + + pthread_mutex_unlock(&mutex_btm); render_pass(); + pthread_mutex_lock(&mutex_btm); unsigned long local_height; local_height = getmaxy(win_b); @@ -621,6 +640,7 @@ void order_by(int passes, int index){ } void cmd_on_selected(int passes, int index){ (void)passes; + pthread_mutex_lock(&mutex_btm); unsigned int i = 0; unsigned int hits = 0; @@ -651,7 +671,9 @@ void cmd_on_selected(int passes, int index){ mvwin(win_b, terminal_height-6, 0); wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/ + pthread_mutex_unlock(&mutex_btm); render_pass(); + pthread_mutex_lock(&mutex_btm); timeout(-1); /* negative numbers block until enter is pressed */ @@ -675,7 +697,7 @@ void cmd_on_selected(int passes, int index){ } } free(btm_buffer); - btm_buffer = concat("completed: ", key_binding[index].black_magic); + memcpy(btm_buffer, "completed: ", strlen("completed: ")); } else { free(btm_buffer); free(cmd); @@ -693,7 +715,7 @@ void cmd_on_selected(int passes, int index){ } else { free(btm_buffer); - btm_buffer = "cancled deletion"; + memcpy(btm_buffer, "cancled deletion", strlen("cancled deletion")); } timeout(10); @@ -702,6 +724,7 @@ void cmd_on_selected(int passes, int index){ if (hits) { free(file_str); } + pthread_mutex_unlock(&mutex_btm); } void yank_text(int passes, int index){ (void)passes; @@ -805,12 +828,15 @@ void paste(){ status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL); } void search(){ + pthread_mutex_lock(&mutex_btm); unsigned long local_height; local_height = getmaxy(win_b); - memset(search_buffer, '\0', 255); + + pthread_mutex_unlock(&mutex_btm); render_pass(); + pthread_mutex_lock(&mutex_btm); curs_set(1); @@ -868,6 +894,7 @@ void search(){ update_selected_file(); status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0); + pthread_mutex_unlock(&mutex_btm); } void search_next(){ unsigned long i; diff --git a/threading.c b/threading.c index b7590e8..594b778 100644 --- a/threading.c +++ b/threading.c @@ -315,6 +315,7 @@ void *thread_btm(){ btm_buffer[offset_back - 2] = size_unit[(unsigned)size_index]; offset_back -= strlen(float_str) + 2; memcpy(btm_buffer + offset_back, float_str, strlen(float_str)); + free(path); pthread_mutex_unlock(&mutex_btm); }