mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-18 02:55:12 +00:00
threading stuff resolved?
git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@522 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
parent
c8e33e9cc3
commit
9d0b2d5fb4
112
src/conky.c
112
src/conky.c
@ -1025,39 +1025,19 @@ void lock_all_threads()
|
|||||||
{
|
{
|
||||||
if (thread_count) {
|
if (thread_count) {
|
||||||
ERR("trying to end all threads");
|
ERR("trying to end all threads");
|
||||||
int i, ret, tries;
|
int i, ret;
|
||||||
// now we wait to get the locks
|
// now we wait to get the locks
|
||||||
for (i = 0; i < thread_count; i++) {
|
for (i = 0; i < thread_count; i++) {
|
||||||
ret = 1;
|
usleep(50);
|
||||||
tries = 0;
|
ret = pthread_mutex_lock(&(thread_list[i]->mutex));
|
||||||
if (!thread_list[i]->thread) {
|
if (ret) {
|
||||||
while (ret) {
|
ERR("giving up on thread %i", (int)thread_list[i]->thread);
|
||||||
tries++;
|
|
||||||
usleep(50);
|
|
||||||
ret = pthread_mutex_trylock(&(thread_list[i]->mutex));
|
|
||||||
if (tries > 25) {
|
|
||||||
ERR("giving up on thread %i", (int)thread_list[i]->thread);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (pthread_join(thread_list[i]->thread, NULL))
|
|
||||||
ERR("Problem joining thread %i\n", (int)thread_list[i]->thread);
|
|
||||||
while (ret) {
|
|
||||||
tries++;
|
|
||||||
usleep(50);
|
|
||||||
ret = pthread_mutex_trylock(&(thread_list[i]->mutex));
|
|
||||||
if (tries > 25) {
|
|
||||||
ERR("giving up on thread %i", (int)thread_list[i]->thread);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void replace_thread(struct thread_info_s *new_thread, int pos)
|
void replace_thread(struct thread_info_s *new_thread, int pos) // this isn't even used anymore; oh wells
|
||||||
{
|
{
|
||||||
if (pos >= 0 && pos < MAX_THREADS) {
|
if (pos >= 0 && pos < MAX_THREADS) {
|
||||||
thread_list[pos] = new_thread;
|
thread_list[pos] = new_thread;
|
||||||
@ -1066,25 +1046,38 @@ void replace_thread(struct thread_info_s *new_thread, int pos)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void *threaded_exec(struct text_object *obj) {
|
void *threaded_exec(struct text_object *obj) { // pthreads are really beginning to piss me off
|
||||||
pthread_mutex_lock(&(obj->data.execi.thread_info.mutex));
|
double update_time;
|
||||||
char *p2 = obj->data.execi.buffer;
|
while (1) {
|
||||||
FILE *fp = popen(obj->data.execi.cmd,"r");
|
update_time = get_time();
|
||||||
int n2 = fread(p2, 1, TEXT_BUFFER_SIZE, fp);
|
pthread_mutex_lock(&(obj->data.execi.thread_info.mutex));
|
||||||
(void) pclose(fp);
|
char *p2 = obj->data.execi.buffer;
|
||||||
p2[n2] = '\0';
|
FILE *fp = popen(obj->data.execi.cmd,"r");
|
||||||
if (n2 && p2[n2 - 1] == '\n')
|
int n2 = fread(p2, 1, TEXT_BUFFER_SIZE, fp);
|
||||||
p2[n2 - 1] = '\0';
|
(void) pclose(fp);
|
||||||
|
p2[n2] = '\0';
|
||||||
while (*p2) {
|
if (n2 && p2[n2 - 1] == '\n')
|
||||||
if (*p2 == '\001')
|
p2[n2 - 1] = '\0';
|
||||||
*p2 = ' ';
|
while (*p2) {
|
||||||
p2++;
|
if (*p2 == '\001')
|
||||||
}
|
*p2 = ' ';
|
||||||
obj->data.execi.last_update = current_update_time;
|
p2++;
|
||||||
int unlock = pthread_mutex_unlock(&(obj->data.execi.thread_info.mutex));
|
}
|
||||||
if (unlock) {
|
obj->data.execi.last_update = update_time;
|
||||||
ERR("error %i unlocking thread", unlock);
|
usleep(100); // prevent race condition
|
||||||
|
int unlock = pthread_mutex_unlock(&(obj->data.execi.thread_info.mutex));
|
||||||
|
if (unlock) {
|
||||||
|
ERR("error %i unlocking thread", unlock);
|
||||||
|
}
|
||||||
|
if (get_time() - obj->data.execi.last_update > obj->data.execi.interval) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
unsigned int delay = 1000000 * (obj->data.execi.interval -(get_time() - obj->data.execi.last_update));
|
||||||
|
if (delay < update_interval * 500000) {
|
||||||
|
delay = update_interval * 1000000;
|
||||||
|
}
|
||||||
|
usleep(delay);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
}
|
}
|
||||||
@ -1385,7 +1378,6 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
|
|||||||
}
|
}
|
||||||
END OBJ(endif, 0)
|
END OBJ(endif, 0)
|
||||||
if (blockdepth) {
|
if (blockdepth) {
|
||||||
printf("blockdepth is %i and blockstart[blockdepth] is %i and object_count is %i\n", blockdepth, blockstart[blockdepth - 1], object_count);
|
|
||||||
blockdepth--;
|
blockdepth--;
|
||||||
text_objects[blockstart[blockdepth]].data.ifblock.pos = object_count;
|
text_objects[blockstart[blockdepth]].data.ifblock.pos = object_count;
|
||||||
} else {
|
} else {
|
||||||
@ -1443,8 +1435,7 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
|
|||||||
obj->data.execi.buffer =
|
obj->data.execi.buffer =
|
||||||
(char *) calloc(1, TEXT_BUFFER_SIZE);
|
(char *) calloc(1, TEXT_BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
pthread_mutex_init(&(obj->data.execi.thread_info.mutex), NULL);
|
obj->data.execi.pos = -1;
|
||||||
obj->data.execi.pos = register_thread(&(obj->data.execi.thread_info));
|
|
||||||
END OBJ(pre_exec, 0) obj->type = OBJ_text;
|
END OBJ(pre_exec, 0) obj->type = OBJ_text;
|
||||||
if (arg) {
|
if (arg) {
|
||||||
FILE *fp = popen(arg, "r");
|
FILE *fp = popen(arg, "r");
|
||||||
@ -1762,7 +1753,6 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
|
|||||||
blockstart[blockdepth] = object_count;
|
blockstart[blockdepth] = object_count;
|
||||||
obj->data.ifblock.pos = object_count + 2;
|
obj->data.ifblock.pos = object_count + 2;
|
||||||
blockdepth++;
|
blockdepth++;
|
||||||
printf("blockdepth is %i and blockstart[blockdepth] is %i and object_count is %i\n", blockdepth, blockstart[blockdepth - 1], object_count);
|
|
||||||
END OBJ(if_running, 0)
|
END OBJ(if_running, 0)
|
||||||
if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
|
if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
|
||||||
CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
|
CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
|
||||||
@ -2654,25 +2644,19 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
|
|||||||
//parse_conky_vars(output, p, cur);
|
//parse_conky_vars(output, p, cur);
|
||||||
}
|
}
|
||||||
OBJ(texeci) {
|
OBJ(texeci) {
|
||||||
if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
|
if (obj->data.execi.pos < 0) {
|
||||||
snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
|
obj->data.execi.last_update = current_update_time;
|
||||||
} else {
|
pthread_mutex_init(&(obj->data.execi.thread_info.mutex), NULL);
|
||||||
if (!obj->data.execi.thread_info.thread && !pthread_mutex_trylock(&(obj->data.execi.thread_info.mutex))) {
|
if (!obj->data.execi.thread_info.thread && !pthread_mutex_trylock(&(obj->data.execi.thread_info.mutex))) {
|
||||||
|
if (pthread_create(&(obj->data.execi.thread_info.thread), NULL, (void*)threaded_exec, (void*) obj)) {
|
||||||
if (pthread_create(&(obj->data.execi.thread_info.thread), NULL, (void*)threaded_exec, (void*) obj)) {
|
ERR("Error starting thread");
|
||||||
ERR("Error starting thread");
|
}
|
||||||
|
obj->data.execi.pos = register_thread(&(obj->data.execi.thread_info));
|
||||||
|
pthread_mutex_unlock(&(obj->data.execi.thread_info.mutex));
|
||||||
}
|
}
|
||||||
replace_thread(&(obj->data.execi.thread_info), obj->data.execi.pos);
|
|
||||||
pthread_mutex_unlock(&(obj->data.execi.thread_info.mutex));
|
|
||||||
}
|
}
|
||||||
snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
|
snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
|
||||||
}
|
}
|
||||||
if (!pthread_mutex_trylock(&(obj->data.execi.thread_info.mutex))) {
|
|
||||||
obj->data.execi.thread_info.thread = (pthread_t)0;
|
|
||||||
pthread_mutex_unlock(&(obj->data.execi.thread_info.mutex));
|
|
||||||
}
|
|
||||||
//parse_conky_vars(obj->data.execi.buffer, p, cur);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
OBJ(fs_bar) {
|
OBJ(fs_bar) {
|
||||||
if (obj->data.fs != NULL) {
|
if (obj->data.fs != NULL) {
|
||||||
|
Loading…
Reference in New Issue
Block a user