30 #ifdef OVR_LOCKLESS_TEST
37 namespace OVR {
namespace LocklessTest {
40 const int TestIterations = 10000000;
54 enum { ItemCount = 20 };
61 for (
int i=0; i<ItemCount; i++)
63 Data[i] = val*100 + i;
67 int ReadAndCheckConsistency(
int prevValue)
const
71 for (
int i=1; i<ItemCount; i++)
74 if (Data[i] != (val + i))
77 if (prevValue != val / 100)
79 LogText(
"LocklessTest Fail - corruption at %d inside block %d\n",
93 volatile bool FirstItemWritten =
false;
94 LocklessUpdater<TestData> TestDataUpdater;
105 class Consumer :
public Thread
109 LogText(
"LocklessTest::Consumer::Run started.\n");
112 while (!FirstItemWritten)
125 d = TestDataUpdater.GetState();
128 newValue = d.ReadAndCheckConsistency(oldValue);
131 if (newValue < oldValue)
133 LogText(
"LocklessTest Fail - %d after %d; delta = %d\n",
134 newValue, oldValue, newValue - oldValue);
139 if (oldValue != newValue)
143 if (oldValue % (TestIterations/30) == 0)
145 LogText(
"LocklessTest::Consumer - %5.2f%% done\n",
146 100.0f * (
float)oldValue/(
float)TestIterations);
151 for (
int j = 0; j< 300; j++)
157 }
while (oldValue < (TestIterations * 99 / 100));
159 LogText(
"LocklessTest::Consumer::Run exiting.\n");
168 class Producer :
public Thread
173 LogText(
"LocklessTest::Producer::Run started.\n");
175 for (
int testVal = 0; testVal < TestIterations; testVal++)
182 TestDataUpdater.SetState(d);
185 FirstItemWritten =
true;
188 for(
int j = 0; j < 1000; j++)
193 if (testVal % (TestIterations/30) == 0)
195 LogText(
"LocklessTest::Producer - %5.2f%% done\n",
196 100.0f * (
float)testVal/(
float)TestIterations);
200 LogText(
"LocklessTest::Producer::Run exiting.\n");
210 void StartLocklessTest()
213 Ptr<LocklessTest::Producer> producerThread = *
new LocklessTest::Producer;
214 Ptr<LocklessTest::Consumer> consumerThread = *
new LocklessTest::Consumer;
216 producerThread->Start();
217 consumerThread->Start();
231 #endif // OVR_LOCKLESS_TEST
void LogText(const char *fmt,...) OVR_LOG_VAARG_ATTRIBUTE(1