From aea8d3ed525896d124a71484e73ecc97c0321a92 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Wed, 10 Feb 2010 21:23:21 +0100 Subject: [PATCH] Combine print_texeci and print_execi as much as possible --- src/core.cc | 8 ++++++-- src/exec.cc | 45 ++++++++++++++++++++------------------------- src/text_object.h | 1 + 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/core.cc b/src/core.cc index f63ed42c..28888131 100644 --- a/src/core.cc +++ b/src/core.cc @@ -620,23 +620,27 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ_ARG(execi, 0, "execi needs arguments") scan_execi_arg(obj, arg); obj->parse = false; + obj->thread = false; obj->callbacks.print = &print_execi; obj->callbacks.free = &free_execi; END OBJ_ARG(execpi, 0, "execpi needs arguments") scan_execi_arg(obj, arg); obj->verbatim_output = 1; obj->parse = true; + obj->thread = false; obj->callbacks.print = &print_execi; obj->callbacks.free = &free_execi; END OBJ_ARG(texeci, 0, "texeci needs arguments") scan_execi_arg(obj, arg); obj->parse = false; - obj->callbacks.print = &print_texeci; + obj->thread = true; + obj->callbacks.print = &print_execi; obj->callbacks.free = &free_execi; END OBJ_ARG(texecpi, 0, "texecpi needs arguments") scan_execi_arg(obj, arg); obj->parse = true; - obj->callbacks.print = &print_texeci; + obj->thread = true; + obj->callbacks.print = &print_execi; obj->callbacks.free = &free_execi; END OBJ(pre_exec, 0) scan_pre_exec_arg(obj, arg); diff --git a/src/exec.cc b/src/exec.cc index 43a9b6d8..5073fb4a 100644 --- a/src/exec.cc +++ b/src/exec.cc @@ -318,39 +318,34 @@ void print_execp(struct text_object *obj, char *p, int p_max_size) void print_execi(struct text_object *obj, char *p, int p_max_size) { struct execi_data *ed = (struct execi_data *)obj->data.opaque; + bool fillbuffer = true; if (!ed) return; - if (time_to_update(ed)) { - if (!ed->buffer) - ed->buffer = (char*)malloc(text_buffer_size); - read_exec(ed->cmd, ed->buffer, text_buffer_size); - ed->last_update = current_update_time; - } - fill_p(ed->buffer, obj, p, p_max_size); -} - -void print_texeci(struct text_object *obj, char *p, int p_max_size) -{ - struct execi_data *ed = (struct execi_data *)obj->data.opaque; - - if (!ed) - return; - - if (!ed->p_timed_thread) { - /* - * note that we don't register this thread with the - * timed_thread list, because we destroy it manually - */ - ed->p_timed_thread = timed_thread::create(std::bind(threaded_exec, std::placeholders::_1, obj), ed->interval * 1000000, false); + if(obj->thread == true) { if (!ed->p_timed_thread) { - NORM_ERR("Error creating texeci timed thread"); + /* + * note that we don't register this thread with the + * timed_thread list, because we destroy it manually + */ + ed->p_timed_thread = timed_thread::create(std::bind(threaded_exec, std::placeholders::_1, obj), ed->interval * 1000000, false); + if (!ed->p_timed_thread) { + NORM_ERR("Error creating texeci timed thread"); + } + fillbuffer = false; + } else { + std::lock_guard lock(ed->p_timed_thread->mutex()); } } else { - std::lock_guard lock(ed->p_timed_thread->mutex()); - fill_p(ed->buffer, obj, p, p_max_size); + if (time_to_update(ed)) { + if (!ed->buffer) + ed->buffer = (char*)malloc(text_buffer_size); + read_exec(ed->cmd, ed->buffer, text_buffer_size); + ed->last_update = current_update_time; + } } + if(fillbuffer) fill_p(ed->buffer, obj, p, p_max_size); } double execbarval(struct text_object *obj) diff --git a/src/text_object.h b/src/text_object.h index e45020a7..df7b6948 100644 --- a/src/text_object.h +++ b/src/text_object.h @@ -96,6 +96,7 @@ struct text_object { long line; struct obj_cb callbacks; bool parse; //if this true then data.s should still be parsed + bool thread; //if this true then data.s should be set by a seperate thread }; /* text object list helpers */