From 2f2b4338446051aba25188003ce37fc796fc3f7d Mon Sep 17 00:00:00 2001 From: Jimmy Rubin Date: Wed, 6 Jul 2011 11:45:38 +0200 Subject: [b2r2lib] Add handling of other events than POLLIN In the callback thread a poll is performed on the blt handle in order to know if the thread should be terminated or not. When poll returns OK (>0) the event field can contain other events than POLLIN. If another event has occurred the thread has to be terminated because it is likely that the blt handle is closed. ST-Ericsson ID: 350511, 342717, 350544 ST-Ericsson FOSS-OUT ID: Trivial Signed-off-by: Jimmy Rubin Change-Id: I289d1dcd68398c3c1ba489785b24289455304e58 Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/26664 Reviewed-by: QATOOLS Reviewed-by: QATEST Tested-by: Jimmy RUBIN Reviewed-by: Per-Daniel OLSSON Reviewed-by: Robert LIND --- src/blt_b2r2.c | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/src/blt_b2r2.c b/src/blt_b2r2.c index 5a73969..02f3bc1 100644 --- a/src/blt_b2r2.c +++ b/src/blt_b2r2.c @@ -123,28 +123,44 @@ static void free_handle(int handle) { static void *callback_thread_run(void *arg) { while (1) { + int result; struct pollfd fds; struct b2r2_blt_report report; fds.fd = (int)arg; fds.events = POLLIN; - if (poll(&fds, 1, -1) <= 0) { - /* We assume that this is because the device was closed */ - pthread_exit(NULL); - break; - } else { - ssize_t count; - - memset(&report, 0, sizeof(report)); - count = read(fds.fd, &report, sizeof(report)); - if (count < 0) { - LOGE2("Could not read report from b2r2 device (%s)", + result = poll(&fds, 1, -1); + switch (result) { + case 0: + /* timeout occurred */ + pthread_exit(NULL); + break; + case -1: + /* We assume that this is because the device was closed */ + LOGE2("poll returned (%s)", + strerror(errno)); + pthread_exit(NULL); + break; + default: + if (fds.revents & POLLIN) { + ssize_t count; + memset(&report, 0, sizeof(report)); + count = read(fds.fd, &report, sizeof(report)); + if (count < 0) { + LOGE2("Could not read report from b2r2 device (%s)", + strerror(errno)); + } else if (report.report1 != 0) { + void (*callback)(int, uint32_t) = (void*)report.report1; + callback(report.request_id, (uint32_t)report.report2); + } + } else { + /* We assume that this is because the device was closed */ + LOGE2("Other event than POLLIN (%s)", strerror(errno)); - } else if (report.report1 != 0) { - void (*callback)(int, uint32_t) = (void*)report.report1; - callback(report.request_id, (uint32_t)report.report2); - } + pthread_exit(NULL); + } + break; } } return NULL; -- cgit v1.2.3