diff options
author | José Bollo <jose.bollo@iot.bzh> | 2017-03-28 17:46:32 +0200 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2017-03-28 17:46:32 +0200 |
commit | 162436f4ffbbf63d867735f7de5b78dcd684f890 (patch) | |
tree | 3c7a1f4b37829da57b1b9be1ecf027d753101a89 /src/tests | |
parent | 48827b7b9862ab5961f938f38a8667e15421a50c (diff) |
Refactor job to allow synchronous calls
The family of methods "jobs_invoke" make synchronous
job activation. It waits for the completion of the
job while still dispatching it internally and
providing the calling thread for processing any job
queued.
Change-Id: Id36a30789cc51245a7bbfca42f0122cf4ea623b2
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/test-thread.c | 22 | ||||
-rwxr-xr-x | src/tests/test-thread.sh | 2 |
2 files changed, 21 insertions, 3 deletions
diff --git a/src/tests/test-thread.c b/src/tests/test-thread.c index 2f0e1853..3ed31401 100644 --- a/src/tests/test-thread.c +++ b/src/tests/test-thread.c @@ -24,7 +24,7 @@ void unref(void *closure) { struct foo *foo = closure; if(!--foo->refcount) { - printf("%06d FREE\n", foo->value); + /* printf("%06d FREE\n", foo->value); */ free(foo); } } @@ -32,7 +32,7 @@ void unref(void *closure) void fail(void *closure, const char *status, const char *info) { struct foo *foo = closure; - printf("%06d ERROR %s\n", foo->value, status); + printf("%06d ABORT T%d %s\n", foo->value, (int)syscall(SYS_gettid), status); } struct afb_req_itf itf = { @@ -70,6 +70,17 @@ void process(struct afb_req req) // nanosleep(&ts, NULL); } +void terminate(int signum) +{ + printf("---------------- TERMINATE T%d (%d)\n", (int)syscall(SYS_gettid), signum); +#if 0 + jobs_terminate(); +#else + jobs_invoke0(0, jobs_terminate); +#endif + exit(0); +} + int main() { int i; @@ -85,6 +96,12 @@ int main() foo->refcount = 1; afb_thread_req_call(req, process, 5, (&ts) + (i % 7)); unref(foo); + if (i == 5000) +#if 1 + jobs_invoke0(0, terminate); +#else + jobs_queue0(NULL, 0, terminate); +#endif ts.tv_sec = 0; ts.tv_nsec = 1000000; // nanosleep(&ts, NULL); @@ -93,6 +110,7 @@ int main() ts.tv_nsec = 0; nanosleep(&ts, NULL); jobs_terminate(); + return 0; } diff --git a/src/tests/test-thread.sh b/src/tests/test-thread.sh index d5186d19..fe73516f 100755 --- a/src/tests/test-thread.sh +++ b/src/tests/test-thread.sh @@ -1,4 +1,4 @@ #!/bin/sh cc test-thread.c ../afb-thread.c ../verbose.c ../sig-monitor.c ../jobs.c -o test-thread -lrt -lpthread -I../../include -g -O2 -gdb ./test-thread +./test-thread |