diff options
author | Jimmy Rubin <jimmy.rubin@stericsson.com> | 2011-07-06 11:45:38 +0200 |
---|---|---|
committer | Robert LIND <robert.lind@stericsson.com> | 2011-07-08 12:56:37 +0200 |
commit | 2f2b4338446051aba25188003ce37fc796fc3f7d (patch) | |
tree | 154bedda202f7855c5b5a15eb53c292252831a03 /src | |
parent | 144e7e08bddcfc6627eb9d7b9648c7188af5e51b (diff) |
[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 <jimmy.rubin@stericsson.com>
Change-Id: I289d1dcd68398c3c1ba489785b24289455304e58
Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/26664
Reviewed-by: QATOOLS
Reviewed-by: QATEST
Tested-by: Jimmy RUBIN <jimmy.rubin@stericsson.com>
Reviewed-by: Per-Daniel OLSSON <per-daniel.olsson@stericsson.com>
Reviewed-by: Robert LIND <robert.lind@stericsson.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/blt_b2r2.c | 46 |
1 files 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; |