Details
-
Improvement
-
Status: Closed
-
Major - P3
-
Resolution: Fixed
-
None
-
None
-
None
-
Fully Compatible
Description
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);
|
}
|
~
~
Attachments
Issue Links
- related to
-
SERVER-30838 Remove "_inlock" function name usage
-
- Closed
-