• Home
  • Raw
  • Download

Lines Matching refs:cxt

89   TestContext *cxt = static_cast<TestContext *>(v);  in CheckSumG0G1()  local
90 ABSL_RAW_CHECK(cxt->g0 == -cxt->g1, "Error in CheckSumG0G1"); in CheckSumG0G1()
94 static void TestMu(TestContext *cxt, int c) { in TestMu() argument
95 for (int i = 0; i != cxt->iterations; i++) { in TestMu()
96 absl::MutexLock l(&cxt->mu); in TestMu()
97 int a = cxt->g0 + 1; in TestMu()
98 cxt->g0 = a; in TestMu()
99 cxt->g1--; in TestMu()
103 static void TestTry(TestContext *cxt, int c) { in TestTry() argument
104 for (int i = 0; i != cxt->iterations; i++) { in TestTry()
107 } while (!cxt->mu.TryLock()); in TestTry()
108 int a = cxt->g0 + 1; in TestTry()
109 cxt->g0 = a; in TestTry()
110 cxt->g1--; in TestTry()
111 cxt->mu.Unlock(); in TestTry()
115 static void TestR20ms(TestContext *cxt, int c) { in TestR20ms() argument
116 for (int i = 0; i != cxt->iterations; i++) { in TestR20ms()
117 absl::ReaderMutexLock l(&cxt->mu); in TestR20ms()
119 cxt->mu.AssertReaderHeld(); in TestR20ms()
123 static void TestRW(TestContext *cxt, int c) { in TestRW() argument
125 for (int i = 0; i != cxt->iterations; i++) { in TestRW()
126 absl::WriterMutexLock l(&cxt->mu); in TestRW()
127 cxt->g0++; in TestRW()
128 cxt->g1--; in TestRW()
129 cxt->mu.AssertHeld(); in TestRW()
130 cxt->mu.AssertReaderHeld(); in TestRW()
133 for (int i = 0; i != cxt->iterations; i++) { in TestRW()
134 absl::ReaderMutexLock l(&cxt->mu); in TestRW()
135 ABSL_RAW_CHECK(cxt->g0 == -cxt->g1, "Error in TestRW"); in TestRW()
136 cxt->mu.AssertReaderHeld(); in TestRW()
143 TestContext *cxt; member
148 TestContext *cxt = this->cxt; in MyTurn() local
149 return cxt->g0 == this->target || cxt->g0 == cxt->iterations; in MyTurn()
152 static void TestAwait(TestContext *cxt, int c) { in TestAwait() argument
155 mc.cxt = cxt; in TestAwait()
156 absl::MutexLock l(&cxt->mu); in TestAwait()
157 cxt->mu.AssertHeld(); in TestAwait()
158 while (cxt->g0 < cxt->iterations) { in TestAwait()
159 cxt->mu.Await(absl::Condition(&mc, &MyContext::MyTurn)); in TestAwait()
161 cxt->mu.AssertHeld(); in TestAwait()
162 if (cxt->g0 < cxt->iterations) { in TestAwait()
163 int a = cxt->g0 + 1; in TestAwait()
164 cxt->g0 = a; in TestAwait()
165 mc.target += cxt->threads; in TestAwait()
170 static void TestSignalAll(TestContext *cxt, int c) { in TestSignalAll() argument
172 absl::MutexLock l(&cxt->mu); in TestSignalAll()
173 cxt->mu.AssertHeld(); in TestSignalAll()
174 while (cxt->g0 < cxt->iterations) { in TestSignalAll()
175 while (cxt->g0 != target && cxt->g0 != cxt->iterations) { in TestSignalAll()
176 cxt->cv.Wait(&cxt->mu); in TestSignalAll()
178 if (cxt->g0 < cxt->iterations) { in TestSignalAll()
179 int a = cxt->g0 + 1; in TestSignalAll()
180 cxt->g0 = a; in TestSignalAll()
181 cxt->cv.SignalAll(); in TestSignalAll()
182 target += cxt->threads; in TestSignalAll()
187 static void TestSignal(TestContext *cxt, int c) { in TestSignal() argument
188 ABSL_RAW_CHECK(cxt->threads == 2, "TestSignal should use 2 threads"); in TestSignal()
190 absl::MutexLock l(&cxt->mu); in TestSignal()
191 cxt->mu.AssertHeld(); in TestSignal()
192 while (cxt->g0 < cxt->iterations) { in TestSignal()
193 while (cxt->g0 != target && cxt->g0 != cxt->iterations) { in TestSignal()
194 cxt->cv.Wait(&cxt->mu); in TestSignal()
196 if (cxt->g0 < cxt->iterations) { in TestSignal()
197 int a = cxt->g0 + 1; in TestSignal()
198 cxt->g0 = a; in TestSignal()
199 cxt->cv.Signal(); in TestSignal()
200 target += cxt->threads; in TestSignal()
205 static void TestCVTimeout(TestContext *cxt, int c) { in TestCVTimeout() argument
207 absl::MutexLock l(&cxt->mu); in TestCVTimeout()
208 cxt->mu.AssertHeld(); in TestCVTimeout()
209 while (cxt->g0 < cxt->iterations) { in TestCVTimeout()
210 while (cxt->g0 != target && cxt->g0 != cxt->iterations) { in TestCVTimeout()
211 cxt->cv.WaitWithTimeout(&cxt->mu, absl::Seconds(100)); in TestCVTimeout()
213 if (cxt->g0 < cxt->iterations) { in TestCVTimeout()
214 int a = cxt->g0 + 1; in TestCVTimeout()
215 cxt->g0 = a; in TestCVTimeout()
216 cxt->cv.SignalAll(); in TestCVTimeout()
217 target += cxt->threads; in TestCVTimeout()
222 static bool G0GE2(TestContext *cxt) { return cxt->g0 >= 2; } in G0GE2() argument
224 static void TestTime(TestContext *cxt, int c, bool use_cv) { in TestTime() argument
225 ABSL_RAW_CHECK(cxt->iterations == 1, "TestTime should only use 1 iteration"); in TestTime()
226 ABSL_RAW_CHECK(cxt->threads > 2, "TestTime should use more than 2 threads"); in TestTime()
229 absl::Condition g0ge2(G0GE2, cxt); in TestTime()
231 absl::MutexLock l(&cxt->mu); in TestTime()
235 cxt->cv.WaitWithTimeout(&cxt->mu, absl::Seconds(1)); in TestTime()
237 ABSL_RAW_CHECK(!cxt->mu.AwaitWithTimeout(false_cond, absl::Seconds(1)), in TestTime()
244 ABSL_RAW_CHECK(cxt->g0 == 1, "TestTime failed"); in TestTime()
248 cxt->cv.WaitWithTimeout(&cxt->mu, absl::Seconds(1)); in TestTime()
250 ABSL_RAW_CHECK(!cxt->mu.AwaitWithTimeout(false_cond, absl::Seconds(1)), in TestTime()
257 cxt->g0++; in TestTime()
259 cxt->cv.Signal(); in TestTime()
264 cxt->cv.WaitWithTimeout(&cxt->mu, absl::Seconds(4)); in TestTime()
266 ABSL_RAW_CHECK(!cxt->mu.AwaitWithTimeout(false_cond, absl::Seconds(4)), in TestTime()
273 ABSL_RAW_CHECK(cxt->g0 >= 3, "TestTime failed"); in TestTime()
277 cxt->cv.WaitWithTimeout(&cxt->mu, absl::Seconds(1)); in TestTime()
279 ABSL_RAW_CHECK(!cxt->mu.AwaitWithTimeout(false_cond, absl::Seconds(1)), in TestTime()
287 cxt->cv.SignalAll(); in TestTime()
292 cxt->cv.WaitWithTimeout(&cxt->mu, absl::Seconds(1)); in TestTime()
294 ABSL_RAW_CHECK(!cxt->mu.AwaitWithTimeout(false_cond, absl::Seconds(1)), in TestTime()
300 ABSL_RAW_CHECK(cxt->g0 == cxt->threads, "TestTime failed"); in TestTime()
303 absl::MutexLock l(&cxt->mu); in TestTime()
306 cxt->cv.WaitWithTimeout(&cxt->mu, absl::Milliseconds(500)); in TestTime()
309 !cxt->mu.AwaitWithTimeout(false_cond, absl::Milliseconds(500)), in TestTime()
316 cxt->g0++; in TestTime()
318 absl::MutexLock l(&cxt->mu); in TestTime()
320 while (cxt->g0 < 2) { in TestTime()
321 cxt->cv.WaitWithTimeout(&cxt->mu, absl::Seconds(100)); in TestTime()
324 ABSL_RAW_CHECK(cxt->mu.AwaitWithTimeout(g0ge2, absl::Seconds(100)), in TestTime()
327 cxt->g0++; in TestTime()
329 absl::MutexLock l(&cxt->mu); in TestTime()
331 while (cxt->g0 < 2) { in TestTime()
332 cxt->cv.Wait(&cxt->mu); in TestTime()
335 cxt->mu.Await(g0ge2); in TestTime()
337 cxt->g0++; in TestTime()
341 static void TestMuTime(TestContext *cxt, int c) { TestTime(cxt, c, false); } in TestMuTime() argument
343 static void TestCVTime(TestContext *cxt, int c) { TestTime(cxt, c, true); } in TestCVTime() argument
357 static int RunTestCommon(TestContext *cxt, void (*test)(TestContext *cxt, int), in RunTestCommon() argument
363 cxt->g0 = 0; in RunTestCommon()
364 cxt->g1 = 0; in RunTestCommon()
365 cxt->iterations = iterations; in RunTestCommon()
366 cxt->threads = threads; in RunTestCommon()
371 std::bind(test, cxt, std::placeholders::_1)))); in RunTestCommon()
378 return cxt->g0; in RunTestCommon()
382 static int RunTest(void (*test)(TestContext *cxt, int), int threads, in RunTest() argument
384 TestContext cxt; in RunTest() local
385 return RunTestCommon(&cxt, test, threads, iterations, operations); in RunTest()
393 static int RunTestWithInvariantDebugging(void (*test)(TestContext *cxt, int), in RunTestWithInvariantDebugging() argument
399 TestContext cxt; in RunTestWithInvariantDebugging() local
400 cxt.mu.EnableInvariantDebugging(invariant, &cxt); in RunTestWithInvariantDebugging()
401 int ret = RunTestCommon(&cxt, test, threads, iterations, operations); in RunTestWithInvariantDebugging()