#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
+
+#ifndef PLATFORM_WINDOWS
#include <poll.h>
+#endif
+
#include "pbd/error.h"
#include "pbd/pthread_utils.h"
#include "ardour/butler.h"
Butler::Butler(Session& s)
: SessionHandleRef (s)
- , thread(0)
+ , thread()
, audio_dstream_capture_buffer_size(0)
, audio_dstream_playback_buffer_size(0)
, midi_dstream_buffer_size(0)
}
}
+#ifndef PLATFORM_WINDOWS
int
Butler::setup_request_pipe ()
{
}
return 0;
}
+#endif
int
Butler::start_thread()
should_run = false;
+#ifndef PLATFORM_WINDOWS
if (setup_request_pipe() != 0) return -1;
+#endif
if (pthread_create_and_store ("disk butler", &thread, _thread_work, this)) {
error << _("Session: could not create butler thread") << endmsg;
void
Butler::terminate_thread ()
{
- if (thread) {
- void* status;
- queue_request (Request::Quit);
- pthread_join (thread, &status);
- }
+ void* status;
+ queue_request (Request::Quit);
+ pthread_join (thread, &status);
}
void *
bool
Butler::wait_for_requests ()
{
+#ifndef PLATFORM_WINDOWS
struct pollfd pfd[1];
pfd[0].fd = request_pipe[0];
}
}
return false;
+#else
+ m_request_sem.wait ();
+ return true;
+#endif
}
bool
Butler::dequeue_request (Request::Type& r)
{
+#ifndef PLATFORM_WINDOWS
char req;
size_t nread = ::read (request_pipe[0], &req, sizeof (req));
if (nread == 1) {
fatal << _("Error reading from butler request pipe") << endmsg;
/*NOTREACHED*/
}
+#else
+ r = (Request::Type) m_request_state.get();
+#endif
return false;
}
Request::Type req;
/* empty the pipe of all current requests */
+#ifdef PLATFORM_WINDOWS
+ dequeue_request (req);
+ {
+#else
while(dequeue_request(req)) {
+#endif
switch (req) {
case Request::Run:
break;
case Request::Quit:
- pthread_exit_pbd (0);
+ return 0;
/*NOTREACHED*/
break;
empty_pool_trash ();
}
- pthread_exit_pbd (0);
- /*NOTREACHED*/
return (0);
}
void
Butler::queue_request (Request::Type r)
{
+#ifndef PLATFORM_WINDOWS
char c = r;
(void) ::write (request_pipe[1], &c, 1);
+#else
+ m_request_state.set (r);
+ m_request_sem.post ();
+#endif
}
void
void
Butler::drop_references ()
{
+ cerr << "Butler drops pool trash\n";
SessionEvent::pool->set_trash (0);
}