@@ -136,7 +136,7 @@ class Mutex {
136
136
// /
137
137
// / Precondition: Mutex not held by this thread, undefined otherwise.
138
138
template <typename CriticalSection>
139
- void lock (CriticalSection criticalSection) {
139
+ void withLock (CriticalSection criticalSection) {
140
140
lock ();
141
141
criticalSection ();
142
142
unlock ();
@@ -155,7 +155,7 @@ class Mutex {
155
155
// / ...all while being correctly protected by mutex.
156
156
// /
157
157
// / ```
158
- // / mutex.lockOrWait (condition, [&value] {
158
+ // / mutex.withLockOrWait (condition, [&value] {
159
159
// / if (value > 0) {
160
160
// / value--;
161
161
// / return true;
@@ -166,9 +166,9 @@ class Mutex {
166
166
// /
167
167
// / Precondition: Mutex not held by this thread, undefined otherwise.
168
168
template <typename CriticalSection>
169
- void lockOrWait (ConditionVariable &condition,
170
- CriticalSection criticalSection) {
171
- lock ([&] {
169
+ void withLockOrWait (ConditionVariable &condition,
170
+ CriticalSection criticalSection) {
171
+ withLock ([&] {
172
172
while (!criticalSection ()) {
173
173
wait (condition);
174
174
}
@@ -185,14 +185,14 @@ class Mutex {
185
185
// / then notifies one condition waiter about this change.
186
186
// /
187
187
// / ```
188
- // / mutex.lockAndNotifyOne( [&value] { value++; });
188
+ // / mutex.withLockThenNotifyOne(condition, [&value] { value++; });
189
189
// / ```
190
190
// /
191
191
// / Precondition: Mutex not held by this thread, undefined otherwise.
192
192
template <typename CriticalSection>
193
- void lockAndNotifyOne (ConditionVariable &condition,
194
- CriticalSection criticalSection) {
195
- lock ([&] {
193
+ void withLockThenNotifyOne (ConditionVariable &condition,
194
+ CriticalSection criticalSection) {
195
+ withLock ([&] {
196
196
criticalSection ();
197
197
condition.notifyOne ();
198
198
});
@@ -208,14 +208,14 @@ class Mutex {
208
208
// / then notifies all condition waiters about this change.
209
209
// /
210
210
// / ```
211
- // / mutex.lockAndNotifyAll( [&value] { value++; });
211
+ // / mutex.withLockThenNotifyAll(condition, [&value] { value++; });
212
212
// / ```
213
213
// /
214
214
// / Precondition: Mutex not held by this thread, undefined otherwise.
215
215
template <typename CriticalSection>
216
- void lockAndNotifyAll (ConditionVariable &condition,
217
- CriticalSection criticalSection) {
218
- lock ([&] {
216
+ void withLockThenNotifyAll (ConditionVariable &condition,
217
+ CriticalSection criticalSection) {
218
+ withLock ([&] {
219
219
criticalSection ();
220
220
condition.notifyAll ();
221
221
});
@@ -343,12 +343,12 @@ class ReadWriteLock {
343
343
// / the read lock.
344
344
// /
345
345
// / ```
346
- // / rw.readLock ([&value] { value = cachedValue; });
346
+ // / rw.withReadLock ([&value] { value = cachedValue; });
347
347
// / ```
348
348
// /
349
349
// / Precondition: ReadWriteLock not held by this thread, undefined otherwise.
350
350
template <typename CriticalSection>
351
- void readLock (CriticalSection criticalSection) {
351
+ void withReadLock (CriticalSection criticalSection) {
352
352
readLock ();
353
353
criticalSection ();
354
354
readUnlock ();
@@ -363,61 +363,17 @@ class ReadWriteLock {
363
363
// / the write lock.
364
364
// /
365
365
// / ```
366
- // / rw.writeLock ([&newValue] { cachedValue = newValue });
366
+ // / rw.withWriteLock ([&newValue] { cachedValue = newValue });
367
367
// / ```
368
368
// /
369
369
// / Precondition: ReadWriteLock not held by this thread, undefined otherwise.
370
370
template <typename CriticalSection>
371
- void writeLock (CriticalSection criticalSection) {
371
+ void withWriteLock (CriticalSection criticalSection) {
372
372
writeLock ();
373
373
criticalSection ();
374
374
writeUnlock ();
375
375
}
376
376
377
- // / Acquires read lock before calling the read critical section and if
378
- // / the critical section returns `true` (done) readWriteLock returns to the
379
- // / caller. If the read critical section returns `false` the read lock
380
- // / will be dropped, the write lock will be acquired and then the read
381
- // / critical section will be called again. Then if the critical section
382
- // / returns `true` (done) readWriteLock returns to the caller. If the read
383
- // / critical section returns `false` then the write critical section will
384
- // / be called (with write lock still held).
385
- // /
386
- // / Note in all situations on return to caller the ReadWriteLock will
387
- // / not be held.
388
- // /
389
- // / For example the following attempts to get a cachedValue if it exists
390
- // / if not found it will create the needed cachedValue.
391
- // /
392
- // / ```
393
- // / rw.readWriteLock(
394
- // / [&value] {
395
- // / if (cachedValue) {
396
- // / value = cachedValue;
397
- // / return true;
398
- // / }
399
- // / return false;
400
- // / },
401
- // / [&value] {
402
- // / cachedValue = createValue();
403
- // / value = cachedValue;
404
- // / });
405
- // / ```
406
- // /
407
- // / Precondition: ReadWriteLock not held by this thread, undefined otherwise.
408
- template <typename ReadonlySection, typename WriteSection>
409
- void readWriteLock (ReadonlySection readSection, WriteSection writeSection) {
410
- bool done;
411
- readLock ([&done, &readSection] { done = readSection (); });
412
- if (!done) {
413
- writeLock ([&readSection, &writeSection] {
414
- if (!readSection ()) {
415
- writeSection ();
416
- }
417
- });
418
- }
419
- }
420
-
421
377
private:
422
378
ReadWriteLockHandle Handle;
423
379
};
@@ -485,38 +441,38 @@ class StaticMutex {
485
441
486
442
// / See Mutex::lock
487
443
template <typename CriticalSection>
488
- void lock (CriticalSection criticalSection) {
444
+ void withLock (CriticalSection criticalSection) {
489
445
lock ();
490
446
criticalSection ();
491
447
unlock ();
492
448
}
493
449
494
- // / See Mutex::lockOrWait
450
+ // / See Mutex::withLockOrWait
495
451
template <typename CriticalSection>
496
- void lockOrWait (StaticConditionVariable &condition,
497
- CriticalSection criticalSection) {
498
- lock ([&] {
452
+ void withLockOrWait (StaticConditionVariable &condition,
453
+ CriticalSection criticalSection) {
454
+ withLock ([&] {
499
455
while (!criticalSection ()) {
500
456
wait (condition);
501
457
}
502
458
});
503
459
}
504
460
505
- // / See Mutex::lockAndNotifyOne
461
+ // / See Mutex::withLockThenNotifyOne
506
462
template <typename CriticalSection>
507
- void lockAndNotifyOne (StaticConditionVariable &condition,
508
- CriticalSection criticalSection) {
509
- lock ([&] {
463
+ void withLockThenNotifyOne (StaticConditionVariable &condition,
464
+ CriticalSection criticalSection) {
465
+ withLock ([&] {
510
466
criticalSection ();
511
467
condition.notifyOne ();
512
468
});
513
469
}
514
470
515
- // / See Mutex::lockAndNotifyAll
471
+ // / See Mutex::withLockThenNotifyAll
516
472
template <typename CriticalSection>
517
- void lockAndNotifyAll (StaticConditionVariable &condition,
518
- CriticalSection criticalSection) {
519
- lock ([&] {
473
+ void withLockThenNotifyAll (StaticConditionVariable &condition,
474
+ CriticalSection criticalSection) {
475
+ withLock ([&] {
520
476
criticalSection ();
521
477
condition.notifyAll ();
522
478
});
@@ -566,36 +522,22 @@ class StaticReadWriteLock {
566
522
// / See ReadWriteLock::writeUnlock
567
523
void writeUnlock () { ReadWriteLockPlatformHelper::writeUnlock (Handle); }
568
524
569
- // / See ReadWriteLock::readLock
525
+ // / See ReadWriteLock::withReadLock
570
526
template <typename CriticalSection>
571
- void readLock (CriticalSection criticalSection) {
527
+ void withReadLock (CriticalSection criticalSection) {
572
528
readLock ();
573
529
criticalSection ();
574
530
readUnlock ();
575
531
}
576
532
577
- // / See ReadWriteLock::writeLock
533
+ // / See ReadWriteLock::withWriteLock
578
534
template <typename CriticalSection>
579
- void writeLock (CriticalSection criticalSection) {
535
+ void withWriteLock (CriticalSection criticalSection) {
580
536
writeLock ();
581
537
criticalSection ();
582
538
writeUnlock ();
583
539
}
584
540
585
- // / See ReadWriteLock::readWriteLock
586
- template <typename ReadonlySection, typename WriteSection>
587
- void readWriteLock (ReadonlySection readSection, WriteSection writeSection) {
588
- bool done;
589
- readLock ([&done, &readSection] { done = readSection (); });
590
- if (!done) {
591
- writeLock ([&readSection, &writeSection] {
592
- if (!readSection ()) {
593
- writeSection ();
594
- }
595
- });
596
- }
597
- }
598
-
599
541
private:
600
542
ReadWriteLockHandle Handle;
601
543
};
0 commit comments