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

Alternative to '_inlock' function naming

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 3.5.13
    • 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

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: