afb-api: Define the notion of group for concurrency
authorJosé Bollo <jose.bollo@iot.bzh>
Thu, 21 Sep 2017 05:57:24 +0000 (07:57 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Mon, 9 Oct 2017 12:08:32 +0000 (14:08 +0200)
Change-Id: Iafbbff8387bb1f8577cb7aeb6e8ed4b14ab1f4a4
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/afb-api-dbus.c
src/afb-api-so-v1.c
src/afb-api-so-v2.c
src/afb-api.h
src/afb-stub-ws.c
src/afb-xreq.c

index 2d03269..d31eda0 100644 (file)
@@ -610,7 +610,7 @@ int afb_api_dbus_add_client(const char *path, struct afb_apiset *apiset)
        /* record it as an API */
        afb_api.closure = api;
        afb_api.itf = &dbus_api_itf;
-       afb_api.noconcurrency = 0;
+       afb_api.group = NULL;
        if (afb_apiset_add(apiset, api->api, afb_api) < 0)
                goto error2;
 
index b885cf7..c69f294 100644 (file)
@@ -256,7 +256,7 @@ int afb_api_so_v1_add(const char *path, void *handle, struct afb_apiset *apiset)
                afb_export_rename(desc->export, desc->binding->v1.prefix);
        afb_api.closure = desc;
        afb_api.itf = &so_v1_api_itf;
-       afb_api.noconcurrency = 0;
+       afb_api.group = NULL;
        if (afb_apiset_add(apiset, afb_export_apiname(desc->export), afb_api) < 0) {
                ERROR("binding [%s] can't be registered...", path);
                goto error;
index 14a92a9..9d4caee 100644 (file)
@@ -264,7 +264,7 @@ int afb_api_so_v2_add_binding(const struct afb_binding_v2 *binding, void *handle
        /* records the binding */
        afb_api.closure = desc;
        afb_api.itf = &so_v2_api_itf;
-       afb_api.noconcurrency = binding->noconcurrency;
+       afb_api.group = binding->noconcurrency ? export : NULL;
        if (afb_apiset_add(apiset, afb_export_apiname(desc->export), afb_api) < 0) {
                ERROR("binding %s can't be registered to set %s...", afb_export_apiname(desc->export), afb_apiset_name(apiset));
                goto error;
index 1a14988..dd5d4e0 100644 (file)
@@ -35,7 +35,7 @@ struct afb_api
 {
        void *closure;
        struct afb_api_itf *itf;
-       unsigned noconcurrency: 1;
+       const void *group;
 };
 
 extern int afb_api_is_valid_name(const char *name);
index 83f07ca..bdc2c14 100644 (file)
@@ -680,7 +680,7 @@ struct afb_api afb_stub_ws_client_api(struct afb_stub_ws *stubws)
        assert(!stubws->listener); /* check client */
        api.closure = stubws;
        api.itf = &ws_api_itf;
-       api.noconcurrency = 0;
+       api.group = NULL;
        return api;
 }
 
index 696bf9d..9c0ba16 100644 (file)
@@ -1030,12 +1030,10 @@ void afb_xreq_process(struct afb_xreq *xreq, struct afb_apiset *apiset)
        xreq->context.api_key = api;
 
        /* check self locking */
-       if (!api->noconcurrency)
-               api = NULL;
-       else {
+       if (api->group) {
                caller = xreq->caller;
                while (caller) {
-                       if (caller->context.api_key == api) {
+                       if (((const struct afb_api *)caller->context.api_key)->group == api->group) {
                                /* noconcurrency lock detected */
                                ERROR("self-lock detected in call stack for API %s", xreq->api);
                                early_failure(xreq, "self-locked", "recursive self lock, API %s", xreq->api);
@@ -1047,7 +1045,7 @@ void afb_xreq_process(struct afb_xreq *xreq, struct afb_apiset *apiset)
 
        /* queue the request job */
        afb_xreq_unhooked_addref(xreq);
-       if (jobs_queue(api, afb_apiset_timeout_get(apiset), process_async, xreq) < 0) {
+       if (jobs_queue(api->group, afb_apiset_timeout_get(apiset), process_async, xreq) < 0) {
                /* TODO: allows or not to proccess it directly as when no threading? (see above) */
                ERROR("can't process job with threads: %m");
                early_failure(xreq, "cancelled", "not able to create a job for the task");