2 Copyright (C) 2009 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include "pbd/error.h"
27 #include "pbd/crossthread.h"
33 CrossThreadChannel::CrossThreadChannel ()
40 error << "cannot create x-thread pipe for read (%2)" << ::strerror (errno) << endmsg;
44 if (fcntl (fds[0], F_SETFL, O_NONBLOCK)) {
45 error << "cannot set non-blocking mode for x-thread pipe (read) (" << ::strerror (errno) << ')' << endmsg;
49 if (fcntl (fds[1], F_SETFL, O_NONBLOCK)) {
50 error << "cannot set non-blocking mode for x-thread pipe (write) (%2)" << ::strerror (errno) << ')' << endmsg;
55 CrossThreadChannel::~CrossThreadChannel ()
72 CrossThreadChannel::wakeup ()
75 (void) ::write (fds[1], &c, 1);
79 CrossThreadChannel::ios ()
82 _ios = new RefPtr<IOSource> (IOSource::create (fds[0], IOCondition(IO_IN|IO_PRI|IO_ERR|IO_HUP|IO_NVAL)));
88 CrossThreadChannel::drop_ios ()
95 CrossThreadChannel::drain ()
101 CrossThreadChannel::drain (int fd)
103 /* drain selectable fd */
105 while (::read (fd, buf, sizeof (buf)) > 0);
109 CrossThreadChannel::deliver (char msg)
111 return ::write (fds[1], &msg, 1);
115 CrossThreadChannel::receive (char& msg)
117 return ::read (fds[0], &msg, 1);