Index: hdtvrecorder.h
===================================================================
--- hdtvrecorder.h	(revision 13379)
+++ hdtvrecorder.h	(working copy)
@@ -85,8 +85,8 @@
     // Data for managing the device ringbuffer
     struct {
         pthread_t        thread;
-        mutable pthread_mutex_t lock;
-        mutable pthread_mutex_t lock_stats;
+        mutable QMutex lock;
+        mutable QMutex lock_stats;
 
         bool             run;
         bool             eof;
Index: hdtvrecorder.cpp
===================================================================
--- hdtvrecorder.cpp	(revision 13379)
+++ hdtvrecorder.cpp	(working copy)
@@ -128,8 +128,6 @@
 
     ringbuf.run = false;
     ringbuf.buffer = 0;
-    pthread_mutex_init(&ringbuf.lock, NULL);
-    pthread_mutex_init(&ringbuf.lock_stats, NULL);
     loop = random() % (report_loops / 2);
 }
 
@@ -156,8 +154,6 @@
 HDTVRecorder::~HDTVRecorder()
 {
     TeardownAll();
-    pthread_mutex_destroy(&ringbuf.lock);
-    pthread_mutex_destroy(&ringbuf.lock_stats);
 }
 
 void HDTVRecorder::SetOptionsFromProfile(RecordingProfile *profile,
@@ -296,27 +292,27 @@
     size_t    read_size;
     bool      run, request_pause, paused;
 
-    pthread_mutex_lock(&ringbuf.lock);
+    ringbuf.lock.lock();
     ringbuf.run = true;
-    pthread_mutex_unlock(&ringbuf.lock);
+    ringbuf.lock.unlock();
 
     for (;;)
     {
-        pthread_mutex_lock(&ringbuf.lock);
+        ringbuf.lock.lock();
         run = ringbuf.run;
         unused = ringbuf.size - ringbuf.used;
         request_pause = ringbuf.request_pause;
         paused = ringbuf.paused;
-        pthread_mutex_unlock(&ringbuf.lock);
+        ringbuf.lock.unlock();
 
         if (!run)
             break;
 
         if (request_pause)
         {
-            pthread_mutex_lock(&ringbuf.lock);
+            ringbuf.lock.lock();
             ringbuf.paused = true;
-            pthread_mutex_unlock(&ringbuf.lock);
+            ringbuf.lock.unlock();
 
             pauseWait.wakeAll();
             if (tvrec)
@@ -327,11 +323,10 @@
         }
         else if (paused)
         {
-            pthread_mutex_lock(&ringbuf.lock);
+            QMutexLocker locker(&ringbuf.lock);
             ringbuf.writePtr = ringbuf.readPtr = ringbuf.buffer;
             ringbuf.used = 0;
             ringbuf.paused = false;
-            pthread_mutex_unlock(&ringbuf.lock);
         }
 
         contiguous = ringbuf.endPtr - ringbuf.writePtr;
@@ -339,11 +334,11 @@
         while (unused < TSPacket::SIZE && contiguous > TSPacket::SIZE)
         {
             usleep(500);
+            
+            QMutexLocker locker(&ringbuf.lock);
 
-            pthread_mutex_lock(&ringbuf.lock);
             unused = ringbuf.size - ringbuf.used;
             request_pause = ringbuf.request_pause;
-            pthread_mutex_unlock(&ringbuf.lock);
 
             if (request_pause)
                 break;
@@ -367,10 +362,8 @@
             perror("read");
             if (++errcnt > 5)
             {
-                pthread_mutex_lock(&ringbuf.lock);
+                QMutexLocker locker(&ringbuf.lock);
                 ringbuf.error = true;
-                pthread_mutex_unlock(&ringbuf.lock);
-
                 break;
             }
 
@@ -383,11 +376,8 @@
             {
                 VERBOSE(VB_IMPORTANT, QString("HD8 %1 end of file found.")
                         .arg(videodevice));
-
-                pthread_mutex_lock(&ringbuf.lock);
+                QMutexLocker locker(&ringbuf.lock);
                 ringbuf.eof = true;
-                pthread_mutex_unlock(&ringbuf.lock);
-
                 break;
             }
             usleep(500);
@@ -396,21 +386,22 @@
 
         errcnt = 0;
 
-        pthread_mutex_lock(&ringbuf.lock);
+        ringbuf.lock.lock();
         ringbuf.used += len;
         used = ringbuf.used;
         ringbuf.writePtr += len;
-        pthread_mutex_unlock(&ringbuf.lock);
+        ringbuf.lock.unlock();
 
 #ifdef REPORT_RING_STATS
-        pthread_mutex_lock(&ringbuf.lock_stats);
+        ringbuf.lock_stats.lock();
 
         if (ringbuf.max_used < used)
             ringbuf.max_used = used;
 
         ringbuf.avg_used = ((ringbuf.avg_used * ringbuf.avg_cnt) + used)
                            / ++ringbuf.avg_cnt;
-        pthread_mutex_unlock(&ringbuf.lock_stats);
+    
+        ringbuf.lock_stats.unlock();
 #endif
 
         if (ringbuf.writePtr == ringbuf.endPtr)
@@ -432,9 +423,9 @@
     bool            dev_error = false;
     bool            dev_eof = false;
 
-    pthread_mutex_lock(&ringbuf.lock);
+    ringbuf.lock.lock();
     avail = ringbuf.used;
-    pthread_mutex_unlock(&ringbuf.lock);
+    ringbuf.lock.unlock();
 
     min_read = cnt < ringbuf.min_read ? cnt : ringbuf.min_read;
 
@@ -445,11 +436,11 @@
         if (request_pause || dev_error || dev_eof)
             return 0;
 
-        pthread_mutex_lock(&ringbuf.lock);
+        QMutexLocker locker(&ringbuf.lock);
+
         dev_error = ringbuf.error;
         dev_eof = ringbuf.eof;
         avail = ringbuf.used;
-        pthread_mutex_unlock(&ringbuf.lock);
     }
     if (cnt > avail)
         cnt = avail;
@@ -475,9 +466,9 @@
         ringbuf.readPtr += cnt;
     }
 
-    pthread_mutex_lock(&ringbuf.lock);
+    ringbuf.lock.lock();
     ringbuf.used -= cnt;
-    pthread_mutex_unlock(&ringbuf.lock);
+    ringbuf.lock.unlock();
 
     if (ringbuf.readPtr == ringbuf.endPtr)
         ringbuf.readPtr = ringbuf.buffer;
@@ -488,15 +479,15 @@
 
         if (++loop == report_loops)
         {
+            QMutexLocker locker(&ringbuf.lock_stats);
+
             loop = 0;
-            pthread_mutex_lock(&ringbuf.lock_stats);
             avg = ringbuf.avg_used;
             samples = ringbuf.avg_cnt;
             max = ringbuf.max_used;
             ringbuf.avg_used = 0;
             ringbuf.avg_cnt = 0;
             ringbuf.max_used = 0;
-            pthread_mutex_unlock(&ringbuf.lock_stats);
 
             VERBOSE(VB_IMPORTANT, QString("%1 ringbuf avg %2% max %3%"
                                           " samples %4")
@@ -582,26 +573,26 @@
     // TRANSFER DATA
     while (_request_recording) 
     {
-        pthread_mutex_lock(&ringbuf.lock);
+        ringbuf.lock.lock();
         dev_error = ringbuf.error;
         dev_eof = ringbuf.eof;
         pause = ringbuf.paused;
-        pthread_mutex_unlock(&ringbuf.lock);
+        ringbuf.lock.unlock();
 
         if (request_pause)
         {
-            pthread_mutex_lock(&ringbuf.lock);
+            ringbuf.lock.lock();
             ringbuf.request_pause = true;
-            pthread_mutex_unlock(&ringbuf.lock);
+            ringbuf.lock.unlock();
 
             usleep(1000);
             continue;
         }
         else if (pause)
         {
-            pthread_mutex_lock(&ringbuf.lock);
+            ringbuf.lock.lock();
             ringbuf.request_pause = false;
-            pthread_mutex_unlock(&ringbuf.lock);
+            ringbuf.lock.unlock();
 
             usleep(1500);
             continue;
@@ -646,10 +637,10 @@
 
     _request_recording = false;
 
-    pthread_mutex_lock(&ringbuf.lock);
+    ringbuf.lock.lock();
     bool run = ringbuf.run;
     ringbuf.run = false;
-    pthread_mutex_unlock(&ringbuf.lock);
+    ringbuf.lock.unlock();
 
     if (run)
         pthread_join(ringbuf.thread, NULL);
@@ -669,17 +660,17 @@
 
 void HDTVRecorder::Pause(bool /*clear*/)
 {
-    pthread_mutex_lock(&ringbuf.lock);
+    ringbuf.lock.lock();
     ringbuf.paused = false;
-    pthread_mutex_unlock(&ringbuf.lock);
+    ringbuf.lock.unlock();
     request_pause = true;
 }
 
 bool HDTVRecorder::IsPaused(void) const
 {
-    pthread_mutex_lock(&ringbuf.lock);
+    ringbuf.lock.lock();    
     bool paused = ringbuf.paused;
-    pthread_mutex_unlock(&ringbuf.lock);
+    ringbuf.lock.unlock();
 
     return paused;
 }
@@ -900,11 +891,10 @@
         }
         else
         {
-            pthread_mutex_lock(&ringbuf.lock);
+            QMutexLocker locker(&ringbuf.lock);
             ringbuf.used = 0;
             ringbuf.max_used = 0;
             ringbuf.readPtr = ringbuf.writePtr = ringbuf.buffer;
-            pthread_mutex_unlock(&ringbuf.lock);
         }
         Unpause();
     }
Index: fifowriter.cpp
===================================================================
--- fifowriter.cpp	(revision 13379)
+++ fifowriter.cpp	(working copy)
@@ -32,14 +32,9 @@
     fb_inptr = new struct fifo_buf *[count];
     fb_outptr = new struct fifo_buf *[count];
     fifothrds = new pthread_t[count];
-    fifo_lock = new pthread_mutex_t [count];
-    empty_cond = new pthread_cond_t[count];
-    full_cond = new pthread_cond_t[count];
-    for (int i = 0; i < count; i++)
-    {
-      pthread_cond_init(&empty_cond[i], NULL);
-      pthread_cond_init(&full_cond[i], NULL);
-    }
+    fifo_lock = new QMutex[count];
+    empty_cond = new QWaitCondition[count];
+    full_cond = new QWaitCondition[count];
     filename = new QString [count];
     fbdesc = new QString [count];
 }
@@ -49,7 +44,11 @@
     for (int i = 0; i <num_fifos; i++)
     {
         killwr[i] = 1;
-        pthread_cond_signal(&empty_cond[i]);
+
+        fifo_lock[i].lock();
+        empty_cond[i].wakeOne();
+        fifo_lock[i].unlock();
+
         pthread_join(fifothrds[i], NULL);
     }
     delete [] maxblksize;
@@ -59,6 +58,7 @@
     delete [] fifothrds;
     delete [] full_cond;
     delete [] empty_cond;
+    delete [] fifo_lock;
     delete [] filename;
     delete [] fbdesc;
     delete [] killwr;
@@ -95,7 +95,6 @@
     }
     fb_inptr[id]  = fifo_buf[id];
     fb_outptr[id] = fifo_buf[id];
-    pthread_mutex_init(&fifo_lock[id], NULL);
 
     cur_id = id;
 
@@ -120,21 +119,21 @@
 {
     int id = cur_id;
     int fd = -1;
-    pthread_mutex_lock(&fifo_lock[id]);
+    fifo_lock[id].lock();
     cur_id = -1;
     while (1) 
     {
         if (fb_inptr[id] == fb_outptr[id])
-            pthread_cond_wait(&empty_cond[id],&fifo_lock[id]);
-        pthread_mutex_unlock(&fifo_lock[id]);
+            empty_cond[id].wait(&fifo_lock[id]);
+        fifo_lock[id].unlock();
         if (killwr[id])
             break;
         if (fd == -1)
             fd = open(filename[id].ascii(), O_WRONLY| O_SYNC);
         write(fd, fb_outptr[id]->data, fb_outptr[id]->blksize);
-        pthread_mutex_lock(&fifo_lock[id]);
+        fifo_lock[id].lock();
         fb_outptr[id] = fb_outptr[id]->next;
-        pthread_cond_signal(&full_cond[id]);
+        full_cond[id].wakeOne();
     }
 
     if (fd != -1)
@@ -155,7 +154,7 @@
 
 void FIFOWriter::FIFOWrite(int id, void *buffer, long blksize)
 {
-    pthread_mutex_lock(&fifo_lock[id]);
+    fifo_lock[id].lock();
     while (fb_inptr[id]->next == fb_outptr[id])
     {
         bool blocking = false;
@@ -183,12 +182,7 @@
         }
         else
         {
-            struct timespec timeout;
-            struct timeval now;
-            gettimeofday(&now, NULL);
-            timeout.tv_sec = now.tv_sec + 1;
-            timeout.tv_nsec = now.tv_usec * 1000;
-            pthread_cond_timedwait(&full_cond[id], &fifo_lock[id], &timeout);
+            full_cond[id].wait(&fifo_lock[id], 1000);
         }
     }
     if (blksize > maxblksize[id])
@@ -199,8 +193,8 @@
     memcpy(fb_inptr[id]->data,buffer,blksize);
     fb_inptr[id]->blksize = blksize;
     fb_inptr[id] = fb_inptr[id]->next;
-    pthread_cond_signal(&empty_cond[id]);
-    pthread_mutex_unlock(&fifo_lock[id]);
+    empty_cond[id].wakeOne();
+    fifo_lock[id].unlock();
 }
 
 void FIFOWriter::FIFODrain(void)
@@ -214,7 +208,9 @@
             if (fb_inptr[i] == fb_outptr[i])
             {
                 killwr[i] = 1;
-                pthread_cond_signal(&empty_cond[i]);
+                fifo_lock[i].lock();
+                empty_cond[i].wakeOne();
+                fifo_lock[i].unlock();
                 count++;
             }
         }
Index: fifowriter.h
===================================================================
--- fifowriter.h	(revision 13379)
+++ fifowriter.h	(working copy)
@@ -4,6 +4,7 @@
 #include <vector>
 #include <qstring.h>
 #include <qmutex.h>
+#include <qwaitcondition.h>
 #include <qptrqueue.h>
 
 #include "mythexp.h"
@@ -32,8 +33,8 @@
      } **fifo_buf, **fb_inptr, **fb_outptr;
 
      pthread_t *fifothrds;
-     pthread_mutex_t *fifo_lock;
-     pthread_cond_t *full_cond, *empty_cond;
+     QMutex *fifo_lock;
+     QWaitCondition *full_cond, *empty_cond;
 
      QString *filename, *fbdesc;
 
