19 #include "MemoryChannel.hpp"
20 #include "NdbThread.h"
30 extern "C" void* runProducer(
void*arg)
33 int count = *(
int*)arg;
39 ndbout <<
"P: " << *p << endl;
40 theMemoryChannel->writeChannel(p);
42 NdbSleep_MilliSleep(i);
48 extern "C" void* runConsumer(
void* arg)
51 int count = *(
int*)arg;
56 p = theMemoryChannel->readChannel();
57 ndbout <<
"C: " << *p << endl;
78 MemoryChannelMultipleWriter<ArgStruct>* theMemoryChannel2;
80 extern "C" void* runProducer2(
void*arg)
84 int count = pArg->items;
90 ndbout <<
"P"<<pArg->no<<
": " << i << endl;
91 theMemoryChannel2->writeChannel(p);
92 NdbSleep_MilliSleep(i);
98 extern "C" void* runConsumer2(
void* arg)
102 int count = pArg->items * pArg->no;
107 p = theMemoryChannel2->readChannel();
108 ndbout <<
"C: "<< p->no <<
", " << p->items << endl;
112 ndbout <<
"Consumer2: " << count <<
" received" << endl;
122 NDB_COMMAND(mctest,
"mctest",
"mctest",
"Test the memory channel used in Ndb", 32768)
125 ndbout <<
"==== testing MemoryChannel ====" << endl;
128 theMemoryChannel2 =
new MemoryChannelMultipleWriter<ArgStruct>;
133 NdbThread_SetConcurrencyLevel(2);
136 producerThread = NdbThread_Create(runProducer,
141 consumerThread = NdbThread_Create(runConsumer,
148 NdbThread_WaitFor(consumerThread, &status);
149 NdbThread_WaitFor(producerThread, &status);
151 ndbout <<
"==== testing MemoryChannelMultipleWriter ====" << endl;
152 #define NUM_THREADS2 5
153 NdbThread_SetConcurrencyLevel(NUM_THREADS2+2);
154 NdbThread* producerThreads[NUM_THREADS2];
157 for (
int j = 0; j < NUM_THREADS2; j++)
160 sprintf((
char*)&buf,
"producer%d", j);
162 producerThreads[j] = NdbThread_Create(runProducer2,
168 pArg =
new ArgStruct(numItems, NUM_THREADS2);
169 consumerThread = NdbThread_Create(runConsumer2,
175 NdbThread_WaitFor(consumerThread, &status);
176 for (
int j = 0; j < NUM_THREADS2; j++)
178 NdbThread_WaitFor(producerThreads[j], &status);
186 void ErrorReporter::handleError(ErrorCategory
type,
int messageID,
187 const char* problemData,
const char* objRef,
191 ndbout <<
"ErrorReporter::handleError activated" << endl;