-O2 related refactoring

This commit is contained in:
nova
2025-07-09 01:09:45 +02:00
parent b6f9633677
commit d96046ac44
10 changed files with 136 additions and 95 deletions

View File

@@ -28,7 +28,7 @@ char *btm_buffer;
file *file_current;
char *top_content; /* current path */
char *top_buffer; /* current path */
unsigned long rgt_file_count;
unsigned long mid_file_count;
@@ -191,17 +191,20 @@ void *thread_rgt(void *data){
get_dir_content(path, &rgt_file_count, rgt_content);
rgt_content[0].status &= ~FILE_STATUS_FILE_OPEN;
free(path);
free(rgt_buffer);
rgt_buffer = malloc(sizeof(char));
memset(rgt_buffer, ' ', sizeof(char));
} else {
rgt_file_count = 0;
free(rgt_buffer);
if (rgt_content->status & FILE_STATUS_DIR_EMPTY) {
free(rgt_buffer);
rgt_buffer = "empty dir";
} else {
rgt_content->file_type = FILE_TYPE_OPEN_FILE;
rgt_content->status = FILE_STATUS_HOVER;
free(rgt_buffer);
rgt_buffer = preview_file(rgt_content);
}
}
@@ -211,16 +214,16 @@ void *thread_rgt(void *data){
}
void *thread_top(void *data){
pthread_mutex_lock(&mutex_top);
free(top_content);
free(top_buffer);
char *path;
if((path=getcwd(NULL, 0)) == NULL) {
top_content = malloc(sizeof("cannot open directory"));
top_buffer = malloc(sizeof("cannot open directory"));
top_width = sizeof("cannot open directory");
top_content = "cannot open directory";
top_buffer = "cannot open directory";
} else {
top_content = getcwd(NULL, 0);
top_width = strlen(top_content);
top_buffer = getcwd(NULL, 0);
top_width = strlen(top_buffer);
}
free(path);
@@ -228,12 +231,12 @@ void *thread_top(void *data){
pthread_exit(0);
}
void *thread_btm(void *data){
pthread_mutex_lock(&mutex_btm);
pthread_mutex_lock(&mutex_wait);
wait_count++;
pthread_cond_wait(&cond_wait, &mutex_wait);
wait_count--;
pthread_mutex_unlock(&mutex_wait);
pthread_mutex_lock(&mutex_btm);
free(btm_buffer);
int buffer_width = terminal_width;
@@ -260,9 +263,12 @@ void threading_init(){
mid_content = malloc(sizeof(file));
lft_content = malloc(sizeof(file));
top_content = malloc(sizeof(char));
top_buffer = malloc(sizeof(char));
rgt_buffer = malloc(sizeof(char));
btm_buffer = malloc(sizeof(char));
memset(top_buffer, ' ', sizeof(char));
memset(rgt_buffer, ' ', sizeof(char));
memset(btm_buffer, ' ', sizeof(char));
rgt_content[0].file_type = 0;
@@ -291,7 +297,7 @@ void threading_free(){
free(rgt_content);
free(mid_content);
free(lft_content);
free(top_content);
free(top_buffer);
pthread_mutex_destroy(&mutex_top);
pthread_mutex_destroy(&mutex_mid);