Alternative to '_inlock' function naming

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Fixed
    • Priority: Major - P3
    • 3.5.13
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

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

      ~
      ~

            Assignee:
            Nathan Myers (Inactive)
            Reporter:
            Nathan Myers (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: