mirror of
https://gittea.dev/nova/th.git
synced 2025-10-21 10:20:15 -04:00
removed the recreation and destruction of threads
This commit is contained in:
27
main.c
27
main.c
@@ -59,6 +59,11 @@ int main(){
|
||||
char threading = 0;
|
||||
terminal_width_empty_line = malloc(terminal_width);
|
||||
|
||||
pthread_create(&thread_t, NULL, thread_top, &status); /*top bar*/
|
||||
pthread_create(&thread_l, NULL, thread_lft, &status); /*parent_content slash win_l*/
|
||||
pthread_create(&thread_m, NULL, thread_mid, &status); /*current_content slash win_m*/
|
||||
pthread_create(&thread_r, NULL, thread_rgt, &status); /*child_content slash win_r*/
|
||||
pthread_create(&thread_b, NULL, thread_btm, &status); /*bottom bar*/
|
||||
|
||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||
getmaxyx(stdscr, terminal_height, terminal_width);
|
||||
@@ -67,29 +72,17 @@ int main(){
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_RESIZE);
|
||||
temp_width = terminal_width;
|
||||
temp_heigth = terminal_height;
|
||||
}
|
||||
if (status & STATUS_RUN_BACKEND && threading) {
|
||||
pthread_cancel(thread_b);
|
||||
pthread_cancel(thread_r);
|
||||
pthread_cancel(thread_m);
|
||||
pthread_cancel(thread_l);
|
||||
pthread_cancel(thread_t);
|
||||
}
|
||||
if (threading) {
|
||||
status &= ~(STATUS_RELOAD_DIRECTORY);
|
||||
pthread_join(thread_t, NULL);
|
||||
pthread_join(thread_l, NULL);
|
||||
pthread_join(thread_m, NULL);
|
||||
pthread_join(thread_b, NULL);
|
||||
pthread_join(thread_r, NULL);
|
||||
threading = 0;
|
||||
}
|
||||
if (status & STATUS_RUN_BACKEND) {
|
||||
pthread_create(&thread_t, NULL, thread_top, &status); /*top bar*/
|
||||
pthread_create(&thread_l, NULL, thread_lft, &status); /*parent_content slash win_l*/
|
||||
pthread_create(&thread_m, NULL, thread_mid, &status); /*current_content slash win_m*/
|
||||
pthread_create(&thread_b, NULL, thread_btm, &status); /*bottom bar*/
|
||||
pthread_create(&thread_r, NULL, thread_rgt, &status); /*child_content slash win_r*/
|
||||
pthread_cond_signal(&cond_top);
|
||||
pthread_cond_signal(&cond_lft);
|
||||
pthread_cond_signal(&cond_mid);
|
||||
pthread_cond_signal(&cond_rgt);
|
||||
pthread_cond_signal(&cond_btm);
|
||||
status &= ~(STATUS_RUN_BACKEND);
|
||||
status |= STATUS_UPDATE_SCREEN_0;
|
||||
threading = 1;
|
||||
|
56
threading.c
56
threading.c
@@ -20,6 +20,12 @@ 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;
|
||||
@@ -42,12 +48,15 @@ unsigned long top_width;
|
||||
volatile unsigned long selected_file_current = 0;
|
||||
volatile unsigned long selected_file_last = 0;
|
||||
extern unsigned int terminal_width;
|
||||
extern unsigned int status;
|
||||
|
||||
|
||||
void *thread_mid(void *data){
|
||||
unsigned int status = *(unsigned int*)data;
|
||||
pthread_mutex_lock(&mutex_mid);
|
||||
unsigned int local_status = *(unsigned int*)data;
|
||||
|
||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||
pthread_mutex_lock(&mutex_mid);
|
||||
pthread_cond_wait(&cond_mid, &mutex_mid);
|
||||
|
||||
char *path;
|
||||
if((path=getcwd(NULL, 0)) == NULL) {
|
||||
@@ -57,7 +66,7 @@ void *thread_mid(void *data){
|
||||
} else {
|
||||
|
||||
|
||||
if (status & STATUS_RELOAD_DIRECTORY) {
|
||||
if (local_status & STATUS_RELOAD_DIRECTORY) {
|
||||
unsigned long i = 0;
|
||||
for (i = 0; i < mid_file_count; i++) {
|
||||
free(mid_content[i].file_name);
|
||||
@@ -113,11 +122,15 @@ void *thread_mid(void *data){
|
||||
}
|
||||
free(path);
|
||||
pthread_mutex_unlock(&mutex_mid);
|
||||
}
|
||||
pthread_exit(0);
|
||||
}
|
||||
void *thread_lft(void *data){
|
||||
unsigned int status = *(unsigned int*)data;
|
||||
unsigned int local_status = *(unsigned int*)data;
|
||||
|
||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||
pthread_mutex_lock(&mutex_lft);
|
||||
pthread_cond_wait(&cond_lft, &mutex_lft);
|
||||
|
||||
char *path;
|
||||
if((path=getcwd(NULL, 0)) == NULL) {
|
||||
@@ -129,7 +142,7 @@ void *thread_lft(void *data){
|
||||
path[strrchr(path, '/')-path] = '\0';
|
||||
path[0] = '/';
|
||||
|
||||
if (status & STATUS_RELOAD_DIRECTORY) {
|
||||
if (local_status & STATUS_RELOAD_DIRECTORY) {
|
||||
lft_file_count = get_dir_size(path);
|
||||
free(lft_content);
|
||||
lft_content = malloc(lft_file_count * sizeof(file));
|
||||
@@ -140,15 +153,18 @@ void *thread_lft(void *data){
|
||||
}
|
||||
free(path);
|
||||
pthread_mutex_unlock(&mutex_lft);
|
||||
}
|
||||
pthread_exit(0);
|
||||
|
||||
|
||||
}
|
||||
void *thread_rgt(void *data){
|
||||
unsigned int status = *(unsigned int*)data;
|
||||
(void)status;
|
||||
unsigned int local_status = *(unsigned int*)data;
|
||||
(void)local_status;
|
||||
|
||||
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);
|
||||
@@ -161,7 +177,7 @@ void *thread_rgt(void *data){
|
||||
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_status = file_current->status;
|
||||
char file_current_local_status = file_current->status;
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
|
||||
if (file_current_type == FILE_TYPE_DIR || file_current_type == FILE_TYPE_SYMLINK) {
|
||||
@@ -193,7 +209,7 @@ void *thread_rgt(void *data){
|
||||
rgt_content = malloc(sizeof(file));
|
||||
|
||||
free(rgt_buffer);
|
||||
if (file_current_status & FILE_STATUS_DIR_EMPTY) {
|
||||
if (file_current_local_status & FILE_STATUS_DIR_EMPTY) {
|
||||
rgt_buffer = "empty dir";
|
||||
} else {
|
||||
rgt_content->file_type = FILE_TYPE_OPEN_FILE;
|
||||
@@ -204,13 +220,17 @@ void *thread_rgt(void *data){
|
||||
free(path);
|
||||
|
||||
pthread_mutex_unlock(&mutex_rgt);
|
||||
}
|
||||
pthread_exit(0);
|
||||
}
|
||||
void *thread_top(void *data){
|
||||
unsigned int status = *(unsigned int*)data;
|
||||
(void)status;
|
||||
unsigned int local_status = *(unsigned int*)data;
|
||||
(void)local_status;
|
||||
|
||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||
pthread_mutex_lock(&mutex_top);
|
||||
pthread_cond_wait(&cond_top, &mutex_top);
|
||||
|
||||
free(top_buffer);
|
||||
|
||||
char *path;
|
||||
@@ -225,13 +245,17 @@ void *thread_top(void *data){
|
||||
|
||||
free(path);
|
||||
pthread_mutex_unlock(&mutex_top);
|
||||
}
|
||||
pthread_exit(0);
|
||||
}
|
||||
void *thread_btm(void *data){
|
||||
unsigned int status = *(unsigned int*)data;
|
||||
(void)status;
|
||||
unsigned int local_status = *(unsigned int*)data;
|
||||
(void)local_status;
|
||||
|
||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||
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);
|
||||
@@ -255,6 +279,7 @@ void *thread_btm(void *data){
|
||||
|
||||
|
||||
pthread_mutex_unlock(&mutex_btm);
|
||||
}
|
||||
pthread_exit(0);
|
||||
}
|
||||
|
||||
@@ -295,6 +320,11 @@ void threading_init(){
|
||||
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);
|
||||
vol = pthread_cond_init(&cond_top, NULL);
|
||||
vol = pthread_cond_init(&cond_btm, NULL);
|
||||
vol;
|
||||
selected_file_current = 0;
|
||||
selected_file_last = 0;
|
||||
|
Reference in New Issue
Block a user