now runs with -O2
This commit is contained in:
48
threading.c
48
threading.c
@@ -18,7 +18,7 @@ pthread_mutex_t mutex_rgt;
|
||||
pthread_mutex_t mutex_selection;
|
||||
pthread_mutex_t mutex_wait;
|
||||
pthread_cond_t cond_wait;
|
||||
int wait_count; /* this is used to determine how many threads are waiting for cont_wait */
|
||||
volatile char wait_count; /* this is used to determine how many threads are waiting for cont_wait */
|
||||
|
||||
file *rgt_content;
|
||||
file *mid_content;
|
||||
@@ -39,12 +39,11 @@ unsigned long top_width;
|
||||
|
||||
unsigned long selected_file_current=0;
|
||||
unsigned long selected_file_last=0;
|
||||
unsigned int status_mid;
|
||||
extern unsigned int status;
|
||||
extern unsigned int terminal_width;
|
||||
|
||||
|
||||
void *thread_mid(void *data){
|
||||
unsigned int status = *(unsigned int*)data;
|
||||
pthread_mutex_lock(&mutex_mid);
|
||||
|
||||
|
||||
@@ -98,10 +97,9 @@ void *thread_mid(void *data){
|
||||
|
||||
|
||||
pthread_mutex_lock(&mutex_selection);
|
||||
while(1) { /* this useless while loop exists for the singular purpose of making valgrind happy */
|
||||
if (selected_file_current >= mid_file_count) {
|
||||
selected_file_current = mid_file_count-1;
|
||||
} else {
|
||||
}
|
||||
mid_content[selected_file_current].status |= FILE_STATUS_HOVER;
|
||||
if (selected_file_current != selected_file_last) {
|
||||
mid_content[selected_file_last].status &= ~FILE_STATUS_HOVER;
|
||||
@@ -116,23 +114,22 @@ void *thread_mid(void *data){
|
||||
file_current->permissions = mid_content[selected_file_current].permissions;
|
||||
file_current->status = mid_content[selected_file_current].status;
|
||||
|
||||
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);
|
||||
break;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
free(path);
|
||||
pthread_mutex_unlock(&mutex_mid);
|
||||
pthread_exit(0);
|
||||
}
|
||||
void *thread_lft(void *data){
|
||||
unsigned int status = *(unsigned int*)data;
|
||||
pthread_mutex_lock(&mutex_lft);
|
||||
|
||||
char *path;
|
||||
@@ -162,6 +159,7 @@ void *thread_lft(void *data){
|
||||
|
||||
}
|
||||
void *thread_rgt(void *data){
|
||||
unsigned int status = *(unsigned int*)data;
|
||||
pthread_mutex_lock(&mutex_rgt);
|
||||
pthread_mutex_lock(&mutex_wait);
|
||||
wait_count++;
|
||||
@@ -170,7 +168,7 @@ void *thread_rgt(void *data){
|
||||
pthread_mutex_unlock(&mutex_wait);
|
||||
|
||||
|
||||
pthread_mutex_lock(&mutex_mid);
|
||||
pthread_mutex_lock(&mutex_selection);
|
||||
free(rgt_content);
|
||||
rgt_content = malloc(sizeof(file));
|
||||
rgt_content->file_name = malloc(file_current->file_name_width + 1);
|
||||
@@ -179,7 +177,7 @@ void *thread_rgt(void *data){
|
||||
rgt_content->file_size = file_current->file_size;
|
||||
rgt_content->file_type = file_current->file_type;
|
||||
rgt_content->status = file_current->status;
|
||||
pthread_mutex_unlock(&mutex_mid);
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
|
||||
if (rgt_content->file_type == FILE_TYPE_DIR || rgt_content->file_type == FILE_TYPE_SYMLINK) {
|
||||
char *path = malloc(rgt_content[0].file_name_width + 1);
|
||||
@@ -213,6 +211,7 @@ void *thread_rgt(void *data){
|
||||
pthread_exit(0);
|
||||
}
|
||||
void *thread_top(void *data){
|
||||
unsigned int status = *(unsigned int*)data;
|
||||
pthread_mutex_lock(&mutex_top);
|
||||
free(top_buffer);
|
||||
|
||||
@@ -231,6 +230,7 @@ void *thread_top(void *data){
|
||||
pthread_exit(0);
|
||||
}
|
||||
void *thread_btm(void *data){
|
||||
unsigned int status = *(unsigned int*)data;
|
||||
pthread_mutex_lock(&mutex_btm);
|
||||
pthread_mutex_lock(&mutex_wait);
|
||||
wait_count++;
|
||||
@@ -284,12 +284,16 @@ void threading_init(){
|
||||
file_current->file_name = malloc(sizeof("a"));
|
||||
strcpy(file_current->file_name, "a");
|
||||
|
||||
pthread_mutex_init(&mutex_top, NULL);
|
||||
pthread_mutex_init(&mutex_mid, NULL);
|
||||
pthread_mutex_init(&mutex_lft, NULL);
|
||||
pthread_mutex_init(&mutex_selection, NULL);
|
||||
pthread_mutex_init(&mutex_wait, NULL);
|
||||
pthread_cond_init(&cond_wait, NULL);
|
||||
volatile char vol; /* needed to make sure higher optimization steps dont move these around */
|
||||
vol = pthread_mutex_init(&mutex_top, NULL);
|
||||
vol = pthread_mutex_init(&mutex_mid, NULL);
|
||||
vol = pthread_mutex_init(&mutex_lft, NULL);
|
||||
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;
|
||||
selected_file_current = 0;
|
||||
selected_file_last = 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user