[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sptk-commits
Subject:    r1620 - trunk/sptk4
From:       alexey () mail ! total-knowledge ! com
Date:       2011-09-15 3:32:26
Message-ID: courier.000000004E7171CA.00006E1E () mail ! total-knowledge ! com
[Download RAW message or body]

Author: alexey
Date: 2011-09-14 20:32:26 -0700 (Wed, 14 Sep 2011)
New Revision: 1620

Modified:
   trunk/sptk4/CFragmentedStream.h
   trunk/sptk4/CSafeQueue.h
Log:
CSafeQueue: Removed support for maximum queue items to minimize object size.

Modified: trunk/sptk4/CFragmentedStream.h
===================================================================
--- trunk/sptk4/CFragmentedStream.h	2011-09-14 23:27:14 UTC (rev 1619)
+++ trunk/sptk4/CFragmentedStream.h	2011-09-15 03:32:26 UTC (rev 1620)
@@ -52,13 +52,9 @@
     uint32_t    m_bytes;
 
 public:
-    /// @brief Constructor
-    ///
-    /// If maxQueueItems is omitted or 0, the queue is limited only with available memory.
-    /// Otherwise, when queue is full, push() will block until at least one item leaves the queue.
-    /// @param maxQueueItems uint32_t, Maximum number of items allowed in the queue
-    CSafeBufferQueue(uint32_t maxQueueItems=0) :
-        CSafeQueue<PCBuffer>(maxQueueItems),
+    /// @brief Default constructor
+    CSafeBufferQueue() :
+        CSafeQueue<PCBuffer>(),
         m_bytes(0)
     {
     }
@@ -77,7 +73,6 @@
             delete m_queue->front();
             m_queue->pop();
         }
-        m_pushSemaphore.post();
     }
 
     /// @brief This method is called when a buffer is added to the queue

Modified: trunk/sptk4/CSafeQueue.h
===================================================================
--- trunk/sptk4/CSafeQueue.h	2011-09-14 23:27:14 UTC (rev 1619)
+++ trunk/sptk4/CSafeQueue.h	2011-09-15 03:32:26 UTC (rev 1620)
@@ -47,26 +47,19 @@
 
 /// @brief Thread-safe queue
 ///
+/// Represents a queue of class T items with the ability to wait
+/// for the item arrival (if queue is empty).
 /// Can be safely shared between threads. Any operations with the queue
-/// are mutex-protected. Pop operation also allows waiting for a queue
-/// item to appear in the queue (to be added to the queue by another
-/// thread).
+/// are mutex-protected.
 template <class T>
 class CSafeQueue {
 protected:
     std::queue<T>*      m_queue;            ///< Queue of the Ts
-	CCriticalSection    m_lock;             ///< Lock to protect queue operations
+    CCriticalSection    m_lock;             ///< Lock to protect queue operations
     CSemaphore          m_popSemaphore;     ///< Semaphore to waiting for an item if queue is empty
-    CSemaphore          m_pushSemaphore;    ///< Semaphore to wait if queue is full
-    uint32_t            m_maxQueueItems;    ///< Maximum number of items allowed in the queue
 public:
     /// @brief Constructor
-    ///
-    /// If maxQueueItems is omitted or 0, the queue is limited only with available memory.
-    /// Otherwise, when queue is full, push() will block until at least one item leaves the queue.
-    /// @param maxQueueItems uint32_t, Maximum number of items allowed in the queue
-    CSafeQueue(uint32_t maxQueueItems=0) :
-        m_pushSemaphore(maxQueueItems), m_maxQueueItems(maxQueueItems)
+    CSafeQueue()
     {
         m_queue = new std::queue<T>;
     }
@@ -85,13 +78,9 @@
     /// @param item T&, a new queue item
     void push(const T& item)
     {
-        if (m_maxQueueItems)
-            m_pushSemaphore.wait();
-        {
-            CCSGuard guard(m_lock);
-            m_queue->push(item);
-            pushCalled(item);
-        }
+        CCSGuard guard(m_lock);
+        m_queue->push(item);
+        pushCalled(item);
         m_popSemaphore.post();
     }
 
@@ -120,8 +109,6 @@
                 item = m_queue->front();
                 m_queue->pop();
                 popCalled(item);
-                if (m_maxQueueItems)
-                    m_pushSemaphore.post();
                 return true;
             } catch (CTimeoutException&) {
                 m_popSemaphore.post();
@@ -151,7 +138,6 @@
         CODE_GUARD(m_lock);
         while (!m_queue->empty())
             m_queue->pop();
-        m_pushSemaphore.post();
     }
 
     /// @brief Returns true if the queue is empty

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic