=== modified file 'storage/ndb/src/kernel/blocks/ndbfs/AsyncFile.hpp' --- storage/ndb/src/kernel/blocks/ndbfs/AsyncFile.hpp 2009-10-12 06:21:54 +0000 +++ storage/ndb/src/kernel/blocks/ndbfs/AsyncFile.hpp 2009-11-30 08:42:36 +0000 @@ -148,6 +148,8 @@ public: // Information for open, needed if the first open action fails. AsyncFile* file; Uint32 theTrace; + + MemoryChannel::ListMember m_mem_channel; }; NdbOut& operator <<(NdbOut&, const Request&); === modified file 'storage/ndb/src/kernel/blocks/ndbfs/MemoryChannel.hpp' --- storage/ndb/src/kernel/blocks/ndbfs/MemoryChannel.hpp 2009-05-26 18:53:34 +0000 +++ storage/ndb/src/kernel/blocks/ndbfs/MemoryChannel.hpp 2009-11-30 09:03:48 +0000 @@ -78,19 +78,26 @@ template class MemoryChannel { public: - MemoryChannel( int size= 512); - virtual ~MemoryChannel( ); + MemoryChannel(); + virtual ~MemoryChannel(); - void writeChannel( T *t); - void writeChannelNoSignal( T *t); + void writeChannel(T *t); + void writeChannelNoSignal(T *t); T* readChannel(); T* tryReadChannel(); + /** + * Should be made class using MemoryChannel + */ + struct ListMember + { + T* m_next; + }; + private: - int theSize; - T **theChannel; - CircularIndex theWriteIndex; - CircularIndex theReadIndex; + Uint32 m_occupancy; + T* m_head; // First element in list (e.g will be read by readChannel) + T* m_tail; NdbMutex* theMutexPtr; NdbCondition* theConditionPtr; @@ -102,18 +109,14 @@ template NdbOut& operator<<(NdbOut& out, const MemoryChannel & chn) { NdbMutex_Lock(chn.theMutexPtr); - out << "[ theSize: " << chn.theSize - << " theReadIndex: " << (int)chn.theReadIndex - << " theWriteIndex: " << (int)chn.theWriteIndex << " ]"; + out << "[ occupancy: " << chn.m_occupancy + << " ]"; NdbMutex_Unlock(chn.theMutexPtr); return out; } -template MemoryChannel::MemoryChannel( int size): - theSize(size), - theChannel(new T*[size] ), - theWriteIndex(0, size), - theReadIndex(0, size) +template MemoryChannel::MemoryChannel() : + m_occupancy(0), m_head(0), m_tail(0) { theMutexPtr = NdbMutex_Create(); theConditionPtr = NdbCondition_Create(); @@ -123,55 +126,79 @@ template MemoryChannel::~Me { NdbMutex_Destroy(theMutexPtr); NdbCondition_Destroy(theConditionPtr); - delete [] theChannel; } template void MemoryChannel::writeChannel( T *t) { - - NdbMutex_Lock(theMutexPtr); - if(full(theWriteIndex, theReadIndex) || theChannel == NULL) abort(); - theChannel[theWriteIndex]= t; - ++theWriteIndex; - NdbMutex_Unlock(theMutexPtr); + writeChannelNoSignal(t); NdbCondition_Signal(theConditionPtr); } template void MemoryChannel::writeChannelNoSignal( T *t) { - NdbMutex_Lock(theMutexPtr); - if(full(theWriteIndex, theReadIndex) || theChannel == NULL) abort(); - theChannel[theWriteIndex]= t; - ++theWriteIndex; + if (m_head == 0) + { + assert(m_occupancy == 0); + m_head = m_tail = t; + } + else + { + assert(m_tail != 0); + m_tail->m_mem_channel.m_next = t; + m_tail = t; + } + t->m_mem_channel.m_next = 0; + m_occupancy++; NdbMutex_Unlock(theMutexPtr); } template T* MemoryChannel::readChannel() { - T* tmp; - NdbMutex_Lock(theMutexPtr); - while ( empty(theWriteIndex, theReadIndex) ) + while (m_head == 0) { + assert(m_occupancy == 0); NdbCondition_Wait(theConditionPtr, - theMutexPtr); + theMutexPtr); } - - tmp= theChannel[theReadIndex]; - ++theReadIndex; + assert(m_occupancy > 0); + T* tmp = m_head; + if (m_head == m_tail) + { + assert(m_occupancy == 1); + m_head = m_tail = 0; + } + else + { + m_head = m_head->m_mem_channel.m_next; + } + m_occupancy--; NdbMutex_Unlock(theMutexPtr); return tmp; } template T* MemoryChannel::tryReadChannel() { - T* tmp= 0; NdbMutex_Lock(theMutexPtr); - if ( !empty(theWriteIndex, theReadIndex) ) - { - tmp= theChannel[theReadIndex]; - ++theReadIndex; + T* tmp = m_head; + if (m_head != 0) + { + assert(m_occupancy > 0); + if (m_head == m_tail) + { + assert(m_occupancy == 1); + m_head = m_tail = 0; + } + else + { + m_head = m_head->m_mem_channel.m_next; + } + m_occupancy--; + } + else + { + assert(m_occupancy == 0); } NdbMutex_Unlock(theMutexPtr); return tmp;