2
Copyright (C) 2003, 2005, 2006 MySQL AB
3
All rights reserved. Use is subject to license terms.
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
#include "MemoryChannel.hpp"
20
#include "NdbThread.h"
27
MemoryChannel<int>* theMemoryChannel;
30
extern "C" void* runProducer(void*arg)
32
// The producer will items into the MemoryChannel
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)
50
// The producer will read items from MemoryChannel and print on screen
51
int count = *(int*)arg;
56
p = theMemoryChannel->readChannel();
57
ndbout << "C: " << *p << endl;
70
ArgStruct(int _items, int _no){
78
MemoryChannelMultipleWriter<ArgStruct>* theMemoryChannel2;
80
extern "C" void* runProducer2(void*arg)
82
// The producer will items into the MemoryChannel
83
ArgStruct* pArg = (ArgStruct*)arg;
84
int count = pArg->items;
89
p = new ArgStruct(i, pArg->no);
90
ndbout << "P"<<pArg->no<<": " << i << endl;
91
theMemoryChannel2->writeChannel(p);
92
NdbSleep_MilliSleep(i);
98
extern "C" void* runConsumer2(void* arg)
100
// The producer will read items from MemoryChannel and print on screen
101
ArgStruct* pArg = (ArgStruct*)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;
119
//#if defined MEMORYCHANNELTEST
121
//int main(int argc, char **argv)
122
NDB_COMMAND(mctest, "mctest", "mctest", "Test the memory channel used in Ndb", 32768)
125
ndbout << "==== testing MemoryChannel ====" << endl;
127
theMemoryChannel = new MemoryChannel<int>;
128
theMemoryChannel2 = new MemoryChannelMultipleWriter<ArgStruct>;
130
NdbThread* consumerThread;
131
NdbThread* producerThread;
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);
161
pArg = new ArgStruct(numItems, 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;