Commit d2b2c636 authored by Davide Ciminaghi's avatar Davide Ciminaghi Committed by Alessandro Rubini

fsm: cache pointer to current state table item

parent fa17b6c7
......@@ -68,10 +68,16 @@ get_current_state_table_item(struct pp_instance *ppi)
struct pp_state_table_item *ip;
struct pp_state_table_item *out = NULL;
/* Avoid searching if we already know where we are */
if (ppi->current_state_item)
return ppi->current_state_item;
/* a linear search is affordable up to a few dozen items */
for (ip = pp_state_table; ip->state != PPS_END_OF_TABLE && !out; ip++)
if (ip->state == ppi->state)
if (ip->state == ppi->state) {
out = ip;
ppi->current_state_item = ip;
}
return out;
}
......@@ -139,6 +145,7 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen)
pp_timeout_setall(ppi);
ppi->flags &= ~PPI_FLAGS_WAITING;
pp_diag_fsm(ppi, ip->name, STATE_LEAVE, 0);
ppi->current_state_item = NULL;
return 0; /* next_delay unused: go to new state now */
}
ppi->is_new_state = 0;
......
......@@ -123,6 +123,7 @@ struct pp_instance_cfg {
struct pp_instance {
int state;
int next_state, next_delay, is_new_state; /* set by state processing */
struct pp_state_table_item *current_state_item;
void *arch_data; /* if arch needs it */
void *ext_data; /* if protocol ext needs it */
unsigned long d_flags; /* diagnostics, ppi-specific flags */
......
......@@ -12,7 +12,8 @@
#include <ppsi/lib.h>
#include "wr-constants.h"
#define WRS_PPSI_SHMEM_VERSION 14 /* Many changes since the last incease */
#define WRS_PPSI_SHMEM_VERSION 15 /* added current_state_item the structure
* pp_instance */
/*
* This structure is used as extension-specific data in the DSPort
......
......@@ -78,6 +78,7 @@ int pp_init_globals(struct pp_globals *ppg, struct pp_runtime_opts *pp_rt_opts)
def->slaveOnly = 0;
ppi->state = PPS_INITIALIZING;
ppi->current_state_item = NULL;
ppi->port_idx = i;
ppi->frgn_rec_best = -1;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment