mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
inline *_type() functions
This commit is contained in:
parent
3b99227537
commit
7798f09a35
4 changed files with 30 additions and 27 deletions
|
@ -81,6 +81,12 @@ int hook_process_list(struct vlist *hs, struct sample *smps[], unsigned cnt);
|
|||
/** Compare two hook functions with their priority. Used by vlist_sort() */
|
||||
int hook_cmp_priority(const void *a, const void *b);
|
||||
|
||||
static inline
|
||||
struct hook_type * hook_type(struct hook *h)
|
||||
{
|
||||
return h->_vt;
|
||||
}
|
||||
|
||||
/** Parses an object of hooks
|
||||
*
|
||||
* Example:
|
||||
|
|
|
@ -199,7 +199,11 @@ int node_poll_fds(struct node *n, int fds[]);
|
|||
|
||||
int node_netem_fds(struct node *n, int fds[]);
|
||||
|
||||
struct node_type * node_type(struct node *n);
|
||||
static inline
|
||||
struct node_type * node_type(struct node *n)
|
||||
{
|
||||
return n->_vt;
|
||||
}
|
||||
|
||||
struct memory_type * node_memory_type(struct node *n, struct memory_type *parent);
|
||||
|
||||
|
|
38
lib/hook.c
38
lib/hook.c
|
@ -45,7 +45,7 @@ int hook_init(struct hook *h, struct hook_type *vt, struct path *p, struct node
|
|||
h->_vt = vt;
|
||||
h->_vd = alloc(vt->size);
|
||||
|
||||
ret = h->_vt->init ? h->_vt->init(h) : 0;
|
||||
ret = hook_type(h)->init ? hook_type(h)->init(h) : 0;
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
|
@ -66,9 +66,9 @@ int hook_parse(struct hook *h, json_t *cfg)
|
|||
"enabled", &h->enabled
|
||||
);
|
||||
if (ret)
|
||||
jerror(&err, "Failed to parse configuration of hook '%s'", hook_type_name(h->_vt));
|
||||
jerror(&err, "Failed to parse configuration of hook '%s'", hook_type_name(hook_type(h)));
|
||||
|
||||
ret = h->_vt->parse ? h->_vt->parse(h, cfg) : 0;
|
||||
ret = hook_type(h)->parse ? hook_type(h)->parse(h, cfg) : 0;
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
|
@ -84,7 +84,7 @@ int hook_destroy(struct hook *h)
|
|||
|
||||
assert(h->state != STATE_DESTROYED);
|
||||
|
||||
ret = h->_vt->destroy ? h->_vt->destroy(h) : 0;
|
||||
ret = hook_type(h)->destroy ? hook_type(h)->destroy(h) : 0;
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
|
@ -101,10 +101,10 @@ int hook_start(struct hook *h)
|
|||
if (!h->enabled)
|
||||
return 0;
|
||||
|
||||
if (h->_vt->start) {
|
||||
debug(LOG_HOOK | 10, "Start hook %s: priority=%d", hook_type_name(h->_vt), h->priority);
|
||||
if (hook_type(h)->start) {
|
||||
debug(LOG_HOOK | 10, "Start hook %s: priority=%d", hook_type_name(hook_type(h)), h->priority);
|
||||
|
||||
return h->_vt->start(h);
|
||||
return hook_type(h)->start(h);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
|
@ -115,10 +115,10 @@ int hook_stop(struct hook *h)
|
|||
if (!h->enabled)
|
||||
return 0;
|
||||
|
||||
if (h->_vt->stop) {
|
||||
debug(LOG_HOOK | 10, "Stopping hook %s: priority=%d", hook_type_name(h->_vt), h->priority);
|
||||
if (hook_type(h)->stop) {
|
||||
debug(LOG_HOOK | 10, "Stopping hook %s: priority=%d", hook_type_name(hook_type(h)), h->priority);
|
||||
|
||||
return h->_vt->stop(h);
|
||||
return hook_type(h)->stop(h);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
|
@ -129,10 +129,10 @@ int hook_periodic(struct hook *h)
|
|||
if (!h->enabled)
|
||||
return 0;
|
||||
|
||||
if (h->_vt->periodic) {
|
||||
debug(LOG_HOOK | 10, "Periodic hook %s: priority=%d", hook_type_name(h->_vt), h->priority);
|
||||
if (hook_type(h)->periodic) {
|
||||
debug(LOG_HOOK | 10, "Periodic hook %s: priority=%d", hook_type_name(hook_type(h)), h->priority);
|
||||
|
||||
return h->_vt->periodic(h);
|
||||
return hook_type(h)->periodic(h);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
|
@ -143,10 +143,10 @@ int hook_restart(struct hook *h)
|
|||
if (!h->enabled)
|
||||
return 0;
|
||||
|
||||
if (h->_vt->restart) {
|
||||
debug(LOG_HOOK | 10, "Restarting hook %s: priority=%d", hook_type_name(h->_vt), h->priority);
|
||||
if (hook_type(h)->restart) {
|
||||
debug(LOG_HOOK | 10, "Restarting hook %s: priority=%d", hook_type_name(hook_type(h)), h->priority);
|
||||
|
||||
return h->_vt->restart(h);
|
||||
return hook_type(h)->restart(h);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
|
@ -157,10 +157,10 @@ int hook_process(struct hook *h, struct sample *smps[], unsigned *cnt)
|
|||
if (!h->enabled)
|
||||
return 0;
|
||||
|
||||
if (h->_vt->process) {
|
||||
debug(LOG_HOOK | 10, "Process hook %s: priority=%d, cnt=%d", hook_type_name(h->_vt), h->priority, *cnt);
|
||||
if (hook_type(h)->process) {
|
||||
debug(LOG_HOOK | 10, "Process hook %s: priority=%d, cnt=%d", hook_type_name(hook_type(h)), h->priority, *cnt);
|
||||
|
||||
return h->_vt->process(h, smps, cnt);
|
||||
return hook_type(h)->process(h, smps, cnt);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
|
|
|
@ -704,13 +704,6 @@ int node_netem_fds(struct node *n, int fds[])
|
|||
return node_type(n)->netem_fds ? node_type(n)->netem_fds(n, fds) : -1;
|
||||
}
|
||||
|
||||
struct node_type * node_type(struct node *n)
|
||||
{
|
||||
assert(n->state != STATE_DESTROYED);
|
||||
|
||||
return n->_vt;
|
||||
}
|
||||
|
||||
struct memory_type * node_memory_type(struct node *n, struct memory_type *parent)
|
||||
{
|
||||
return node_type(n)->memory_type ? node_type(n)->memory_type(n, parent) : &memory_hugepage;
|
||||
|
|
Loading…
Add table
Reference in a new issue