#At file:///home/jonas/src/telco-6.3/ based on revid:jonas@stripped
3174 Jonas Oreland 2009-11-30 [merge]
merge 62 to 63
modified:
storage/ndb/src/kernel/blocks/ndbfs/AsyncFile.hpp
storage/ndb/src/kernel/blocks/ndbfs/MemoryChannel.hpp
=== modified file 'storage/ndb/src/kernel/blocks/ndbfs/AsyncFile.hpp'
--- a/storage/ndb/src/kernel/blocks/ndbfs/AsyncFile.hpp 2009-10-12 06:21:54 +0000
+++ b/storage/ndb/src/kernel/blocks/ndbfs/AsyncFile.hpp 2009-11-30 11:30:57 +0000
@@ -148,6 +148,8 @@ public:
// Information for open, needed if the first open action fails.
AsyncFile* file;
Uint32 theTrace;
+
+ MemoryChannel<Request>::ListMember m_mem_channel;
};
NdbOut& operator <<(NdbOut&, const Request&);
=== modified file 'storage/ndb/src/kernel/blocks/ndbfs/MemoryChannel.hpp'
--- a/storage/ndb/src/kernel/blocks/ndbfs/MemoryChannel.hpp 2009-05-26 18:53:34 +0000
+++ b/storage/ndb/src/kernel/blocks/ndbfs/MemoryChannel.hpp 2009-11-30 11:12:13 +0000
@@ -78,19 +78,26 @@ template <class T>
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 <class T>
NdbOut& operator<<(NdbOut& out, const MemoryChannel<T> & 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 <class T> MemoryChannel<T>::MemoryChannel( int size):
- theSize(size),
- theChannel(new T*[size] ),
- theWriteIndex(0, size),
- theReadIndex(0, size)
+template <class T> MemoryChannel<T>::MemoryChannel() :
+ m_occupancy(0), m_head(0), m_tail(0)
{
theMutexPtr = NdbMutex_Create();
theConditionPtr = NdbCondition_Create();
@@ -123,55 +126,79 @@ template <class T> MemoryChannel<T>::~Me
{
NdbMutex_Destroy(theMutexPtr);
NdbCondition_Destroy(theConditionPtr);
- delete [] theChannel;
}
template <class T> void MemoryChannel<T>::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 <class T> void MemoryChannel<T>::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 <class T> T* MemoryChannel<T>::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 <class T> T* MemoryChannel<T>::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;
Attachment: [text/bzr-bundle] bzr/jonas@mysql.com-20091130113057-vvfogdxcst814cjn.bundle
| Thread |
|---|
| • bzr commit into mysql-5.1-telco-6.3 branch (jonas:3174) | Jonas Oreland | 30 Nov |