attempted multithreadded rendering
This commit is contained in:
56
main.c
56
main.c
@@ -31,6 +31,12 @@ WINDOW *win_l;
|
|||||||
WINDOW *win_m;
|
WINDOW *win_m;
|
||||||
WINDOW *win_r;
|
WINDOW *win_r;
|
||||||
|
|
||||||
|
extern pthread_mutex_t mutex_top;
|
||||||
|
extern pthread_mutex_t mutex_btm;
|
||||||
|
extern pthread_mutex_t mutex_lft;
|
||||||
|
extern pthread_mutex_t mutex_mid;
|
||||||
|
extern pthread_mutex_t mutex_rgt;
|
||||||
|
|
||||||
char *input; /*used in user_interactions*/
|
char *input; /*used in user_interactions*/
|
||||||
char *terminal_width_empty_line; /* used in user_interactions */
|
char *terminal_width_empty_line; /* used in user_interactions */
|
||||||
|
|
||||||
@@ -154,21 +160,41 @@ void render_pass(){
|
|||||||
|
|
||||||
}
|
}
|
||||||
if (status & STATUS_UPDATE_SCREEN_MASK) {
|
if (status & STATUS_UPDATE_SCREEN_MASK) {
|
||||||
werase(win_t);
|
if (pthread_mutex_trylock(&mutex_top) == 0) {
|
||||||
werase(win_l);
|
wnoutrefresh(win_t);
|
||||||
werase(win_m);
|
pthread_mutex_unlock(&mutex_top);
|
||||||
werase(win_r);
|
} else {
|
||||||
werase(win_b);
|
mvwaddstr(win_t, terminal_height/2, terminal_width/4, "LOADING");
|
||||||
window_top(win_t);
|
status |= STATUS_UPDATE_SCREEN_GENERIC;
|
||||||
window_lft(win_l);
|
}
|
||||||
window_mid(win_m);
|
if (pthread_mutex_trylock(&mutex_rgt) == 0) {
|
||||||
window_rgt(win_r);
|
wnoutrefresh(win_r);
|
||||||
window_btm(win_b);
|
pthread_mutex_unlock(&mutex_rgt);
|
||||||
wnoutrefresh(win_t);
|
} else {
|
||||||
wnoutrefresh(win_l);
|
mvwaddstr(win_r, terminal_height/2, terminal_width/4, "LOADING");
|
||||||
wnoutrefresh(win_m);
|
status |= STATUS_UPDATE_SCREEN_GENERIC;
|
||||||
wnoutrefresh(win_r);
|
}
|
||||||
wnoutrefresh(win_b);
|
if (pthread_mutex_lock(&mutex_mid) == 0) {
|
||||||
|
wnoutrefresh(win_m);
|
||||||
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
|
} else {
|
||||||
|
mvwaddstr(win_m, terminal_height/2, terminal_width/4, "LOADING");
|
||||||
|
status |= STATUS_UPDATE_SCREEN_GENERIC;
|
||||||
|
}
|
||||||
|
if (pthread_mutex_trylock(&mutex_lft) == 0) {
|
||||||
|
wnoutrefresh(win_l);
|
||||||
|
pthread_mutex_unlock(&mutex_lft);
|
||||||
|
} else {
|
||||||
|
mvwaddstr(win_l, terminal_height/2, terminal_width/4, "LOADING");
|
||||||
|
status |= STATUS_UPDATE_SCREEN_GENERIC;
|
||||||
|
}
|
||||||
|
if (pthread_mutex_trylock(&mutex_btm) == 0) {
|
||||||
|
wnoutrefresh(win_b);
|
||||||
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
|
} else {
|
||||||
|
mvwaddstr(win_b, terminal_height/2, terminal_width/4, "LOADING");
|
||||||
|
status |= STATUS_UPDATE_SCREEN_GENERIC;
|
||||||
|
}
|
||||||
doupdate();
|
doupdate();
|
||||||
status &= ~(STATUS_UPDATE_SCREEN_MASK - STATUS_UPDATE_SCREEN_DIR_CHANGE);
|
status &= ~(STATUS_UPDATE_SCREEN_MASK - STATUS_UPDATE_SCREEN_DIR_CHANGE);
|
||||||
}
|
}
|
||||||
|
|||||||
60
threading.c
60
threading.c
@@ -33,6 +33,11 @@ char *rgt_buffer; /* used for file previews, unlike rgt_content, which is used f
|
|||||||
char *btm_buffer;
|
char *btm_buffer;
|
||||||
char *top_buffer; /* current path */
|
char *top_buffer; /* current path */
|
||||||
|
|
||||||
|
extern WINDOW *win_t;
|
||||||
|
extern WINDOW *win_b;
|
||||||
|
extern WINDOW *win_l;
|
||||||
|
extern WINDOW *win_m;
|
||||||
|
extern WINDOW *win_r;
|
||||||
|
|
||||||
|
|
||||||
unsigned long top_width;
|
unsigned long top_width;
|
||||||
@@ -81,12 +86,23 @@ void *thread_mid(){
|
|||||||
mid_dir.current_file = NULL;
|
mid_dir.current_file = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* rendering */
|
||||||
|
werase(win_m);
|
||||||
|
if (mid_dir.file_count == 0) {
|
||||||
|
mvwaddstr(win_m, 0, 0, "empty");
|
||||||
|
} else {
|
||||||
|
print_dir(win_m, 1, &mid_dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
|
|
||||||
pthread_cond_signal(&cond_rgt);
|
pthread_cond_signal(&cond_rgt);
|
||||||
|
|
||||||
btm_status = local_status;
|
btm_status = local_status;
|
||||||
pthread_cond_signal(&cond_btm);
|
pthread_cond_signal(&cond_btm);
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_mid);
|
|
||||||
|
|
||||||
long i;
|
long i;
|
||||||
for (i = 0; i < tmp.file_count; i++) {
|
for (i = 0; i < tmp.file_count; i++) {
|
||||||
@@ -140,6 +156,10 @@ void *thread_lft(){
|
|||||||
lft_dir.file_count = 0;
|
lft_dir.file_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* rendering */
|
||||||
|
werase(win_l);
|
||||||
|
print_dir(win_l, 0, &lft_dir);
|
||||||
|
pthread_mutex_unlock(&mutex_lft);
|
||||||
|
|
||||||
free(path);
|
free(path);
|
||||||
pthread_mutex_unlock(&mutex_lft);
|
pthread_mutex_unlock(&mutex_lft);
|
||||||
@@ -203,6 +223,19 @@ void *thread_rgt(){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* rendering */
|
||||||
|
werase(win_r);
|
||||||
|
if (!rgt_dir.current_file) {
|
||||||
|
mvwaddstr(win_r, 0, 0, "not accessible");
|
||||||
|
}else if (rgt_dir.current_file->file_type == FILE_TYPE_OPEN_FILE) {
|
||||||
|
mvwaddnstr(win_r, 0, 0, rgt_buffer, (terminal_width/2) * terminal_width);
|
||||||
|
} else if ((rgt_dir.current_file->permissions & S_IRUSR) == 0) {
|
||||||
|
mvwaddstr(win_r, 0, 0, "not accessible");
|
||||||
|
} else {
|
||||||
|
print_dir(win_r, 0, &rgt_dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_rgt);
|
pthread_mutex_unlock(&mutex_rgt);
|
||||||
long i;
|
long i;
|
||||||
for (i = 0; i < tmp.file_count; i++) {
|
for (i = 0; i < tmp.file_count; i++) {
|
||||||
@@ -234,7 +267,20 @@ void *thread_top(){
|
|||||||
top_buffer = malloc(strlen(global_path)+1);
|
top_buffer = malloc(strlen(global_path)+1);
|
||||||
memcpy(top_buffer, global_path, strlen(global_path)+1);
|
memcpy(top_buffer, global_path, strlen(global_path)+1);
|
||||||
top_width = strlen(top_buffer);
|
top_width = strlen(top_buffer);
|
||||||
/*printing of mid_dir.current_file->file_name is done directly in window.c window_top()*/
|
|
||||||
|
|
||||||
|
/* rendering */
|
||||||
|
werase(win_t);
|
||||||
|
if (*top_buffer != ' ') { /*printing ' ' (standard initialized value, see threading_init) makes valgrind throw a fuss*/
|
||||||
|
wattron(win_t, COLOR_PAIR(COLOR_PATH));
|
||||||
|
mvwaddstr(win_t, 0, 0, top_buffer);
|
||||||
|
mvwaddch(win_t, 0, strlen(top_buffer), '/');
|
||||||
|
wattroff(win_t, COLOR_PAIR(COLOR_PATH));
|
||||||
|
if (mid_dir.file_count != 0 && !(mid_dir.current_file == NULL)) {
|
||||||
|
mvwaddstr(win_t, 0, strlen(top_buffer)+1, mid_dir.current_file->file_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_top);
|
pthread_mutex_unlock(&mutex_top);
|
||||||
}
|
}
|
||||||
@@ -347,6 +393,16 @@ void *thread_btm(){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* rendering */
|
||||||
|
werase(win_b);
|
||||||
|
if (*top_buffer != ' ') { /*printing ' ' (standard initialized value, see threading_init) makes valgrind throw a fuss*/
|
||||||
|
mvwprintw(win_b, 0, 0, "%s", btm_buffer);
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
|
/*the printing of the input char is done in user_interactions*/
|
||||||
|
/*the printing of all possible inputs are done in user_interactions */
|
||||||
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_btm);
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
}
|
}
|
||||||
pthread_exit(0);
|
pthread_exit(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user