mirror of
https://gittea.dev/nova/th.git
synced 2025-10-21 10:20:15 -04:00
further thread pool stuff
This commit is contained in:
52
threading.c
52
threading.c
@@ -18,15 +18,12 @@ pthread_mutex_t mutex_lft;
|
||||
pthread_mutex_t mutex_mid;
|
||||
pthread_mutex_t mutex_rgt;
|
||||
pthread_mutex_t mutex_selection;
|
||||
pthread_mutex_t mutex_wait;
|
||||
pthread_cond_t cond_wait;
|
||||
pthread_cond_t cond_mid;
|
||||
pthread_cond_t cond_rgt;
|
||||
pthread_cond_t cond_lft;
|
||||
pthread_cond_t cond_top;
|
||||
pthread_cond_t cond_btm;
|
||||
|
||||
volatile char wait_count; /* this is used to determine how many threads are waiting for cont_wait */
|
||||
|
||||
file *rgt_content;
|
||||
file *mid_content;
|
||||
@@ -95,12 +92,8 @@ void *thread_mid(void *data){
|
||||
file_current->status = mid_content->status;
|
||||
mid_file_count = 0;
|
||||
|
||||
while(wait_count < 2){
|
||||
/*wait for thread_rgt and thread_btm to lock*/
|
||||
}
|
||||
pthread_mutex_lock(&mutex_wait);
|
||||
pthread_cond_broadcast(&cond_wait);
|
||||
pthread_mutex_unlock(&mutex_wait);
|
||||
pthread_cond_signal(&cond_rgt);
|
||||
pthread_cond_signal(&cond_lft);
|
||||
|
||||
free(path);
|
||||
pthread_mutex_unlock(&mutex_mid);
|
||||
@@ -112,12 +105,8 @@ void *thread_mid(void *data){
|
||||
}
|
||||
|
||||
|
||||
while(wait_count < 2){
|
||||
/*wait for thread_rgt and thread_btm to lock*/
|
||||
}
|
||||
pthread_mutex_lock(&mutex_wait);
|
||||
pthread_cond_broadcast(&cond_wait);
|
||||
pthread_mutex_unlock(&mutex_wait);
|
||||
pthread_cond_signal(&cond_rgt);
|
||||
pthread_cond_signal(&cond_lft);
|
||||
|
||||
}
|
||||
free(path);
|
||||
@@ -162,25 +151,21 @@ void *thread_rgt(void *data){
|
||||
unsigned int local_status = *(unsigned int*)data;
|
||||
(void)local_status;
|
||||
|
||||
file file_current;
|
||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||
pthread_mutex_lock(&mutex_rgt);
|
||||
pthread_cond_wait(&cond_rgt, &mutex_rgt);
|
||||
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_selection);
|
||||
char *path = malloc(strlen(file_current->file_name) + 1);
|
||||
strcpy(path, file_current->file_name);
|
||||
unsigned char file_current_type = file_current->file_type;
|
||||
unsigned long file_current_size = file_current->file_size;
|
||||
char file_current_local_status = file_current->status;
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
pthread_mutex_lock(&mutex_mid);
|
||||
char *path = malloc(strlen(mid_content[selected_file_current].file_name) + 1);
|
||||
strcpy(path, mid_content[selected_file_current].file_name);
|
||||
file_current.file_type = mid_content[selected_file_current].file_type;
|
||||
file_current.file_size = mid_content[selected_file_current].file_size;
|
||||
file_current.status = mid_content[selected_file_current].status;
|
||||
pthread_mutex_unlock(&mutex_mid);
|
||||
|
||||
if (file_current_type == FILE_TYPE_DIR || file_current_type == FILE_TYPE_SYMLINK) {
|
||||
if (file_current.file_type == FILE_TYPE_DIR || file_current.file_type == FILE_TYPE_SYMLINK) {
|
||||
images_clear();
|
||||
|
||||
unsigned long i = 0;
|
||||
@@ -209,12 +194,12 @@ void *thread_rgt(void *data){
|
||||
rgt_content = malloc(sizeof(file));
|
||||
|
||||
free(rgt_buffer);
|
||||
if (file_current_local_status & FILE_STATUS_DIR_EMPTY) {
|
||||
if (file_current.status & FILE_STATUS_DIR_EMPTY) {
|
||||
rgt_buffer = "empty dir";
|
||||
} else {
|
||||
rgt_content->file_type = FILE_TYPE_OPEN_FILE;
|
||||
rgt_content->status = FILE_STATUS_HOVER;
|
||||
rgt_buffer = preview_file(path, file_current_size);
|
||||
rgt_buffer = preview_file(path, file_current.file_size);
|
||||
}
|
||||
}
|
||||
free(path);
|
||||
@@ -256,11 +241,6 @@ void *thread_btm(void *data){
|
||||
pthread_mutex_lock(&mutex_btm);
|
||||
pthread_cond_wait(&cond_btm, &mutex_btm);
|
||||
|
||||
pthread_mutex_lock(&mutex_wait);
|
||||
wait_count++;
|
||||
pthread_cond_wait(&cond_wait, &mutex_wait);
|
||||
wait_count--;
|
||||
pthread_mutex_unlock(&mutex_wait);
|
||||
|
||||
free(btm_buffer);
|
||||
int buffer_width = terminal_width;
|
||||
@@ -318,8 +298,6 @@ void threading_init(){
|
||||
vol = pthread_mutex_init(&mutex_btm, NULL);
|
||||
vol = pthread_mutex_init(&mutex_rgt, NULL);
|
||||
vol = pthread_mutex_init(&mutex_selection, NULL);
|
||||
vol = pthread_mutex_init(&mutex_wait, NULL);
|
||||
vol = pthread_cond_init(&cond_wait, NULL);
|
||||
vol = pthread_cond_init(&cond_rgt, NULL);
|
||||
vol = pthread_cond_init(&cond_lft, NULL);
|
||||
vol = pthread_cond_init(&cond_mid, NULL);
|
||||
|
Reference in New Issue
Block a user