diff options
author | Robin Gareus <robin@gareus.org> | 2015-03-01 19:59:50 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2015-03-01 20:49:55 +0100 |
commit | d7727a77e0b19ecb2d1957d1e13d554dbed58243 (patch) | |
tree | b4bf35e94e2670c8e62a290cb5e364fa0b5b7a05 /libs/pbd/crossthread.posix.cc | |
parent | 60388f975c7731fbfa69327c2374cf83f39d85ce (diff) |
Xthread: blocking read + non-blocking write mode.
Needed for switching the butler to use Crossthreads.
Diffstat (limited to 'libs/pbd/crossthread.posix.cc')
-rw-r--r-- | libs/pbd/crossthread.posix.cc | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/libs/pbd/crossthread.posix.cc b/libs/pbd/crossthread.posix.cc index 44205e680d..6dbca9dcec 100644 --- a/libs/pbd/crossthread.posix.cc +++ b/libs/pbd/crossthread.posix.cc @@ -1,3 +1,5 @@ +#include <poll.h> + CrossThreadChannel::CrossThreadChannel (bool non_blocking) : receive_channel (0) { @@ -61,8 +63,37 @@ CrossThreadChannel::deliver (char msg) return ::write (fds[1], &msg, 1); } +bool +CrossThreadChannel::poll_for_request() +{ + struct pollfd pfd[1]; + pfd[0].fd = fds[0]; + pfd[0].events = POLLIN|POLLERR|POLLHUP; + while(true) { + if (poll (pfd, 1, -1) < 0) { + if (errno == EINTR) { + continue; + } + break; + } + if (pfd[0].revents & ~POLLIN) { + break; + } + + if (pfd[0].revents & POLLIN) { + return true; + } + } + return false; +} + int -CrossThreadChannel::receive (char& msg) +CrossThreadChannel::receive (char& msg, bool wait) { + if (wait) { + if (!poll_for_request ()) { + return -1; + } + } return ::read (fds[0], &msg, 1); } |