Skip to content
  • Matheus Tavares's avatar
    replace-object: make replace operations thread-safe · b1fc9da1
    Matheus Tavares authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    replace-object functions are very close to being thread-safe: the only
    current racy section is the lazy initialization at
    prepare_replace_object(). The following patches will protect some object
    reading operations to be called threaded, but before that, replace
    functions must be protected. To do so, add a mutex to struct
    raw_object_store and acquire it before lazy initializing the
    replace_map. This won't cause any noticeable performance drop as the
    mutex will no longer be used after the replace_map is initialized.
    
    Later, when the replace functions are called in parallel, thread
    debuggers might point our use of the added replace_map_initialized flag
    as a data race. However, as this boolean variable is initialized as
    false and it's only updated once, there's no real harm. It's perfectly
    fine if the value is updated right after a thread read it in
    replace-map.h:lookup_replace_object() (there'll only be a performance
    penalty for the affected threads at that moment). We could cease the
    debugger warning protecting the variable reading at the said function.
    However, this would negatively affect performance for all threads
    calling it, at any time, so it's not really worthy since the warning
    doesn't represent a real problem. Instead, to make sure we don't get
    false positives (at ThreadSanitizer, at least) an entry for the
    respective function is added to .tsan-suppressions.
    
    Signed-off-by: default avatarMatheus Tavares <matheus.bernardino@usp.br>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    b1fc9da1