jobs: Ensure releasing event loop 81/19981/1 6.99.5 guppy/6.99.5 guppy_6.99.5
authorJose Bollo <jose.bollo@iot.bzh>
Wed, 6 Feb 2019 16:16:09 +0000 (17:16 +0100)
committerJosé Bollo <jose.bollo@iot.bzh>
Thu, 7 Feb 2019 09:35:15 +0000 (10:35 +0100)
The internal functions blocking threads
for implementing call_sync were not releasing
the event loop, leading to deafness of the
binder.

Include a tuto-4 that reproduce the issue
on a binder with the bug and that also shows
interesting usages of the binder.

Bug-AGL: SPEC-2161

Change-Id: I83ad4d55d721a6046e798a5e06967df4dd5a7284
Signed-off-by: Jose Bollo <jose.bollo@iot.bzh>
bindings/tutorial/CMakeLists.txt
bindings/tutorial/tuto-4.c [new file with mode: 0644]
src/jobs.c

index 5c19bb8..b45851f 100644 (file)
@@ -32,5 +32,6 @@ ENDMACRO(tuto)
 tuto(1 c)
 tuto(2 c)
 tuto(3 cpp)
+tuto(4 c)
 
 tuto(app1 c)
diff --git a/bindings/tutorial/tuto-4.c b/bindings/tutorial/tuto-4.c
new file mode 100644 (file)
index 0000000..cb909fd
--- /dev/null
@@ -0,0 +1,29 @@
+#define AFB_BINDING_VERSION 3
+#include <afb/afb-binding.h>
+
+void hello(afb_req_t req)
+{
+       AFB_REQ_DEBUG(req, "hello world");
+       afb_req_reply(req, NULL, NULL, "hello world");
+}
+
+const afb_verb_t verbs[] = {
+       { .verb="hello", .callback=hello },
+       { .verb=NULL }
+};
+
+
+static int init(afb_api_t api)
+{
+       int rc = afb_api_require_api(api, "hello", 1);
+       if (!rc)
+               rc = afb_api_call_sync(api, "hello", "ping", NULL, NULL, NULL, NULL);
+       return rc;
+}
+
+const afb_binding_t afbBindingExport = {
+       .api = "tuto-4",
+       .verbs = verbs,
+       .init = init
+};
+
index 4a88c30..d06d24c 100644 (file)
@@ -337,7 +337,7 @@ static void evloop_release()
 {
        struct thread *nh, *ct = current_thread;
 
-       if (evloop.holder == ct) {
+       if (ct && evloop.holder == ct) {
                nh = ct->nholder;
                evloop.holder = nh;
                if (nh)
@@ -397,6 +397,7 @@ static void evloop_acquire()
  */
 static void thread_enter(volatile struct thread *me)
 {
+       evloop_release();
        /* initialize description of itself and link it in the list */
        me->tid = pthread_self();
        me->stop = 0;