graph.c: do not warn when the graph is canceled during bt_graph_run()
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 7 Jun 2017 20:12:56 +0000 (16:12 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 9 Jun 2017 21:03:27 +0000 (17:03 -0400)
If the graph is canceled during bt_graph_run()'s loop, do not warn: this
was intentionally done during the execution by another thread or by a
signal handler. Log a debug message and quit with the usual
BT_GRAPH_STATUS_CANCELED status.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
lib/graph/graph.c

index c66b4f3cd8655b4fb6ebba932cf3e86f90f91620..1dc7b819c9db02c69d7a3985aca4c0ebb45cfb44 100644 (file)
@@ -417,26 +417,15 @@ end:
        return status;
 }
 
-enum bt_graph_status bt_graph_consume(struct bt_graph *graph)
+static
+enum bt_graph_status bt_graph_consume_no_check(struct bt_graph *graph)
 {
        struct bt_component *sink;
        enum bt_graph_status status = BT_GRAPH_STATUS_OK;
        enum bt_component_status comp_status;
        GList *current_node;
 
-       if (!graph) {
-               BT_LOGW_STR("Invalid parameter: graph is NULL.");
-               status = BT_GRAPH_STATUS_INVALID;
-               goto end;
-       }
-
-       BT_LOGV("Making sink consume: addr=%p", graph);
-
-       if (graph->canceled) {
-               BT_LOGW_STR("Invalid parameter: graph is canceled.");
-               status = BT_GRAPH_STATUS_CANCELED;
-               goto end;
-       }
+       BT_LOGV("Making next sink consume: addr=%p", graph);
 
        if (g_queue_is_empty(graph->sinks_to_consume)) {
                BT_LOGV_STR("Graph's sink queue is empty: end of graph.");
@@ -486,6 +475,29 @@ end:
        return status;
 }
 
+enum bt_graph_status bt_graph_consume(struct bt_graph *graph)
+{
+       enum bt_graph_status status = BT_GRAPH_STATUS_OK;
+
+       if (!graph) {
+               BT_LOGW_STR("Invalid parameter: graph is NULL.");
+               status = BT_GRAPH_STATUS_INVALID;
+               goto end;
+       }
+
+       if (graph->canceled) {
+               BT_LOGW("Invalid parameter: graph is canceled: "
+                       "graph-addr=%p", graph);
+               status = BT_GRAPH_STATUS_CANCELED;
+               goto end;
+       }
+
+       status = bt_graph_consume_no_check(graph);
+
+end:
+       return status;
+}
+
 enum bt_graph_status bt_graph_run(struct bt_graph *graph)
 {
        enum bt_graph_status status = BT_GRAPH_STATUS_OK;
@@ -496,9 +508,29 @@ enum bt_graph_status bt_graph_run(struct bt_graph *graph)
                goto end;
        }
 
+       if (graph->canceled) {
+               BT_LOGW("Invalid parameter: graph is canceled: "
+                       "graph-addr=%p", graph);
+               status = BT_GRAPH_STATUS_CANCELED;
+               goto end;
+       }
+
        BT_LOGV("Running graph: addr=%p", graph);
 
        do {
+               /*
+                * Check if the graph is canceled at each iteration. If
+                * the graph was canceled by another thread or by a
+                * signal, this is not a warning nor an error, it was
+                * intentional: log with a DEBUG level only.
+                */
+               if (graph->canceled) {
+                       BT_LOGD("Stopping the graph: graph is canceled: "
+                               "graph-addr=%p", graph);
+                       status = BT_GRAPH_STATUS_CANCELED;
+                       goto end;
+               }
+
                status = bt_graph_consume(graph);
                if (status == BT_GRAPH_STATUS_AGAIN) {
                        /*
This page took 0.02603 seconds and 4 git commands to generate.