improvements to the threading
This commit is contained in:
145
threading.c
145
threading.c
@@ -47,8 +47,13 @@ unsigned int btm_status;
|
|||||||
|
|
||||||
|
|
||||||
void *thread_mid(){
|
void *thread_mid(){
|
||||||
|
dir tmp;
|
||||||
|
tmp.current_file = NULL;
|
||||||
|
tmp.file_list = NULL;
|
||||||
|
tmp.file_count = 0;
|
||||||
|
|
||||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||||
|
|
||||||
pthread_mutex_lock(&mutex_mid);
|
pthread_mutex_lock(&mutex_mid);
|
||||||
pthread_cond_wait(&cond_mid, &mutex_mid);
|
pthread_cond_wait(&cond_mid, &mutex_mid);
|
||||||
unsigned int local_status = status;
|
unsigned int local_status = status;
|
||||||
@@ -62,35 +67,35 @@ void *thread_mid(){
|
|||||||
memcpy(path, global_path, strlen(global_path)+1);
|
memcpy(path, global_path, strlen(global_path)+1);
|
||||||
|
|
||||||
if (local_status & STATUS_RELOAD_DIRECTORY) {
|
if (local_status & STATUS_RELOAD_DIRECTORY) {
|
||||||
long index = (long)mid_dir.current_file;
|
long index = mid_dir.current_file - mid_dir.file_list;
|
||||||
|
|
||||||
|
tmp = mid_dir;
|
||||||
|
|
||||||
dir tmp;
|
mid_dir.file_count = get_dir_size(path);
|
||||||
tmp.file_count = get_dir_size(global_path);
|
mid_dir.file_list = malloc(mid_dir.file_count * sizeof(file));
|
||||||
tmp.file_list = malloc(tmp.file_count * sizeof(file));
|
if (mid_dir.file_count) { /* fails if dir empty */
|
||||||
if (tmp.file_count) { /* fails if dir empty */
|
get_dir_content(path, &mid_dir);
|
||||||
get_dir_content(global_path, &tmp);
|
mid_dir.current_file = &mid_dir.file_list[index];
|
||||||
|
|
||||||
} else { /* the hovered dir is empty */
|
} else { /* the hovered dir is empty */
|
||||||
tmp.current_file = NULL;
|
mid_dir.current_file = NULL;
|
||||||
}
|
}
|
||||||
long i;
|
|
||||||
for (i = 0; i < mid_dir.file_count; i++) {
|
|
||||||
free(mid_dir.file_list[i].file_name);
|
|
||||||
}
|
|
||||||
free(mid_dir.file_list);
|
|
||||||
mid_dir.file_list = tmp.file_list;
|
|
||||||
mid_dir.current_file = tmp.file_list;
|
|
||||||
mid_dir.file_count = tmp.file_count;
|
|
||||||
|
|
||||||
update_selected_file();
|
|
||||||
}
|
}
|
||||||
|
pthread_cond_signal(&cond_rgt);
|
||||||
|
|
||||||
btm_status = local_status;
|
btm_status = local_status;
|
||||||
pthread_cond_signal(&cond_rgt);
|
|
||||||
pthread_cond_signal(&cond_btm);
|
pthread_cond_signal(&cond_btm);
|
||||||
|
|
||||||
free(path);
|
|
||||||
pthread_mutex_unlock(&mutex_mid);
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
|
|
||||||
|
long i;
|
||||||
|
for (i = 0; i < tmp.file_count; i++) {
|
||||||
|
free(tmp.file_list[i].file_name);
|
||||||
|
}
|
||||||
|
free(tmp.file_list);
|
||||||
|
tmp.current_file = NULL;
|
||||||
|
tmp.file_list = NULL;
|
||||||
|
tmp.file_count = 0;
|
||||||
}
|
}
|
||||||
pthread_exit(0);
|
pthread_exit(0);
|
||||||
}
|
}
|
||||||
@@ -145,22 +150,26 @@ void *thread_lft(){
|
|||||||
}
|
}
|
||||||
void *thread_rgt(){
|
void *thread_rgt(){
|
||||||
|
|
||||||
|
dir tmp;
|
||||||
|
tmp.current_file = NULL;
|
||||||
|
tmp.file_list = NULL;
|
||||||
|
tmp.file_count = 0;
|
||||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||||
pthread_mutex_lock(&mutex_rgt);
|
pthread_mutex_lock(&mutex_rgt);
|
||||||
pthread_cond_wait(&cond_rgt, &mutex_rgt);
|
pthread_cond_wait(&cond_rgt, &mutex_rgt);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pthread_mutex_lock(&mutex_mid);
|
pthread_mutex_lock(&mutex_mid);
|
||||||
|
|
||||||
rgt_dir.current_file = mid_dir.current_file;
|
char *file_name = malloc(strlen(mid_dir.current_file->file_name)+1);
|
||||||
rgt_dir.file_count = 1;
|
file_name = memcpy(file_name, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
|
||||||
|
|
||||||
rgt_dir.file_list = malloc(sizeof(file));
|
rgt_dir.file_list = malloc(sizeof(file));
|
||||||
|
memcpy(rgt_dir.file_list, mid_dir.current_file, sizeof(file));
|
||||||
char *file_name = malloc(strlen(rgt_dir.current_file->file_name)+1);
|
rgt_dir.file_list->file_name = file_name;
|
||||||
memcpy(file_name, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
|
|
||||||
memcpy(rgt_dir.file_list, rgt_dir.current_file, sizeof(file));
|
|
||||||
rgt_dir.current_file = rgt_dir.file_list;
|
rgt_dir.current_file = rgt_dir.file_list;
|
||||||
rgt_dir.current_file->file_name = file_name;
|
rgt_dir.file_count = 1;
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_mid);
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
|
|
||||||
@@ -170,64 +179,40 @@ void *thread_rgt(){
|
|||||||
images_clear();
|
images_clear();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
dir tmp;
|
tmp = rgt_dir;
|
||||||
tmp.file_count = get_dir_size(rgt_dir.current_file->file_name);
|
|
||||||
tmp.file_list = malloc(tmp.file_count * sizeof(file));
|
rgt_dir.file_count = get_dir_size(rgt_dir.current_file->file_name);
|
||||||
if (tmp.file_count) { /* fails if dir empty */
|
rgt_dir.file_list = malloc(rgt_dir.file_count * sizeof(file));
|
||||||
get_dir_content(rgt_dir.current_file->file_name, &tmp);
|
if (rgt_dir.file_count) { /* fails if dir empty */
|
||||||
|
get_dir_content(tmp.current_file->file_name, &rgt_dir);
|
||||||
} else { /* the hovered dir is empty */
|
} else { /* the hovered dir is empty */
|
||||||
tmp.current_file = NULL;
|
rgt_dir.current_file = NULL;
|
||||||
}
|
}
|
||||||
long i;
|
|
||||||
for (i = 0; i < rgt_dir.file_count; i++) {
|
|
||||||
free(rgt_dir.file_list[i].file_name);
|
|
||||||
}
|
|
||||||
free(rgt_dir.file_list);
|
|
||||||
rgt_dir.file_list = tmp.file_list;
|
|
||||||
rgt_dir.current_file = tmp.file_list;
|
|
||||||
rgt_dir.file_count = tmp.file_count;
|
|
||||||
|
|
||||||
} else if ((status & STATUS_DELTA_TIME) != STATUS_DELTA_TIME && mid_dir.file_count > 0) {
|
} else if ((status & STATUS_DELTA_TIME) != STATUS_DELTA_TIME && mid_dir.file_count > 0) {
|
||||||
|
|
||||||
|
|
||||||
free(rgt_buffer);
|
free(rgt_buffer);
|
||||||
rgt_dir.current_file->status = FILE_STATUS_HOVER;
|
|
||||||
rgt_buffer = preview_file(rgt_dir.current_file);
|
rgt_buffer = preview_file(rgt_dir.current_file);
|
||||||
rgt_dir.current_file->file_type = FILE_TYPE_OPEN_FILE;
|
rgt_dir.current_file->file_type |= FILE_TYPE_OPEN_FILE;
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
unsigned long i = 0;
|
|
||||||
for (i = 0; i < rgt_dir.file_count; i++) {
|
|
||||||
if (rgt_dir.file_list[i].file_name) {
|
|
||||||
free(rgt_dir.file_list[i].file_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(rgt_dir.file_list);
|
|
||||||
rgt_dir.file_count = 0;
|
|
||||||
rgt_dir.file_list = malloc(sizeof(file));
|
|
||||||
rgt_dir.current_file = rgt_dir.file_list;
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unsigned long i = 0;
|
|
||||||
for (i = 0; i < rgt_dir.file_count; i++) {
|
|
||||||
if (rgt_dir.current_file[i].file_name) {
|
|
||||||
free(rgt_dir.current_file[i].file_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(rgt_dir.file_list);
|
|
||||||
rgt_dir.file_count = 0;
|
|
||||||
rgt_dir.file_list = malloc(sizeof(file));
|
|
||||||
rgt_dir.current_file = rgt_dir.file_list;
|
|
||||||
|
|
||||||
free(rgt_buffer);
|
|
||||||
rgt_buffer = malloc(sizeof(char));
|
|
||||||
rgt_buffer[0] = '\0';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_rgt);
|
pthread_mutex_unlock(&mutex_rgt);
|
||||||
|
long i;
|
||||||
|
for (i = 0; i < tmp.file_count; i++) {
|
||||||
|
free(tmp.file_list[i].file_name);
|
||||||
|
}
|
||||||
|
free(tmp.file_list);
|
||||||
|
tmp.current_file = NULL;
|
||||||
|
tmp.file_list = NULL;
|
||||||
|
tmp.file_count = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
pthread_exit(0);
|
pthread_exit(0);
|
||||||
}
|
}
|
||||||
@@ -377,20 +362,18 @@ void threading_init(){
|
|||||||
memset(btm_buffer, '\0', sizeof(char));
|
memset(btm_buffer, '\0', sizeof(char));
|
||||||
|
|
||||||
|
|
||||||
|
pthread_mutex_init(&mutex_top, NULL);
|
||||||
volatile char vol; /* needed to make sure higher optimization steps dont move these around */
|
pthread_mutex_init(&mutex_mid, NULL);
|
||||||
vol = pthread_mutex_init(&mutex_top, NULL);
|
pthread_mutex_init(&mutex_lft, NULL);
|
||||||
vol = pthread_mutex_init(&mutex_mid, NULL);
|
pthread_mutex_init(&mutex_btm, NULL);
|
||||||
vol = pthread_mutex_init(&mutex_lft, NULL);
|
pthread_mutex_init(&mutex_rgt, NULL);
|
||||||
vol = pthread_mutex_init(&mutex_btm, NULL);
|
pthread_mutex_init(&mutex_selection, NULL);
|
||||||
vol = pthread_mutex_init(&mutex_rgt, NULL);
|
pthread_cond_init(&cond_rgt, NULL);
|
||||||
vol = pthread_mutex_init(&mutex_selection, NULL);
|
pthread_cond_init(&cond_lft, NULL);
|
||||||
vol = pthread_cond_init(&cond_rgt, NULL);
|
pthread_cond_init(&cond_mid, NULL);
|
||||||
vol = pthread_cond_init(&cond_lft, NULL);
|
pthread_cond_init(&cond_top, NULL);
|
||||||
vol = pthread_cond_init(&cond_mid, NULL);
|
pthread_cond_init(&cond_btm, NULL);
|
||||||
vol = pthread_cond_init(&cond_top, NULL);
|
|
||||||
vol = pthread_cond_init(&cond_btm, NULL);
|
|
||||||
vol;
|
|
||||||
}
|
}
|
||||||
void threading_free(){
|
void threading_free(){
|
||||||
free(top_buffer);
|
free(top_buffer);
|
||||||
|
|||||||
Reference in New Issue
Block a user