• Home
  • Raw
  • Download

Lines Matching refs:cxt

87   TestContext *cxt = static_cast<TestContext *>(v);  in CheckSumG0G1()  local
88 ABSL_RAW_CHECK(cxt->g0 == -cxt->g1, "Error in CheckSumG0G1"); in CheckSumG0G1()
92 static void TestMu(TestContext *cxt, int c) { in TestMu() argument
93 for (int i = 0; i != cxt->iterations; i++) { in TestMu()
94 absl::MutexLock l(&cxt->mu); in TestMu()
95 int a = cxt->g0 + 1; in TestMu()
96 cxt->g0 = a; in TestMu()
97 cxt->g1--; in TestMu()
101 static void TestTry(TestContext *cxt, int c) { in TestTry() argument
102 for (int i = 0; i != cxt->iterations; i++) { in TestTry()
105 } while (!cxt->mu.TryLock()); in TestTry()
106 int a = cxt->g0 + 1; in TestTry()
107 cxt->g0 = a; in TestTry()
108 cxt->g1--; in TestTry()
109 cxt->mu.Unlock(); in TestTry()
113 static void TestR20ms(TestContext *cxt, int c) { in TestR20ms() argument
114 for (int i = 0; i != cxt->iterations; i++) { in TestR20ms()
115 absl::ReaderMutexLock l(&cxt->mu); in TestR20ms()
117 cxt->mu.AssertReaderHeld(); in TestR20ms()
121 static void TestRW(TestContext *cxt, int c) { in TestRW() argument
123 for (int i = 0; i != cxt->iterations; i++) { in TestRW()
124 absl::WriterMutexLock l(&cxt->mu); in TestRW()
125 cxt->g0++; in TestRW()
126 cxt->g1--; in TestRW()
127 cxt->mu.AssertHeld(); in TestRW()
128 cxt->mu.AssertReaderHeld(); in TestRW()
131 for (int i = 0; i != cxt->iterations; i++) { in TestRW()
132 absl::ReaderMutexLock l(&cxt->mu); in TestRW()
133 ABSL_RAW_CHECK(cxt->g0 == -cxt->g1, "Error in TestRW"); in TestRW()
134 cxt->mu.AssertReaderHeld(); in TestRW()
141 TestContext *cxt; member
146 TestContext *cxt = this->cxt; in MyTurn() local
147 return cxt->g0 == this->target || cxt->g0 == cxt->iterations; in MyTurn()
150 static void TestAwait(TestContext *cxt, int c) { in TestAwait() argument
153 mc.cxt = cxt; in TestAwait()
154 absl::MutexLock l(&cxt->mu); in TestAwait()
155 cxt->mu.AssertHeld(); in TestAwait()
156 while (cxt->g0 < cxt->iterations) { in TestAwait()
157 cxt->mu.Await(absl::Condition(&mc, &MyContext::MyTurn)); in TestAwait()
159 cxt->mu.AssertHeld(); in TestAwait()
160 if (cxt->g0 < cxt->iterations) { in TestAwait()
161 int a = cxt->g0 + 1; in TestAwait()
162 cxt->g0 = a; in TestAwait()
163 mc.target += cxt->threads; in TestAwait()
168 static void TestSignalAll(TestContext *cxt, int c) { in TestSignalAll() argument
170 absl::MutexLock l(&cxt->mu); in TestSignalAll()
171 cxt->mu.AssertHeld(); in TestSignalAll()
172 while (cxt->g0 < cxt->iterations) { in TestSignalAll()
173 while (cxt->g0 != target && cxt->g0 != cxt->iterations) { in TestSignalAll()
174 cxt->cv.Wait(&cxt->mu); in TestSignalAll()
176 if (cxt->g0 < cxt->iterations) { in TestSignalAll()
177 int a = cxt->g0 + 1; in TestSignalAll()
178 cxt->g0 = a; in TestSignalAll()
179 cxt->cv.SignalAll(); in TestSignalAll()
180 target += cxt->threads; in TestSignalAll()
185 static void TestSignal(TestContext *cxt, int c) { in TestSignal() argument
186 ABSL_RAW_CHECK(cxt->threads == 2, "TestSignal should use 2 threads"); in TestSignal()
188 absl::MutexLock l(&cxt->mu); in TestSignal()
189 cxt->mu.AssertHeld(); in TestSignal()
190 while (cxt->g0 < cxt->iterations) { in TestSignal()
191 while (cxt->g0 != target && cxt->g0 != cxt->iterations) { in TestSignal()
192 cxt->cv.Wait(&cxt->mu); in TestSignal()
194 if (cxt->g0 < cxt->iterations) { in TestSignal()
195 int a = cxt->g0 + 1; in TestSignal()
196 cxt->g0 = a; in TestSignal()
197 cxt->cv.Signal(); in TestSignal()
198 target += cxt->threads; in TestSignal()
203 static void TestCVTimeout(TestContext *cxt, int c) { in TestCVTimeout() argument
205 absl::MutexLock l(&cxt->mu); in TestCVTimeout()
206 cxt->mu.AssertHeld(); in TestCVTimeout()
207 while (cxt->g0 < cxt->iterations) { in TestCVTimeout()
208 while (cxt->g0 != target && cxt->g0 != cxt->iterations) { in TestCVTimeout()
209 cxt->cv.WaitWithTimeout(&cxt->mu, absl::Seconds(100)); in TestCVTimeout()
211 if (cxt->g0 < cxt->iterations) { in TestCVTimeout()
212 int a = cxt->g0 + 1; in TestCVTimeout()
213 cxt->g0 = a; in TestCVTimeout()
214 cxt->cv.SignalAll(); in TestCVTimeout()
215 target += cxt->threads; in TestCVTimeout()
220 static bool G0GE2(TestContext *cxt) { return cxt->g0 >= 2; } in G0GE2() argument
222 static void TestTime(TestContext *cxt, int c, bool use_cv) { in TestTime() argument
223 ABSL_RAW_CHECK(cxt->iterations == 1, "TestTime should only use 1 iteration"); in TestTime()
224 ABSL_RAW_CHECK(cxt->threads > 2, "TestTime should use more than 2 threads"); in TestTime()
227 absl::Condition g0ge2(G0GE2, cxt); in TestTime()
229 absl::MutexLock l(&cxt->mu); in TestTime()
233 cxt->cv.WaitWithTimeout(&cxt->mu, absl::Seconds(1)); in TestTime()
235 ABSL_RAW_CHECK(!cxt->mu.AwaitWithTimeout(false_cond, absl::Seconds(1)), in TestTime()
242 ABSL_RAW_CHECK(cxt->g0 == 1, "TestTime failed"); in TestTime()
246 cxt->cv.WaitWithTimeout(&cxt->mu, absl::Seconds(1)); in TestTime()
248 ABSL_RAW_CHECK(!cxt->mu.AwaitWithTimeout(false_cond, absl::Seconds(1)), in TestTime()
255 cxt->g0++; in TestTime()
257 cxt->cv.Signal(); in TestTime()
262 cxt->cv.WaitWithTimeout(&cxt->mu, absl::Seconds(4)); in TestTime()
264 ABSL_RAW_CHECK(!cxt->mu.AwaitWithTimeout(false_cond, absl::Seconds(4)), in TestTime()
271 ABSL_RAW_CHECK(cxt->g0 >= 3, "TestTime failed"); in TestTime()
275 cxt->cv.WaitWithTimeout(&cxt->mu, absl::Seconds(1)); in TestTime()
277 ABSL_RAW_CHECK(!cxt->mu.AwaitWithTimeout(false_cond, absl::Seconds(1)), in TestTime()
285 cxt->cv.SignalAll(); in TestTime()
290 cxt->cv.WaitWithTimeout(&cxt->mu, absl::Seconds(1)); in TestTime()
292 ABSL_RAW_CHECK(!cxt->mu.AwaitWithTimeout(false_cond, absl::Seconds(1)), in TestTime()
298 ABSL_RAW_CHECK(cxt->g0 == cxt->threads, "TestTime failed"); in TestTime()
301 absl::MutexLock l(&cxt->mu); in TestTime()
304 cxt->cv.WaitWithTimeout(&cxt->mu, absl::Milliseconds(500)); in TestTime()
307 !cxt->mu.AwaitWithTimeout(false_cond, absl::Milliseconds(500)), in TestTime()
314 cxt->g0++; in TestTime()
316 absl::MutexLock l(&cxt->mu); in TestTime()
318 while (cxt->g0 < 2) { in TestTime()
319 cxt->cv.WaitWithTimeout(&cxt->mu, absl::Seconds(100)); in TestTime()
322 ABSL_RAW_CHECK(cxt->mu.AwaitWithTimeout(g0ge2, absl::Seconds(100)), in TestTime()
325 cxt->g0++; in TestTime()
327 absl::MutexLock l(&cxt->mu); in TestTime()
329 while (cxt->g0 < 2) { in TestTime()
330 cxt->cv.Wait(&cxt->mu); in TestTime()
333 cxt->mu.Await(g0ge2); in TestTime()
335 cxt->g0++; in TestTime()
339 static void TestMuTime(TestContext *cxt, int c) { TestTime(cxt, c, false); } in TestMuTime() argument
341 static void TestCVTime(TestContext *cxt, int c) { TestTime(cxt, c, true); } in TestCVTime() argument
355 static int RunTestCommon(TestContext *cxt, void (*test)(TestContext *cxt, int), in RunTestCommon() argument
361 cxt->g0 = 0; in RunTestCommon()
362 cxt->g1 = 0; in RunTestCommon()
363 cxt->iterations = iterations; in RunTestCommon()
364 cxt->threads = threads; in RunTestCommon()
369 std::bind(test, cxt, std::placeholders::_1)))); in RunTestCommon()
376 return cxt->g0; in RunTestCommon()
380 static int RunTest(void (*test)(TestContext *cxt, int), int threads, in RunTest() argument
382 TestContext cxt; in RunTest() local
383 return RunTestCommon(&cxt, test, threads, iterations, operations); in RunTest()
391 static int RunTestWithInvariantDebugging(void (*test)(TestContext *cxt, int), in RunTestWithInvariantDebugging() argument
397 TestContext cxt; in RunTestWithInvariantDebugging() local
398 cxt.mu.EnableInvariantDebugging(invariant, &cxt); in RunTestWithInvariantDebugging()
399 int ret = RunTestCommon(&cxt, test, threads, iterations, operations); in RunTestWithInvariantDebugging()