Use OneShot for cons->event_resize

This commit is contained in:
Florian Märkl 2018-07-09 21:26:38 +02:00 committed by radare
parent f9f5ddeac5
commit 16d72de010
7 changed files with 60 additions and 8 deletions

View File

@ -2038,6 +2038,7 @@ R_API bool r_core_init(RCore *core) {
core->oneshot_queue = r_list_newf (free);
core->tasks_lock = r_th_lock_new (false);
core->tasks_running = 0;
core->oneshot_running = false;
core->main_task = r_core_task_new (core, false, NULL, NULL, NULL);
r_list_append (core->tasks, core->main_task);
core->current_task = NULL;

View File

@ -3293,6 +3293,10 @@ static int agraph_refresh(struct agraph_refresh_data *grd) {
return agraph_print (g, grd->fs, core, *fcn);
}
static void agraph_refresh_oneshot(struct agraph_refresh_data *grd) {
r_core_task_enqueue_oneshot (grd->core, (RCoreTaskOneShot) agraph_refresh, grd);
}
static void agraph_toggle_speed(RAGraph *g, RCore *core) {
int alt = r_config_get_i (core->config, "graph.scroll");
g->movspeed = g->movspeed == DEFAULT_SPEED? alt: DEFAULT_SPEED;
@ -3811,8 +3815,10 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int
is_error = !ret;
}
core->cons->event_resize = NULL; // avoid running old event with new data
core->cons->event_data = grd;
core->cons->event_resize = (RConsEvent) agraph_refresh;
core->cons->event_resize = (RConsEvent) agraph_refresh_oneshot;
r_cons_break_push (NULL, NULL);
while (!exit_graph && !is_error && !r_cons_is_breaked ()) {
@ -4400,8 +4406,8 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int
}
r_cons_break_pop ();
r_config_set (core->config, "asm.comments", r_str_bool (asm_comments));
core->cons->event_data = NULL;
core->cons->event_resize = NULL;
core->cons->event_data = NULL;
core->vmode = o_vmode;
core->is_asmqjmps_letter = o_asmqjmps_letter;
core->keep_asmqjmps = false;

View File

@ -149,6 +149,7 @@ static void delCurPanel(RPanels *panels);
static void delInvalidPanels(RPanels *panels);
static void dismantlePanel(RPanels *panels);
static void doPanelsRefresh(RCore *core);
static void doPanelsRefreshOneShot(RCore *core);
static bool handleCursorMode(RCore *core, const int key);
static void handleUpKey(RCore *core);
static void handleDownKey(RCore *core);
@ -221,8 +222,9 @@ static void panelPrint(RCore *core, RConsCanvas *can, RPanel *panel, int color)
}
if (!strcmp (panel->title, PANEL_TITLE_GRAPH)) {
graph_pad = 1;
core->cons->event_resize = NULL; // avoid running old event with new data
core->cons->event_data = core;
core->cons->event_resize = (RConsEvent) doPanelsRefresh;
core->cons->event_resize = (RConsEvent) doPanelsRefreshOneShot;
}
if (delta_y < 0) {
delta_y = 0;
@ -972,6 +974,24 @@ static void doPanelsRefresh(RCore *core) {
r_core_panels_refresh (core);
}
static void doPanelsRefreshOneShot(RCore *core) {
r_core_task_enqueue_oneshot (core, (RCoreTaskOneShot) doPanelsRefresh, core);
}
static int havePanel(RPanels *panels, const char *s) {
int i;
if (!panels->panel || !panels->panel[0].title) {
return 0;
}
// add new panel for testing
for (i = 1; panels->panel[i].title; i++) {
if (!strcmp (panels->panel[i].title, s)) {
return 1;
}
}
return 0;
}
static void panelSingleStepIn(RCore *core) {
if (r_config_get_i (core->config, "cfg.debug")) {
if (core->print->cur_enabled) {
@ -1403,8 +1423,9 @@ R_API int r_core_visual_panels(RCore *core, RPanels *panels) {
r_core_panels_layout (panels);
repeat:
core->panels = panels;
core->cons->event_resize = NULL; // avoid running old event with new data
core->cons->event_data = core;
core->cons->event_resize = (RConsEvent) doPanelsRefresh;
core->cons->event_resize = (RConsEvent) doPanelsRefreshOneShot;
r_core_panels_layout_refresh (core);
wheel = r_config_get_i (core->config, "scr.wheel");
if (wheel) {
@ -1781,6 +1802,8 @@ repeat:
}
goto repeat;
exit:
core->cons->event_resize = NULL;
core->cons->event_data = NULL;
core->print->cur = originCursor;
core->print->cur_enabled = false;
core->print->col = 0;

View File

@ -164,7 +164,7 @@ R_API void r_core_task_schedule(RCoreTask *current, RTaskState next_state) {
RCore *core = current->core;
bool stop = next_state != R_CORE_TASK_STATE_RUNNING;
if (!stop && core->tasks_running == 1) {
if (!stop && (core->tasks_running == 1 || core->oneshot_running)) {
return;
}
@ -183,7 +183,9 @@ R_API void r_core_task_schedule(RCoreTask *current, RTaskState next_state) {
// if there are any queued, run them immediately.
OneShot *oneshot;
while ((oneshot = r_list_pop_head (core->oneshot_queue))) {
core->oneshot_running = true;
oneshot->func (oneshot->user);
core->oneshot_running = false;
free (oneshot);
}
@ -324,7 +326,9 @@ R_API void r_core_task_enqueue_oneshot(RCore *core, RCoreTaskOneShot func, void
if (core->tasks_running == 0) {
// nothing is running right now and no other task can be scheduled
// while core->tasks_lock is locked => just run it
core->oneshot_running = true;
func (user);
core->oneshot_running = false;
} else {
OneShot *oneshot = R_NEW (OneShot);
if (oneshot) {

View File

@ -3075,6 +3075,10 @@ static void visual_refresh(RCore *core) {
}
}
static void visual_refresh_oneshot(RCore *core) {
r_core_task_enqueue_oneshot (core, (RCoreTaskOneShot) visual_refresh, core);
}
R_API int r_core_visual(RCore *core, const char *input) {
const char *cmdprompt, *teefile;
ut64 scrseek;
@ -3165,8 +3169,9 @@ dodo:
if (wheel) {
r_cons_enable_mouse (true);
}
core->cons->event_resize = NULL; // avoid running old event with new data
core->cons->event_data = core;
core->cons->event_resize = (RConsEvent) visual_refresh;
core->cons->event_resize = (RConsEvent) visual_refresh_oneshot;
flags = core->print->flags;
color = r_config_get_i (core->config, "scr.color");
if (color) {

View File

@ -2338,6 +2338,7 @@ static void r_core_visual_anal_refresh_column (RCore *core, int colpos) {
}
static ut64 r_core_visual_anal_refresh (RCore *core) {
eprintf("r_core_visual_anal_refresh\n");
if (!core) {
return 0LL;
}
@ -2405,13 +2406,22 @@ static ut64 r_core_visual_anal_refresh (RCore *core) {
return addr;
}
static void r_core_visual_anal_refresh_oneshot (RCore *core) {
r_core_task_enqueue_oneshot (core, (RCoreTaskOneShot) r_core_visual_anal_refresh, core);
}
/* Like emenu but for real */
R_API void r_core_visual_anal(RCore *core) {
char old[218];
int nfcns, ch, _option = 0;
RConsEvent olde = core->cons->event_resize;
core->cons->event_resize = (RConsEvent) r_core_visual_anal_refresh;
core->cons->event_data = (void *) core;
void *olde_user = core->cons->event_data;
core->cons->event_resize = NULL; // avoid running old event with new data
core->cons->event_data = core;
core->cons->event_resize = (RConsEvent) r_core_visual_anal_refresh_oneshot;
level = 0;
addr = core->offset;
@ -2645,6 +2655,8 @@ R_API void r_core_visual_anal(RCore *core) {
}
}
beach:
core->cons->event_resize = NULL; // avoid running old event with new data
core->cons->event_data = olde_user;
core->cons->event_resize = olde;
level = 0;
r_config_set_i (core->config, "asm.bytes", asmbytes);

View File

@ -235,6 +235,7 @@ typedef struct r_core_t {
RCoreTask *main_task;
RThreadLock *tasks_lock;
int tasks_running;
bool oneshot_running;
int cmd_depth;
int max_cmd_depth;
ut8 switch_file_view;