Skip to content
  • Matheus Tavares's avatar
    grep: replace grep_read_mutex by internal obj read lock · 1d1729ca
    Matheus Tavares authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    git-grep uses 'grep_read_mutex' to protect its calls to object reading
    operations. But these have their own internal lock now, which ensures a
    better performance (allowing parallel access to more regions). So, let's
    remove the former and, instead, activate the latter with
    enable_obj_read_lock().
    
    Sections that are currently protected by 'grep_read_mutex' but are not
    internally protected by the object reading lock should be surrounded by
    obj_read_lock() and obj_read_unlock(). These guarantee mutual exclusion
    with object reading operations, keeping the current behavior and
    avoiding race conditions. Namely, these places are:
    
      In grep.c:
    
      - fill_textconv() at fill_textconv_grep().
      - userdiff_get_textconv() at grep_source_1().
    
      In builtin/grep.c:
    
      - parse_object_or_die() and the submodule functions at
        grep_submodule().
      - deref_tag() and gitmodules_config_oid() at grep_objects().
    
    If these functions become thread-safe, in the future, we might remove
    the locking and probably get some speedup.
    
    Note that some of the submodule functions will already be thread-safe
    (or close to being thread-safe) with the internal object reading lock.
    However, as some of them will require additional modifications to be
    removed from the critical section, this will be done in its own patch.
    
    Signed-off-by: default avatarMatheus Tavares <matheus.bernardino@usp.br>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    1d1729ca