Commit 430fee53 authored by Lucas Russo's avatar Lucas Russo

{src,include}/*sm_io*: use smio_mod_handler instead of weak smio_id

Instead of using the index of the smio_mod_dispatch table,
which is weak and error prone, we use a handler pointer instead.
parent 883e1da3
......@@ -89,6 +89,9 @@ typedef struct _smch_rffe_t smch_rffe_t;
/* Opaque sm_ch_isla216p_t structure */
typedef struct _smch_isla216p_t smch_isla216p_t;
/* Forward declaration smio_mod_dispatch_t declaration structure */
typedef struct _smio_mod_dispatch_t smio_mod_dispatch_t;
/* Forward smio_err_e declaration enumeration */
typedef enum _smio_err_e smio_err_e;
/* Opaque smio_t structure */
......
......@@ -28,19 +28,19 @@ extern "C" {
(local_err != SMIO_ERR_FUNC_NOT_IMPL) ? local_err : SMIO_SUCCESS; \
})
#define SMIO_DISPATCH_FUNC_WRAPPER_GEN(func_name, ...) \
#define SMIO_DISPATCH_FUNC_WRAPPER_GEN(func_name, smio_mod_handler, ...) \
({ \
volatile const smio_mod_dispatch_t *smio_mod_dispatch = &_smio_mod_dispatch; \
smio_err_e local_err = SMIO_ERR_FUNC_NOT_IMPL; \
if (smio_mod_dispatch[th_args->smio_id].bootstrap_ops && \
smio_mod_dispatch[th_args->smio_id].bootstrap_ops->func_name) { \
local_err = smio_mod_dispatch[th_args->smio_id].bootstrap_ops->func_name (__VA_ARGS__); \
if (smio_mod_handler->bootstrap_ops && \
smio_mod_handler->bootstrap_ops->func_name) { \
local_err = smio_mod_handler->bootstrap_ops->func_name (__VA_ARGS__); \
} \
local_err; \
})
#define SMIO_DISPATCH_FUNC_WRAPPER(func_name, ...) \
SMIO_DISPATCH_FUNC_WRAPPER_GEN(func_name, self, ## __VA_ARGS__)
#define SMIO_DISPATCH_FUNC_WRAPPER(func_name, smio_mod_handler, ...) \
SMIO_DISPATCH_FUNC_WRAPPER_GEN(func_name, smio_mod_handler, self, ## __VA_ARGS__)
/* Attach an instance of sm_io to dev_io function pointer */
typedef smio_err_e (*attach_fp)(smio_t *self, devio_t *parent);
......@@ -106,14 +106,14 @@ typedef struct {
/* Thread boot args structure */
typedef struct {
struct _devio_t *parent; /* Pointer back to devo parent */
uint32_t smio_id; /* ID of the SMIO instance */
zsock_t *pipe_msg; /* Message PIPE to actor */
char *broker; /* Endpoint to connect to broker */
char *service; /* (part of) the service name to be exported */
int verbose; /* Print trace information to stdout*/
uint64_t base; /* SMIO base address */
uint32_t inst_id; /* SMIO instance ID */
struct _devio_t *parent; /* Pointer back to devo parent */
volatile const smio_mod_dispatch_t *smio_handler; /* SMIO table handler */
zsock_t *pipe_msg; /* Message PIPE to actor */
char *broker; /* Endpoint to connect to broker */
char *service; /* (part of) the service name to be exported */
int verbose; /* Print trace information to stdout*/
uint64_t base; /* SMIO base address */
uint32_t inst_id; /* SMIO instance ID */
} th_boot_args_t;
/***************** Our methods *****************/
......
......@@ -31,11 +31,11 @@ typedef struct {
/* Config thread args structure */
typedef struct {
uint32_t smio_id; /* ID of the SMIO instance */
uint32_t inst_id; /* SMIO instance ID */
char *broker; /* Endpoint to connect to broker */
char *service; /* Full name of the exported service */
char *log_file; /* Thread log file */
volatile const smio_mod_dispatch_t *smio_handler; /* SMIO table handler */
uint32_t inst_id; /* SMIO instance ID */
char *broker; /* Endpoint to connect to broker */
char *service; /* Full name of the exported service */
char *log_file; /* Thread log file */
} th_config_args_t;
/************************************************************/
......
......@@ -14,11 +14,11 @@ extern "C" {
#define SMIO_DISPATCH_END_ID 0xdeaddead
typedef struct {
struct _smio_mod_dispatch_t {
uint32_t id;
const char *name;
const smio_bootstrap_ops_t *bootstrap_ops;
} __attribute__ ((aligned (16))) smio_mod_dispatch_t;
} __attribute__ ((aligned (16)));
/*
* WARNING! Using SMIO_MOD_DECLARE requires .smio_mod_dispatch section in linker script
......
......@@ -42,7 +42,7 @@ void smio_startup (zsock_t *pipe, void *args)
th_boot_args_t *th_args = (th_boot_args_t *) args;
zsock_t *pipe_mgmt = pipe;
zsock_t *pipe_msg = th_args->pipe_msg;
volatile const smio_mod_dispatch_t *smio_mod_dispatch = &_smio_mod_dispatch;
volatile const smio_mod_dispatch_t *smio_mod_dispatch = th_args->smio_handler;
/* Signal parent we are initializing */
zsock_signal (pipe_mgmt, 0);
......@@ -52,7 +52,7 @@ void smio_startup (zsock_t *pipe, void *args)
char *inst_id_str = hutils_stringify_dec_key (th_args->inst_id);
ASSERT_ALLOC(inst_id_str, err_inst_id_str_alloc);
char *smio_service = hutils_concat_strings3 (th_args->service,
smio_mod_dispatch[th_args->smio_id].name, inst_id_str, ':');
smio_mod_dispatch->name, inst_id_str, ':');
ASSERT_ALLOC(smio_service, err_smio_service_alloc);
DBE_DEBUG (DBG_SM_IO | DBG_LVL_INFO, "[sm_io_bootstrap] SMIO Thread %s "
......@@ -64,7 +64,7 @@ void smio_startup (zsock_t *pipe, void *args)
ASSERT_ALLOC(self, err_self_alloc);
/* Call SMIO init function to finish initializing its internal strucutres */
smio_err_e err = SMIO_DISPATCH_FUNC_WRAPPER (init);
smio_err_e err = SMIO_DISPATCH_FUNC_WRAPPER (init, smio_mod_dispatch);
ASSERT_TEST(err == SMIO_SUCCESS, "Could not initialize SMIO", err_call_init);
/* Atach this SMIO instance to its parent */
err = smio_attach (self, th_args->parent);
......@@ -93,7 +93,7 @@ err_smio_export:
err_smio_get_exp_ops:
err_call_attach:
/* FIXME: Poll PIPE sockets and on receiving any message calls shutdown () */
SMIO_DISPATCH_FUNC_WRAPPER (shutdown);
SMIO_DISPATCH_FUNC_WRAPPER (shutdown, smio_mod_dispatch);
err_call_init:
/* Destroy what we did in _smio_new */
smio_destroy (&self);
......@@ -117,7 +117,7 @@ err_inst_id_str_alloc:
void smio_config_defaults (zsock_t *pipe, void *args)
{
th_config_args_t *th_args = (th_config_args_t *) args;
volatile const smio_mod_dispatch_t *smio_mod_dispatch = &_smio_mod_dispatch;
volatile const smio_mod_dispatch_t *smio_mod_dispatch = th_args->smio_handler;
/* Signal parent we are initializing */
zsock_signal (pipe, 0);
......@@ -127,7 +127,7 @@ void smio_config_defaults (zsock_t *pipe, void *args)
char *inst_id_str = hutils_stringify_dec_key (th_args->inst_id);
ASSERT_ALLOC(inst_id_str, err_inst_id_str_alloc);
char *smio_service = hutils_concat_strings3 (th_args->service,
smio_mod_dispatch[th_args->smio_id].name, inst_id_str, ':');
smio_mod_dispatch->name, inst_id_str, ':');
ASSERT_ALLOC(smio_service, err_smio_service_alloc);
DBE_DEBUG (DBG_SM_IO | DBG_LVL_INFO, "[sm_io_bootstrap] Config Thread %s "
......@@ -135,12 +135,12 @@ void smio_config_defaults (zsock_t *pipe, void *args)
DBE_DEBUG (DBG_SM_IO | DBG_LVL_INFO, "[sm_io_bootstrap] Config Thread %s "
"allocating resources ...\n", smio_service);
SMIO_DISPATCH_FUNC_WRAPPER_GEN(config_defaults, th_args->broker,
smio_service, th_args->log_file);
SMIO_DISPATCH_FUNC_WRAPPER_GEN(config_defaults, smio_mod_dispatch,
th_args->broker, smio_service, th_args->log_file);
/* We've finished configuring the SMIO. Tell DEVIO we are done */
char *smio_service_suffix = hutils_concat_strings_no_sep (
smio_mod_dispatch[th_args->smio_id].name, inst_id_str);
smio_mod_dispatch->name, inst_id_str);
ASSERT_ALLOC(smio_service_suffix, err_smio_service_suffix_alloc);
DBE_DEBUG (DBG_SM_IO | DBG_LVL_INFO, "[sm_io_bootstrap] Sending CONFIG DONE message over PIPE\n");
......
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