X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fpbd%2Fcrossthread.cc;h=2ffede5163aecc736372818fd82ddb934b2d8d42;hb=e4514117190f398a0a672e25ecb48bc53cf9414b;hp=2bcb444b366ef322c1468231d7efa313d478ba0a;hpb=b8b55ef0036bbef9a2961f03f44387ea8c89456a;p=ardour.git diff --git a/libs/pbd/crossthread.cc b/libs/pbd/crossthread.cc index 2bcb444b36..2ffede5163 100644 --- a/libs/pbd/crossthread.cc +++ b/libs/pbd/crossthread.cc @@ -30,7 +30,7 @@ using namespace std; using namespace PBD; using namespace Glib; -CrossThreadChannel::CrossThreadChannel () +CrossThreadChannel::CrossThreadChannel (bool non_blocking) { _ios = 0; fds[0] = -1; @@ -41,14 +41,16 @@ CrossThreadChannel::CrossThreadChannel () return; } - if (fcntl (fds[0], F_SETFL, O_NONBLOCK)) { - error << "cannot set non-blocking mode for x-thread pipe (read) (" << ::strerror (errno) << ')' << endmsg; - return; - } - - if (fcntl (fds[1], F_SETFL, O_NONBLOCK)) { - error << "cannot set non-blocking mode for x-thread pipe (write) (%2)" << ::strerror (errno) << ')' << endmsg; - return; + if (non_blocking) { + if (fcntl (fds[0], F_SETFL, O_NONBLOCK)) { + error << "cannot set non-blocking mode for x-thread pipe (read) (" << ::strerror (errno) << ')' << endmsg; + return; + } + + if (fcntl (fds[1], F_SETFL, O_NONBLOCK)) { + error << "cannot set non-blocking mode for x-thread pipe (write) (%2)" << ::strerror (errno) << ')' << endmsg; + return; + } } } @@ -72,7 +74,7 @@ void CrossThreadChannel::wakeup () { char c = 0; - ::write (fds[1], &c, 1); + (void) ::write (fds[1], &c, 1); } RefPtr @@ -102,5 +104,17 @@ CrossThreadChannel::drain (int fd) { /* drain selectable fd */ char buf[64]; - while (::read (fd, buf, sizeof (buf)) > 0); + while (::read (fd, buf, sizeof (buf)) > 0) {}; +} + +int +CrossThreadChannel::deliver (char msg) +{ + return ::write (fds[1], &msg, 1); +} + +int +CrossThreadChannel::receive (char& msg) +{ + return ::read (fds[0], &msg, 1); }