graph: remove scheduler2

Move graph code into graph.h
This commit is contained in:
Wim Taymans 2019-01-08 11:56:44 +01:00
parent b0f4be5fbc
commit d12148cfba
10 changed files with 44 additions and 158 deletions

View file

@ -1,96 +0,0 @@
/* Simple Plugin API
*
* Copyright © 2018 Wim Taymans
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef __SPA_GRAPH_SCHEDULER_H__
#define __SPA_GRAPH_SCHEDULER_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/graph/graph.h>
struct spa_graph_data {
struct spa_graph *graph;
};
static inline void spa_graph_data_init(struct spa_graph_data *data,
struct spa_graph *graph)
{
data->graph = graph;
}
static inline int spa_graph_impl_run(void *data)
{
struct spa_graph_data *d = (struct spa_graph_data *) data;
struct spa_graph *g = d->graph;
struct spa_graph_node *n, *tmp;
struct spa_list pending;
spa_debug("graph %p run", d->graph);
spa_graph_state_reset(g->state);
spa_list_init(&pending);
spa_list_for_each(n, &g->nodes, link) {
struct spa_graph_state *s = n->state;
spa_graph_state_reset(s);
spa_debug("graph %p node %p: state %p add %d status %d", g, n,
s, s->pending, s->status);
if (s->pending == 0)
spa_list_append(&pending, &n->sched_link);
}
spa_list_for_each_safe(n, tmp, &pending, sched_link)
spa_graph_node_process(n);
return 0;
}
static inline int spa_graph_impl_finish(void *data)
{
struct spa_graph_data *d = (struct spa_graph_data *) data;
struct spa_graph *g = d->graph;
spa_debug("graph %p finish", d->graph);
if (g->parent)
spa_graph_node_trigger(g->parent);
return 0;
}
static const struct spa_graph_callbacks spa_graph_impl_default = {
SPA_VERSION_GRAPH_CALLBACKS,
.run = spa_graph_impl_run,
.finish = spa_graph_impl_finish,
};
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_GRAPH_SCHEDULER_H__ */

View file

@ -75,24 +75,11 @@ static inline int spa_graph_link_trigger(struct spa_graph_link *link)
return state->status;
}
struct spa_graph_callbacks {
#define SPA_VERSION_GRAPH_CALLBACKS 0
uint32_t version;
int (*run) (void *data);
int (*finish) (void *data);
};
#define spa_graph_run(g) ((g)->callbacks->run((g)->callbacks_data))
#define spa_graph_finish(g) ((g)->callbacks->finish((g)->callbacks_data))
struct spa_graph {
uint32_t flags; /* flags */
struct spa_graph_node *parent; /* parent node or NULL when driver */
struct spa_graph_state *state; /* state of graph */
struct spa_list nodes; /* list of nodes of this graph */
const struct spa_graph_callbacks *callbacks;
void *callbacks_data;
};
struct spa_graph_node_callbacks {
@ -130,6 +117,49 @@ struct spa_graph_port {
struct spa_graph_port *peer; /**< peer */
};
static inline int spa_graph_run(struct spa_graph *graph)
{
struct spa_graph_node *n, *tmp;
struct spa_list pending;
spa_debug("graph %p run", graph);
spa_graph_state_reset(graph->state);
spa_list_init(&pending);
spa_list_for_each(n, &graph->nodes, link) {
struct spa_graph_state *s = n->state;
spa_graph_state_reset(s);
spa_debug("graph %p node %p: state %p add %d status %d", graph, n,
s, s->pending, s->status);
if (s->pending == 0)
spa_list_append(&pending, &n->sched_link);
}
spa_list_for_each_safe(n, tmp, &pending, sched_link)
spa_graph_node_process(n);
return 0;
}
static inline int spa_graph_node_trigger(struct spa_graph_node *node)
{
struct spa_graph_link *l, *t;
spa_debug("node %p trigger", node);
spa_list_for_each_safe(l, t, &node->links, link)
spa_graph_link_trigger(l);
return 0;
}
static inline int spa_graph_finish(struct spa_graph *graph)
{
spa_debug("graph %p finish", graph);
if (graph->parent)
spa_graph_node_trigger(graph->parent);
return 0;
}
static inline int spa_graph_link_signal_node(void *data)
{
struct spa_graph_node *node = (struct spa_graph_node *)data;
@ -153,15 +183,6 @@ static inline void spa_graph_init(struct spa_graph *graph, struct spa_graph_stat
spa_debug("graph %p init state %p", graph, state);
}
static inline void
spa_graph_set_callbacks(struct spa_graph *graph,
const struct spa_graph_callbacks *callbacks,
void *data)
{
graph->callbacks = callbacks;
graph->callbacks_data = data;
}
static inline void
spa_graph_link_add(struct spa_graph_node *out,
struct spa_graph_state *state,
@ -196,14 +217,6 @@ spa_graph_node_init(struct spa_graph_node *node, struct spa_graph_state *state)
spa_debug("node %p init state %p", node, state);
}
static inline int spa_graph_node_trigger(struct spa_graph_node *node)
{
struct spa_graph_link *l, *t;
spa_debug("node %p trigger", node);
spa_list_for_each_safe(l, t, &node->links, link)
spa_graph_link_trigger(l);
return 0;
}
static inline int spa_graph_node_impl_sub_process(void *data, struct spa_graph_node *node)
{