Clone
ixen <ixen@copyhandler.com>
committed
on 19 Nov 16
Reader/writer cleanups (CH-307)
ParallelizeReaderWriter + 3 more
src/libchcore/TBufferList.cpp (+4 -4)
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 25         TBufferList::TBufferList() :
26 26                 m_eventAllBuffersAccountedFor(true, true)
27 27         {
28 28         }
29 29
30 30         void TBufferList::Push(TOverlappedDataBuffer* pBuffer)
31 31         {
32 32                 if(!pBuffer)
33 33                         throw TCoreException(eErr_InvalidArgument, L"pBuffer", LOCATION);
34 34
35 35                 m_listBuffers.push_front(pBuffer);
36 36                 UpdateEvent();
37                   m_notifier(true);
  37                 m_notifier();
38 38         }
39 39
40 40         TOverlappedDataBuffer* TBufferList::Pop()
41 41         {
42 42                 if(m_listBuffers.empty())
43 43                         return nullptr;
44 44
45 45                 TOverlappedDataBuffer* pBuffer = m_listBuffers.front();
46 46                 m_listBuffers.pop_front();
47 47
48 48                 UpdateEvent();
49 49
50                   m_notifier(false);
  50                 m_notifier();
51 51
52 52                 return pBuffer;
53 53         }
54 54
55 55         void TBufferList::Clear()
56 56         {
57 57                 bool bRemoved = !m_listBuffers.empty();
58 58                 m_listBuffers.clear();
59 59
60 60                 if (bRemoved)
61 61                 {
62 62                         UpdateEvent();
63                           m_notifier(false);
  63                         m_notifier();
64 64                 }
65 65         }
66 66
67 67         size_t TBufferList::GetCount() const
68 68         {
69 69                 return m_listBuffers.size();
70 70         }
71 71
72 72         bool TBufferList::IsEmpty() const
73 73         {
74 74                 return m_listBuffers.empty();
75 75         }
76 76
77 77         void TBufferList::SetExpectedBuffersCount(size_t stExpectedBuffers)
78 78         {
79 79                 m_stExpectedBuffers = stExpectedBuffers;
80 80                 UpdateEvent();
81 81         }
82 82
83 83         HANDLE TBufferList::GetAllBuffersAccountedForEvent() const
84 84         {
85 85                 return m_eventAllBuffersAccountedFor.Handle();
86 86         }
87 87
88           boost::signals2::signal<void(bool bAdded)>& TBufferList::GetNotifier()
  88         boost::signals2::signal<void()>& TBufferList::GetNotifier()
89 89         {
90 90                 return m_notifier;
91 91         }
92 92
93 93         void TBufferList::UpdateEvent()
94 94         {
95 95                 m_eventAllBuffersAccountedFor.SetEvent(m_listBuffers.size() == m_stExpectedBuffers);
96 96         }
97 97 }