Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-30748

Alternative to '_inlock' function naming

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.5.13
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      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);
          }
      

      ~
      ~

            Assignee:
            nathan.myers Nathan Myers
            Reporter:
            nathan.myers Nathan Myers
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: