[SERVER-30748] Alternative to '_inlock' function naming Created: 18/Aug/17  Updated: 30/Oct/23  Resolved: 30/Aug/17

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 3.5.13

Type: Improvement Priority: Major - P3
Reporter: Nathan Myers Assignee: Nathan Myers
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-30838 Remove "_inlock" function name usage Closed
Backwards Compatibility: Fully Compatible
Participants:

 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);
    }

~
~



 Comments   
Comment by Githook User [ 25/Aug/17 ]

Author:

{'email': 'ncm@cantrip.org', 'name': 'Nathan Myers', 'username': 'ncm'}

Message: SERVER-30748 WithLock to replace _inlock
Branch: master
https://github.com/mongodb/mongo/commit/529d5de71344fda500802fa4a8671c5745ad62fa

Comment by Robert Guo (Inactive) [ 24/Aug/17 ]

https://github.com/mongodb/mongo/commit/82b9a76cd28d1687583c2ff98c63897c4d434668
https://github.com/mongodb/mongo/commit/6826796245219c5aaa9209487413b60afebb1bb7

Comment by Ramon Fernandez Marina [ 24/Aug/17 ]

Author:

{'username': u'guoyr', 'name': u'Robert Guo', 'email': u'robert.guo@10gen.com'}

Message:Revert "SERVER-30748 WithLock to replace _inlock (sp)"

This reverts commit 4c62f2f3bf028abc14a2c5cf6a1f35f507b7e04c.
Branch:master
https://github.com/mongodb/mongo/commit/6826796245219c5aaa9209487413b60afebb1bb7

Comment by Ramon Fernandez Marina [ 24/Aug/17 ]

Author:

{'username': u'guoyr', 'name': u'Robert Guo', 'email': u'robert.guo@10gen.com'}

Message:Revert "SERVER-30748 WithLock to replace _inlock"

This reverts commit 200d56c6eec8acdc6cddf0541f31c60f4ed2e760.
Branch:master
https://github.com/mongodb/mongo/commit/82b9a76cd28d1687583c2ff98c63897c4d434668

Comment by Ramon Fernandez Marina [ 24/Aug/17 ]

Author:

{'username': u'ncm', 'name': u'Nathan Myers', 'email': u'ncm@cantrip.org'}

Message:SERVER-30748 WithLock to replace _inlock
Branch:master
https://github.com/mongodb/mongo/commit/200d56c6eec8acdc6cddf0541f31c60f4ed2e760

Comment by Ramon Fernandez Marina [ 24/Aug/17 ]

Author:

{'username': u'ncm', 'name': u'Nathan Myers', 'email': u'ncm@cantrip.org'}

Message:SERVER-30748 WithLock to replace _inlock (sp)
Branch:master
https://github.com/mongodb/mongo/commit/4c62f2f3bf028abc14a2c5cf6a1f35f507b7e04c

Generated at Thu Feb 08 04:24:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.