-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
-
Fully Compatible
WithLock is for use solely to declare a dummy argument to functions that must be called while
holding a lock, as a rigorous alternative to an unchecked naming convention and/or comments to
indicate the requirement.
It may be used to modernize code from (something like) this
// Member _mutex must be held when calling this. void _init_inlock(OperationContext* opCtx) { _stuff = makeStuff(opCtx); }
to
void _init(WithLock, OperationContext* opCtx) { _stuff = makeStuff(opCtx); }
The call to such a function looks like this:
stdx::lock_guard<stdx::mutex> lk(_mutex); _init(lk, opCtx); // instead of _init_inlock(opCtx)
Note that the formal argument need not (and should not) be named unless it is needed to pass
along to another function:
void _init(WithLock lock, OperationContext* opCtx) { _really_init(lock, opCtx); }
~
~
- related to
-
SERVER-30838 Remove "_inlock" function name usage
- Closed