Clone
ixen <ixen@copyhandler.com>
committed
on 27 Oct 16
Rewritten all-buffers-accounted-for handling (simplified; removed dependency on ReaderWriter object) (CH-270).
ParallelizeReaderWriter + 4 more
src/libchcore/TBufferList.cpp (+13 -1)
5 5 //  This program is free software; you can redistribute it and/or modify
6 6 //  it under the terms of the GNU Library General Public License
7 7 //  (version 2) as published by the Free Software Foundation;
8 8 //
9 9 //  This program is distributed in the hope that it will be useful,
10 10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 12 //  GNU General Public License for more details.
13 13 //
14 14 //  You should have received a copy of the GNU Library General Public
15 15 //  License along with this program; if not, write to the
16 16 //  Free Software Foundation, Inc.,
17 17 //  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 18 // ============================================================================
19 19 #include "stdafx.h"
20 20 #include "TBufferList.h"
21 21 #include "TCoreException.h"
22 22
23 23 namespace chcore
24 24 {
25           TBufferList::TBufferList()
  25         TBufferList::TBufferList() :
  26                 m_eventAllBuffersAccountedFor(true, true)
26 27         {
27 28         }
28 29
29 30         void TBufferList::Push(TOverlappedDataBuffer* pBuffer)
30 31         {
31 32                 if(!pBuffer)
32 33                         throw TCoreException(eErr_InvalidArgument, L"pBuffer", LOCATION);
33 34
34 35                 m_listBuffers.push_front(pBuffer);
  36                 UpdateEvent();
35 37                 m_notifier(true);
36 38         }
37 39
38 40         TOverlappedDataBuffer* TBufferList::Pop()
39 41         {
40 42                 if(m_listBuffers.empty())
41 43                         return nullptr;
42 44
43 45                 TOverlappedDataBuffer* pBuffer = m_listBuffers.front();
44 46                 m_listBuffers.pop_front();
45 47
  48                 UpdateEvent();
  49
46 50                 m_notifier(false);
47 51
48 52                 return pBuffer;
49 53         }
50 54
51 55         void TBufferList::Clear()
52 56         {
53 57                 bool bRemoved = !m_listBuffers.empty();
54 58                 m_listBuffers.clear();
55 59
56 60                 if (bRemoved)
  61                 {
  62                         UpdateEvent();
57 63                         m_notifier(false);
58 64                 }
  65         }
59 66
60 67         size_t TBufferList::GetCount() const
61 68         {
62 69                 return m_listBuffers.size();
63 70         }
64 71
65 72         bool TBufferList::IsEmpty() const
66 73         {
67 74                 return m_listBuffers.empty();
68 75         }
69 76
70 77         boost::signals2::signal<void(bool bAdded)>& TBufferList::GetNotifier()
71 78         {
72 79                 return m_notifier;
73 80         }
  81
  82         void TBufferList::UpdateEvent()
  83         {
  84                 m_eventAllBuffersAccountedFor.SetEvent(m_listBuffers.size() == m_stExpectedBuffers);
74 85         }
  86 }