18 #ifndef MemoryChannel_H
19 #define MemoryChannel_H
70 #include "NdbCondition.h"
81 void writeChannel(T *t);
82 void writeChannelNoSignal(T *t);
98 NdbMutex* theMutexPtr;
102 friend NdbOut& operator<<(NdbOut& out, const MemoryChannel<U> & chn);
106 NdbOut& operator<<(NdbOut& out, const MemoryChannel<T> & chn)
108 NdbMutex_Lock(chn.theMutexPtr);
109 out <<
"[ occupancy: " << chn.m_occupancy
111 NdbMutex_Unlock(chn.theMutexPtr);
116 m_occupancy(0), m_head(0), m_tail(0)
118 theMutexPtr = NdbMutex_Create();
119 theConditionPtr = NdbCondition_Create();
124 NdbMutex_Destroy(theMutexPtr);
125 NdbCondition_Destroy(theConditionPtr);
130 writeChannelNoSignal(t);
131 NdbCondition_Signal(theConditionPtr);
136 NdbMutex_Lock(theMutexPtr);
139 assert(m_occupancy == 0);
145 m_tail->m_mem_channel.m_next = t;
148 t->m_mem_channel.m_next = 0;
150 NdbMutex_Unlock(theMutexPtr);
155 NdbMutex_Lock(theMutexPtr);
158 assert(m_occupancy == 0);
159 NdbCondition_Wait(theConditionPtr,
162 assert(m_occupancy > 0);
164 if (m_head == m_tail)
166 assert(m_occupancy == 1);
171 m_head = m_head->m_mem_channel.m_next;
174 NdbMutex_Unlock(theMutexPtr);
180 NdbMutex_Lock(theMutexPtr);
184 assert(m_occupancy > 0);
185 if (m_head == m_tail)
187 assert(m_occupancy == 1);
192 m_head = m_head->m_mem_channel.m_next;
198 assert(m_occupancy == 0);
200 NdbMutex_Unlock(theMutexPtr);
204 #endif // MemoryChannel_H