code: def rwlock(tmp_dir, fs, cmd, read, write, hardlink):
      """Create non-thread-safe RWLock for file paths.
  
      Args:
          tmp_dir (str): existing directory where to create the rwlock file.
          fs (FileSystem): fs instance that tmp_dir belongs to.
          cmd (str): command that will be working on these file path.
          read ([str]): file paths that are going to be read.
          write ([str]): file paths that are going to be written.
          hardlink (bool): use hardlink lock to guard rwlock file when on edit.
  
      Raises:
          LockError: raised if file paths we want to read is being written to by
              another command or if file paths we want to write is being written
              to or read from by another command.
          RWLockFileCorruptedError: raised if rwlock file is not a valid JSON.
          RWLockFileFormatError: raised if rwlock file is a valid JSON, but
              has internal format that doesn't pass our schema validation.
      """
      info = {"pid": os.getpid(), "cmd": cmd}
  
      with _edit_rwlock(tmp_dir, fs, hardlink) as lock:
          _check_blockers(
              tmp_dir, lock, info, mode="write", waiters=read + write
          )
          _check_blockers(
              tmp_dir, lock, info, mode="read", waiters=write
          )
  
          rchanges = _acquire_read(lock, info, read)
          wchanges = _acquire_write(lock, info, write)
  
      try:
          yield
      finally:
          with _edit_rwlock(tmp_dir, fs, hardlink) as lock:
              _release_write(lock, info, wchanges)
              _release_read(lock, info, rchanges)
  
imports: import json
  import os
  from collections import defaultdict
  from contextlib import contextmanager
  import psutil
  from voluptuous import Invalid, Optional, Required, Schema
  from dvc.log import logger
  from .exceptions import DvcException
  from .fs import localfs
  from .lock import make_lock
  from .utils import relpath
label_desc: Use image node_id 8 for calling a global function with example usage: rwlock(tmp_dir, fs, cmd, read, write, hardlink) without return types