--- src/oss4/oss.cc.orig	2015-05-31 03:28:37.000000000 +0500
+++ src/oss4/oss.cc	2015-10-18 17:11:46.124270000 +0500
@@ -20,12 +20,10 @@
  * the use of this software.
  */
 
-#include "oss.h"
-
 #include <libaudcore/audstrings.h>
 #include <libaudcore/runtime.h>
 
-#include <poll.h>
+#include "oss.h"
 
 constexpr StereoVolume to_stereo_volume(int vol)
     { return {vol & 0x00ff, vol >> 8}; }
@@ -42,9 +40,6 @@
  "exclusive", "FALSE",
  nullptr};
 
-static int poll_pipe[2];
-static pollfd poll_handles[2];
-
 bool OSSPlugin::init()
 {
     AUDDBG("Init.\n");
@@ -121,7 +116,7 @@
 static int open_device()
 {
     int res = -1;
-    int flags = O_WRONLY | O_NONBLOCK;
+    int flags = O_WRONLY;
     String device = aud_get_str("oss4", "device");
     String alt_device = aud_get_str("oss4", "alt_device");
 
@@ -147,59 +142,6 @@
     fd = -1;
 }
 
-static bool poll_setup(int fd)
-{
-    if (pipe(poll_pipe))
-    {
-        AUDERR("Failed to create pipe: %s.\n", strerror(errno));
-        return false;
-    }
-
-    if (fcntl(poll_pipe[0], F_SETFL, O_NONBLOCK))
-    {
-        AUDERR("Failed to set O_NONBLOCK on pipe: %s.\n", strerror(errno));
-        close(poll_pipe[0]);
-        close(poll_pipe[1]);
-        return false;
-    }
-
-    poll_handles[0].fd = poll_pipe[0];
-    poll_handles[0].events = POLLIN;
-    poll_handles[1].fd = fd;
-    poll_handles[1].events = POLLOUT;
-
-    return true;
-}
-
-static void poll_sleep()
-{
-    if (poll(poll_handles, 2, -1) < 0)
-    {
-        AUDERR("Failed to poll: %s.\n", strerror(errno));
-        return;
-    }
-
-    if (poll_handles[0].revents & POLLIN)
-    {
-        char c;
-        while (read(poll_pipe[0], &c, 1) == 1)
-            ;
-    }
-}
-
-static void poll_wake()
-{
-    const char c = 0;
-    if (write(poll_pipe[1], &c, 1) < 0)
-        AUDERR("Failed to write to pipe: %s.\n", strerror(errno));
-}
-
-static void poll_cleanup()
-{
-    close(poll_pipe[0]);
-    close(poll_pipe[1]);
-}
-
 bool OSSPlugin::open_audio(int aud_format, int rate, int channels)
 {
     AUDDBG("Opening audio.\n");
@@ -209,9 +151,6 @@
 
     CHECK_NOISY(m_fd = open_device);
 
-    if (!poll_setup(m_fd))
-        goto CLOSE;
-
     format = oss_convert_aud_format(aud_format);
 
     if (!set_format(format, rate, channels))
@@ -237,8 +176,6 @@
     return true;
 
 FAILED:
-    poll_cleanup();
-CLOSE:
     close_device(m_fd);
     return false;
 }
@@ -247,23 +184,24 @@
 {
     AUDDBG("Closing audio.\n");
 
-    poll_cleanup();
     close_device(m_fd);
 }
 
 int OSSPlugin::write_audio(const void *data, int length)
 {
-    if (m_paused)
-        return 0;
-
-    int written = write(m_fd, data, length);
+    int written = 0;
 
-    if (written < 0)
+    if (!m_paused)
     {
-        if (errno != EAGAIN)
-            DESCRIBE_ERROR;
+        written = write(m_fd, data, length);
+
+        if (written < 0)
+        {
+            if (errno != EAGAIN)
+                DESCRIBE_ERROR;
 
-        return 0;
+            written = 0;
+        }
     }
 
     return written;
@@ -271,7 +209,12 @@
 
 void OSSPlugin::period_wait()
 {
-    poll_sleep();
+    pthread_mutex_lock(&m_mutex);
+    if (m_paused)
+    {
+        pthread_cond_wait(&m_cond, &m_mutex);
+    }
+    pthread_mutex_unlock(&m_mutex);
 }
 
 void OSSPlugin::drain()
@@ -298,7 +241,7 @@
     CHECK(ioctl, m_fd, SNDCTL_DSP_RESET, nullptr);
 
 FAILED:
-    poll_wake();
+    pthread_cond_broadcast(&m_cond);
 }
 
 void OSSPlugin::pause(bool pause)
@@ -313,7 +256,11 @@
 
 FAILED:
 #endif
+
+    pthread_mutex_lock(&m_mutex);
     m_paused = pause;
+    pthread_cond_broadcast(&m_cond);
+    pthread_mutex_unlock(&m_mutex);
 }
 
 StereoVolume OSSPlugin::get_volume()
@@ -351,10 +298,8 @@
     if (aud_get_bool("oss4", "save_volume"))
         aud_set_int("oss4", "volume", vol);
 
-    if (m_fd == -1 || !m_ioctl_vol)
-        return;
-
-    CHECK(ioctl, m_fd, SNDCTL_DSP_SETPLAYVOL, &vol);
+    if (m_ioctl_vol && m_fd != -1)
+        CHECK(ioctl, m_fd, SNDCTL_DSP_SETPLAYVOL, &vol);
 
     return;
 
