From patchwork Sat Oct 27 17:29:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10658399 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 24AFB13A4 for ; Sat, 27 Oct 2018 17:30:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F28C2B011 for ; Sat, 27 Oct 2018 17:30:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 03B032B00D; Sat, 27 Oct 2018 17:30:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F95A2B011 for ; Sat, 27 Oct 2018 17:30:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728838AbeJ1CMA (ORCPT ); Sat, 27 Oct 2018 22:12:00 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:37674 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728793AbeJ1CMA (ORCPT ); Sat, 27 Oct 2018 22:12:00 -0400 Received: by mail-lj1-f196.google.com with SMTP id c4-v6so4019113lja.4 for ; Sat, 27 Oct 2018 10:30:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=drqTQBtS50H1vlemHJ1Blbd8zNG6Y/k1rTNoKJyfCqs=; b=UbFa98pbnlvd/LDeJAN1b339brRwnyspRdg9kdZ7acYTXsMeEYLfpi2f3oWwVJUw3f KZB56v0caqOU6PViz2WZf6FdUi06Fjc8A+gSG5amfyXwoodajMz5tzzcHqNSk6i9iXFA o2M9Oa6O0C05SfzkO5i4/KRe5B+kCtxkcH9Wza+B0Qo6vOrz+K3sowEP+LmU/bSYT4Ha EwCfALUmTOUEPHZ/Pt9lDCgHIXqeExneaq3XJdqlgtlFatTjr6bdniRypcQQ3L155Wor HZ1GYHdin+KcqZ+a/dROMSS5f2j1iZ07/4xivhGwOlUt2LdTl1ranSVktn5WMqVmnDXn zk3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=drqTQBtS50H1vlemHJ1Blbd8zNG6Y/k1rTNoKJyfCqs=; b=EhARxAVFWbQRnfcn+DOpLIui3ImWBcIQw2XH/AwyFiJujc/RxI97ahYEdHLzd0kh9b iVhJHAypIa7WLBbuXrB1+o+JJuMGlEsfzFP8pnn6HptPCNxy7aGcuu43VuMMlZ2tcS2H xxPAA+56kxk6f5ddjdi/JE1nr3dSxo5zjhp58nEnsKII8TMUvDBvc9rSeIurw6xg/Y+y 0Gr3PyZg+6I9xiCAtQHausDaHSG0AW16mfqBTwDejP/xlaOVI5nmZ2aP17XDAE/AJWz7 3DGxT6wsrrpVk4SK/8nTfD7hMl0SrvnITmg9XmUOdy78FuC3Zoq/LdqeM0H1b66Sohjf YmWg== X-Gm-Message-State: AGRZ1gJFBpzYyrVPXfiHDA6C3VEGbXxcLeZrroIvffeopFon7QYqAX2Q TqKxQi+sThC8RIB+bbptc0ZE6aGE X-Google-Smtp-Source: AJdET5dQgAFBXkfuPnJx8QQPyk5jEm7XSF9xpubzHUCocBBZHGMsi/Ct4aiKk8e0aOC48UCFvwE8EQ== X-Received: by 2002:a2e:924b:: with SMTP id v11-v6mr1124536ljg.9.1540661417260; Sat, 27 Oct 2018 10:30:17 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id i185-v6sm2333517lfg.89.2018.10.27.10.30.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 10:30:16 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: git@vger.kernel.org, gitster@pobox.com, peartben@gmail.com, peff@peff.net Subject: [PATCH v2 01/10] thread-utils: macros to unconditionally compile pthreads API Date: Sat, 27 Oct 2018 19:29:59 +0200 Message-Id: <20181027173008.18852-2-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181027173008.18852-1-pclouds@gmail.com> References: <20181027071003.1347-1-pclouds@gmail.com> <20181027173008.18852-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When built with NO_PTHREADS, the macros are used make the code build even though pthreads header and library may be missing. The code can still have different code paths for no threads support with HAVE_THREADS variable. There are of course impacts on no-pthreads builds: - data structure may get slightly bigger because all the mutexes and pthread_t are present (as an int) - code execution is not impacted much. Locking (in hot path) is no-op. Other wrapper function calls really should not matter much. - the binary size grows bigger because of threaded code. But at least on Linux this does not matter, if some code is not executed, it's not mapped in memory. This is a preparation step to remove "#ifdef NO_PTHREADS" in the code mostly because of maintainability. As Jeff put it > it's probably OK to stop thinking of it as "non-threaded platforms > are the default and must pay zero cost" and more as "threaded > platforms are the default, and non-threaded ones are OK to pay a > small cost as long as they still work". Signed-off-by: Nguyễn Thái Ngọc Duy --- Makefile | 2 +- thread-utils.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ thread-utils.h | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 94 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index b08d5ea258..321540a736 100644 --- a/Makefile +++ b/Makefile @@ -991,6 +991,7 @@ LIB_OBJS += sub-process.o LIB_OBJS += symlinks.o LIB_OBJS += tag.o LIB_OBJS += tempfile.o +LIB_OBJS += thread-utils.o LIB_OBJS += tmp-objdir.o LIB_OBJS += trace.o LIB_OBJS += trailer.o @@ -1674,7 +1675,6 @@ ifdef NO_PTHREADS else BASIC_CFLAGS += $(PTHREAD_CFLAGS) EXTLIBS += $(PTHREAD_LIBS) - LIB_OBJS += thread-utils.o endif ifdef HAVE_PATHS_H diff --git a/thread-utils.c b/thread-utils.c index a2135e0743..5329845691 100644 --- a/thread-utils.c +++ b/thread-utils.c @@ -20,6 +20,9 @@ int online_cpus(void) { +#ifdef NO_PTHREADS + return 1; +#else #ifdef _SC_NPROCESSORS_ONLN long ncpus; #endif @@ -59,10 +62,12 @@ int online_cpus(void) #endif return 1; +#endif } int init_recursive_mutex(pthread_mutex_t *m) { +#ifndef NO_PTHREADS pthread_mutexattr_t a; int ret; @@ -74,4 +79,47 @@ int init_recursive_mutex(pthread_mutex_t *m) pthread_mutexattr_destroy(&a); } return ret; +#else + return 0; +#endif +} + +#ifdef NO_PTHREADS +int dummy_pthread_create(pthread_t *pthread, const void *attr, + void *(*fn)(void *), void *data) +{ + /* + * Do nothing. + * + * The main purpose of this function is to break compiler's + * flow analysis and avoid -Wunused-variable false warnings. + */ + return ENOSYS; +} + +int dummy_pthread_init(void *data) +{ + /* + * Do nothing. + * + * The main purpose of this function is to break compiler's + * flow analysis or it may realize that functions like + * pthread_mutex_init() is no-op, which means the (static) + * variable is not used/initialized at all and trigger + * -Wunused-variable + */ + return ENOSYS; } + +int dummy_pthread_join(pthread_t pthread, void **retval) +{ + /* + * Do nothing. + * + * The main purpose of this function is to break compiler's + * flow analysis and avoid -Wunused-variable false warnings. + */ + return ENOSYS; +} + +#endif diff --git a/thread-utils.h b/thread-utils.h index d9a769d190..4961487ed9 100644 --- a/thread-utils.h +++ b/thread-utils.h @@ -4,12 +4,54 @@ #ifndef NO_PTHREADS #include -extern int online_cpus(void); -extern int init_recursive_mutex(pthread_mutex_t*); +#define HAVE_THREADS 1 #else -#define online_cpus() 1 +#define HAVE_THREADS 0 + +/* + * macros instead of typedefs because pthread definitions may have + * been pulled in by some system dependencies even though the user + * wants to disable pthread. + */ +#define pthread_t int +#define pthread_mutex_t int +#define pthread_cond_t int +#define pthread_key_t int + +#define pthread_mutex_init(mutex, attr) dummy_pthread_init(mutex) +#define pthread_mutex_lock(mutex) +#define pthread_mutex_unlock(mutex) +#define pthread_mutex_destroy(mutex) + +#define pthread_cond_init(cond, attr) dummy_pthread_init(cond) +#define pthread_cond_wait(cond, mutex) +#define pthread_cond_signal(cond) +#define pthread_cond_broadcast(cond) +#define pthread_cond_destroy(cond) + +#define pthread_key_create(key, attr) dummy_pthread_init(key) +#define pthread_key_delete(key) + +#define pthread_create(thread, attr, fn, data) \ + dummy_pthread_create(thread, attr, fn, data) +#define pthread_join(thread, retval) \ + dummy_pthread_join(thread, retval) + +#define pthread_setspecific(key, data) +#define pthread_getspecific(key) NULL + +int dummy_pthread_create(pthread_t *pthread, const void *attr, + void *(*fn)(void *), void *data); +int dummy_pthread_join(pthread_t pthread, void **retval); + +int dummy_pthread_init(void *); #endif + +int online_cpus(void); +int init_recursive_mutex(pthread_mutex_t*); + + #endif /* THREAD_COMPAT_H */ From patchwork Sat Oct 27 17:30:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10658405 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CBE9A14DE for ; Sat, 27 Oct 2018 17:30:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B7B1A2B007 for ; Sat, 27 Oct 2018 17:30:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A31332B011; Sat, 27 Oct 2018 17:30:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5367B2B007 for ; Sat, 27 Oct 2018 17:30:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728909AbeJ1CMD (ORCPT ); Sat, 27 Oct 2018 22:12:03 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:40974 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728793AbeJ1CMC (ORCPT ); Sat, 27 Oct 2018 22:12:02 -0400 Received: by mail-lj1-f194.google.com with SMTP id u21-v6so4010024lja.8 for ; Sat, 27 Oct 2018 10:30:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ElWD/L0AMYKRyntyrlVCHl2EzE6d7g0uBaIj7GWAy84=; b=Oob7OwQsKw14If90cwG1VOpaZUsBQvqq1NRAo6WbqrKEbnKsLy4IJr6XNBgMdRON68 cmfeAnnY3ZG++JhRc8AE6iFxXq4T15xPPQ5HvQaWf/LdlcNwIZ143nbiS0hqHHedcDHH 9KTvGZmTvqJo98rNx/aZ9QHwDFSrOXSkEBJ5J2/Fl2zqFCCbaymUnXlhS6hDBmWRrYKJ lYrZTDqQPcvEjL6Phd7xJH9T2LXYppye5b1xvq1dsPt9OQdvnbBeT0cmu6kinoBVMlff MqXG2WiFlcPewOFM37yLEns5lDG+NNV1EjTWpNbOGKRI2QpPzuqB+AL/zYoby6+EwyUl FH3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ElWD/L0AMYKRyntyrlVCHl2EzE6d7g0uBaIj7GWAy84=; b=kEoWuB+juwV4boetXdDS+HHi2MmEP3zx9sItMgr09o+CJgjwRLUiA60FMu2yyW8Cor lV+oV+rQtWNq7q4Vn1zDkk0064BSAdJB8To6LiFxXjzni0ta+EJbqZGDXQI6bZpVM65s kaD9dcHPNBsgei3qZJJiPGfx0V/bwNXaH99xubhE+ENxpRUYz+VRdR57ZeNqfsQwLtF/ jEmAMaUOn+yfWETvuB7a7unzLrVNlM7hmxUFzKJ5DD3rrbx5Hzj817EQiLugMITu8Bxu px06efUsZex9LM0Fi5PyqzDbqKKblUJx9heivBwelot5/vd/TffyFrSsPHrhbpzoSdJW 17Cg== X-Gm-Message-State: AGRZ1gJcGfLVWRWMvzZOG0bvJJbFzJsyh0n/Sc3QT52jjGe/e2oCiWD/ oA2B6E9aBxvSFRPWcv0RmRo= X-Google-Smtp-Source: AJdET5czt4r86YSA+E4v/UR9SnG/I5WfXnXihhj11HIkP8I4UyQ8NhEObbQtoUgdhsvuEHZ85Vh8Mw== X-Received: by 2002:a2e:5109:: with SMTP id f9-v6mr5270634ljb.155.1540661419955; Sat, 27 Oct 2018 10:30:19 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id i185-v6sm2333517lfg.89.2018.10.27.10.30.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 10:30:18 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: git@vger.kernel.org, gitster@pobox.com, peartben@gmail.com, peff@peff.net Subject: [PATCH v2 03/10] name-hash.c: remove #ifdef NO_PTHREADS Date: Sat, 27 Oct 2018 19:30:01 +0200 Message-Id: <20181027173008.18852-4-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181027173008.18852-1-pclouds@gmail.com> References: <20181027071003.1347-1-pclouds@gmail.com> <20181027173008.18852-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Nguyễn Thái Ngọc Duy --- name-hash.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/name-hash.c b/name-hash.c index 1fcda73cb3..b3c9ac791d 100644 --- a/name-hash.c +++ b/name-hash.c @@ -7,6 +7,7 @@ */ #define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" +#include "thread-utils.h" struct dir_entry { struct hashmap_entry ent; @@ -131,22 +132,6 @@ static int cache_entry_cmp(const void *unused_cmp_data, static int lazy_try_threaded = 1; static int lazy_nr_dir_threads; -#ifdef NO_PTHREADS - -static inline int lookup_lazy_params(struct index_state *istate) -{ - return 0; -} - -static inline void threaded_lazy_init_name_hash( - struct index_state *istate) -{ -} - -#else - -#include "thread-utils.h" - /* * Set a minimum number of cache_entries that we will handle per * thread and use that to decide how many threads to run (upto @@ -516,6 +501,9 @@ static void threaded_lazy_init_name_hash( struct lazy_dir_thread_data *td_dir; struct lazy_name_thread_data *td_name; + if (!HAVE_THREADS) + return; + k_start = 0; nr_each = DIV_ROUND_UP(istate->cache_nr, lazy_nr_dir_threads); @@ -574,8 +562,6 @@ static void threaded_lazy_init_name_hash( free(lazy_entries); } -#endif - static void lazy_init_name_hash(struct index_state *istate) { From patchwork Sat Oct 27 17:30:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10658407 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C1B7514DE for ; Sat, 27 Oct 2018 17:30:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD59E2B007 for ; Sat, 27 Oct 2018 17:30:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A0F042B011; Sat, 27 Oct 2018 17:30:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4CEC42B007 for ; Sat, 27 Oct 2018 17:30:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728914AbeJ1CME (ORCPT ); Sat, 27 Oct 2018 22:12:04 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:46031 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728610AbeJ1CME (ORCPT ); Sat, 27 Oct 2018 22:12:04 -0400 Received: by mail-lf1-f66.google.com with SMTP id c24-v6so3149437lfi.12 for ; Sat, 27 Oct 2018 10:30:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mAfV2Nz5oHseiWQnq7IrtXDy2ffEDSwSfXwchHyglKQ=; b=CvwWDLdcZM/zewZBYd+NYSE9co/qOc0qN2731u37knRXLs4LYUdJFtTPjhEmGEV1Qc IiDDWWmIBWbI0ONWE+5f0tOl/cd5Vmj+oxeAHXg9u4T2ZB9Oi6yhcI31HqUfPqH4utTJ q2G0npbwmOw2sy3LmtOqpKjvYQwjA58BR0I6zMaqr2Hr4kwP3XRASq9/6yLA0XBFeveV JzgBDPsbYKaWp7yAxTE/dD4bc0rRCSvkF38rDMLKYl9JEpftjQ3eoA2fGFnIhMAIvcuC Y/fRZnUXAiQZMiazF0anBfi12zAp/MEP9IsbXAz+JPkZ8cIn0Pmw6AQNurZUhO78G9to Qw5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mAfV2Nz5oHseiWQnq7IrtXDy2ffEDSwSfXwchHyglKQ=; b=OK7iI12DwXzEUr8ntI4HKe2tsce6WiACWvMsKNyizipNLPq4JAf6Wlm0ZFjYGpUaPx unYx2I+WLyPRKtMEWrGHvObm+dNQK8JuHnPAoOXHHFoZBk3b9mlaTv35Xka40DnzoHFH lKgClbnF+VKAKj/ZnAcTUVjY0bpAg+EAbWUCmbEOwYY3GwZAT0TP3QRAMfgqTMYggZaE mEg6ddXwJm4OgWNt4P5RB4HBiNTvfr4vWOC9N/+k8oGp8udOqM6fv6xvIL9Jbk8N80eV Ojq+hhcNYe2ko+iyzUzMB2nweJT4LmGBxnL9mAcl/WN4YAPsAue4yaqPw+Ggk/+GXiet mr4A== X-Gm-Message-State: AGRZ1gIsqt42phDfrBqRX5y4hyzANjFGCa98jt04x0vjW3FViykRlXiP X721huAv7X+6UW07if+B2u0= X-Google-Smtp-Source: AJdET5ekh4FzqZOCxB9YIdtB/Ma5/dpI6mx//eSNe52+gK2eYzX83+gp3RRDmPC+jrlzslorNXetWQ== X-Received: by 2002:a19:ae03:: with SMTP id f3mr5075773lfc.86.1540661421485; Sat, 27 Oct 2018 10:30:21 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id i185-v6sm2333517lfg.89.2018.10.27.10.30.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 10:30:20 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: git@vger.kernel.org, gitster@pobox.com, peartben@gmail.com, peff@peff.net Subject: [PATCH v2 04/10] attr.c: remove #ifdef NO_PTHREADS Date: Sat, 27 Oct 2018 19:30:02 +0200 Message-Id: <20181027173008.18852-5-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181027173008.18852-1-pclouds@gmail.com> References: <20181027071003.1347-1-pclouds@gmail.com> <20181027173008.18852-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Nguyễn Thái Ngọc Duy --- attr.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/attr.c b/attr.c index 60d284796d..eaece6658d 100644 --- a/attr.c +++ b/attr.c @@ -41,23 +41,17 @@ const char *git_attr_name(const struct git_attr *attr) struct attr_hashmap { struct hashmap map; -#ifndef NO_PTHREADS pthread_mutex_t mutex; -#endif }; static inline void hashmap_lock(struct attr_hashmap *map) { -#ifndef NO_PTHREADS pthread_mutex_lock(&map->mutex); -#endif } static inline void hashmap_unlock(struct attr_hashmap *map) { -#ifndef NO_PTHREADS pthread_mutex_unlock(&map->mutex); -#endif } /* @@ -498,23 +492,17 @@ static struct check_vector { size_t nr; size_t alloc; struct attr_check **checks; -#ifndef NO_PTHREADS pthread_mutex_t mutex; -#endif } check_vector; static inline void vector_lock(void) { -#ifndef NO_PTHREADS pthread_mutex_lock(&check_vector.mutex); -#endif } static inline void vector_unlock(void) { -#ifndef NO_PTHREADS pthread_mutex_unlock(&check_vector.mutex); -#endif } static void check_vector_add(struct attr_check *c) @@ -1181,8 +1169,6 @@ void git_all_attrs(const struct index_state *istate, void attr_start(void) { -#ifndef NO_PTHREADS pthread_mutex_init(&g_attr_hashmap.mutex, NULL); pthread_mutex_init(&check_vector.mutex, NULL); -#endif } From patchwork Sat Oct 27 17:30:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10658409 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1260713A4 for ; Sat, 27 Oct 2018 17:30:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F07722B007 for ; Sat, 27 Oct 2018 17:30:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E49642B011; Sat, 27 Oct 2018 17:30:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5920F2B007 for ; Sat, 27 Oct 2018 17:30:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728918AbeJ1CMG (ORCPT ); Sat, 27 Oct 2018 22:12:06 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:46033 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728793AbeJ1CMF (ORCPT ); Sat, 27 Oct 2018 22:12:05 -0400 Received: by mail-lf1-f67.google.com with SMTP id c24-v6so3149454lfi.12 for ; Sat, 27 Oct 2018 10:30:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+Eo+N31S9V9c5X6pW5M1J4OPBILzxVMSgzud16OJELY=; b=GIZJkYwvqrD/EguiT5xthcee+PEm4uGGOfzJsleGtMSdUHkBdhaHEMyxrYkWfy0ZBR n/hIXqCGe47E7/YrsFHh+BwRPZKOTXUEYiOkBw3fxbLGxlnccvS+2elEPDaBSQBq92Qe Cj+XujT/n3PVHnwdmdGUY1RievSXLnh5q2wTW//B6w/Ku4VPa3Le9K0GCEOi7sXLl01B tfcbzFHIJ3y5XeovY3QSnLMmM81nWfRhst7aulu8YKb077tJSaduEbH+eNNAB/Uu306N qkLGrCfRFPTBq4WF8SgooXg9t7FAnnpCLhth8+tIZmGjwex32yQ09ZCLdQt+jwhyU37v eezQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+Eo+N31S9V9c5X6pW5M1J4OPBILzxVMSgzud16OJELY=; b=caHBelLYpBI/dCUhHu+iE51hFH+OusuEz6L7BM7nbkhC70ZaH8vRUHsKV14uWimp+l ibbxK31lmiWlEhq2f7dSLAOe+XYQNmf5uAZCem3vDWaX/9QB+iphT8cfCkrX5uqZaJ9I 3BTk1DbajIY/tPgslebdBQ2UmX1brT2saFEgbr/up65hy0o2iBZEJjpBmMWNpJRuEgcp NIgzQXjmwyFRK4kOlJs4OCHyB3YjP523xM4lmEDl4RfvL9iwcCn093WKByqhMEWuf6UJ mhJ7NQOXmL6XqquLxllMN6931jNfkQj1H1/iPq6etD1eT6dP8kY3OCcpni71VzKX83T/ u4xg== X-Gm-Message-State: AGRZ1gL1gs+/sjfI8OJVI1O5r5v3//8AXrZWBfKcTne4cKFwraFGD7bk 2pGavwK3W7093HMpoJZpS6Af5ksL X-Google-Smtp-Source: AJdET5e4FxsP+HOS8ab1WpHW91PvAQpfWXv9mMdnG10SC0z/JLxkNsJpuKIMuKLDbRt9YyhrfeCoPQ== X-Received: by 2002:a19:1a41:: with SMTP id a62-v6mr4750356lfa.40.1540661422613; Sat, 27 Oct 2018 10:30:22 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id i185-v6sm2333517lfg.89.2018.10.27.10.30.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 10:30:21 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: git@vger.kernel.org, gitster@pobox.com, peartben@gmail.com, peff@peff.net Subject: [PATCH v2 05/10] grep: remove #ifdef NO_PTHREADS Date: Sat, 27 Oct 2018 19:30:03 +0200 Message-Id: <20181027173008.18852-6-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181027173008.18852-1-pclouds@gmail.com> References: <20181027071003.1347-1-pclouds@gmail.com> <20181027173008.18852-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/grep.c | 59 +++++++++++++++++++------------------------------- grep.c | 6 ----- grep.h | 6 ----- 3 files changed, 22 insertions(+), 49 deletions(-) diff --git a/builtin/grep.c b/builtin/grep.c index d8508ddf79..6dd15dbaa2 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -34,7 +34,6 @@ static int recurse_submodules; #define GREP_NUM_THREADS_DEFAULT 8 static int num_threads; -#ifndef NO_PTHREADS static pthread_t *threads; /* We use one producer thread and THREADS consumer @@ -234,6 +233,9 @@ static int wait_all(void) int hit = 0; int i; + if (!HAVE_THREADS) + return 0; + grep_lock(); all_work_added = 1; @@ -265,13 +267,6 @@ static int wait_all(void) return hit; } -#else /* !NO_PTHREADS */ - -static int wait_all(void) -{ - return 0; -} -#endif static int grep_cmd_config(const char *var, const char *value, void *cb) { @@ -284,8 +279,7 @@ static int grep_cmd_config(const char *var, const char *value, void *cb) if (num_threads < 0) die(_("invalid number of threads specified (%d) for %s"), num_threads, var); -#ifdef NO_PTHREADS - else if (num_threads && num_threads != 1) { + else if (!HAVE_THREADS && num_threads && num_threads != 1) { /* * TRANSLATORS: %s is the configuration * variable for tweaking threads, currently @@ -294,7 +288,6 @@ static int grep_cmd_config(const char *var, const char *value, void *cb) warning(_("no threads support, ignoring %s"), var); num_threads = 0; } -#endif } if (!strcmp(var, "submodule.recurse")) @@ -330,17 +323,14 @@ static int grep_oid(struct grep_opt *opt, const struct object_id *oid, grep_source_init(&gs, GREP_SOURCE_OID, pathbuf.buf, path, oid); strbuf_release(&pathbuf); -#ifndef NO_PTHREADS - if (num_threads) { + if (HAVE_THREADS && num_threads) { /* * add_work() copies gs and thus assumes ownership of * its fields, so do not call grep_source_clear() */ add_work(opt, &gs); return 0; - } else -#endif - { + } else { int hit; hit = grep_source(opt, &gs); @@ -363,17 +353,14 @@ static int grep_file(struct grep_opt *opt, const char *filename) grep_source_init(&gs, GREP_SOURCE_FILE, buf.buf, filename, filename); strbuf_release(&buf); -#ifndef NO_PTHREADS - if (num_threads) { + if (HAVE_THREADS && num_threads) { /* * add_work() copies gs and thus assumes ownership of * its fields, so do not call grep_source_clear() */ add_work(opt, &gs); return 0; - } else -#endif - { + } else { int hit; hit = grep_source(opt, &gs); @@ -1038,20 +1025,20 @@ int cmd_grep(int argc, const char **argv, const char *prefix) pathspec.recursive = 1; pathspec.recurse_submodules = !!recurse_submodules; -#ifndef NO_PTHREADS - if (list.nr || cached || show_in_pager) - num_threads = 0; - else if (num_threads == 0) - num_threads = GREP_NUM_THREADS_DEFAULT; - else if (num_threads < 0) - die(_("invalid number of threads specified (%d)"), num_threads); - if (num_threads == 1) + if (HAVE_THREADS) { + if (list.nr || cached || show_in_pager) + num_threads = 0; + else if (num_threads == 0) + num_threads = GREP_NUM_THREADS_DEFAULT; + else if (num_threads < 0) + die(_("invalid number of threads specified (%d)"), num_threads); + if (num_threads == 1) + num_threads = 0; + } else { + if (num_threads) + warning(_("no threads support, ignoring --threads")); num_threads = 0; -#else - if (num_threads) - warning(_("no threads support, ignoring --threads")); - num_threads = 0; -#endif + } if (!num_threads) /* @@ -1062,15 +1049,13 @@ int cmd_grep(int argc, const char **argv, const char *prefix) */ compile_grep_patterns(&opt); -#ifndef NO_PTHREADS - if (num_threads) { + if (HAVE_THREADS && num_threads) { if (!(opt.name_only || opt.unmatch_name_only || opt.count) && (opt.pre_context || opt.post_context || opt.file_break || opt.funcbody)) skip_first_line = 1; start_threads(&opt); } -#endif if (show_in_pager && (cached || list.nr)) die(_("--open-files-in-pager only works on the worktree")); diff --git a/grep.c b/grep.c index f6bd89e40b..4db1510d16 100644 --- a/grep.c +++ b/grep.c @@ -1513,7 +1513,6 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol, } } -#ifndef NO_PTHREADS int grep_use_locks; /* @@ -1539,11 +1538,6 @@ static inline void grep_attr_unlock(void) */ pthread_mutex_t grep_read_mutex; -#else -#define grep_attr_lock() -#define grep_attr_unlock() -#endif - static int match_funcname(struct grep_opt *opt, struct grep_source *gs, char *bol, char *eol) { xdemitconf_t *xecfg = opt->priv; diff --git a/grep.h b/grep.h index 1a57d12b90..fb04893721 100644 --- a/grep.h +++ b/grep.h @@ -229,7 +229,6 @@ int grep_source(struct grep_opt *opt, struct grep_source *gs); extern struct grep_opt *grep_opt_dup(const struct grep_opt *opt); extern int grep_threads_ok(const struct grep_opt *opt); -#ifndef NO_PTHREADS /* * Mutex used around access to the attributes machinery if * opt->use_threads. Must be initialized/destroyed by callers! @@ -250,9 +249,4 @@ static inline void grep_read_unlock(void) pthread_mutex_unlock(&grep_read_mutex); } -#else -#define grep_read_lock() -#define grep_read_unlock() -#endif - #endif From patchwork Sat Oct 27 17:30:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10658411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 88CB314DE for ; Sat, 27 Oct 2018 17:30:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7434B2B007 for ; Sat, 27 Oct 2018 17:30:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 68CE42B011; Sat, 27 Oct 2018 17:30:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EAF732B007 for ; Sat, 27 Oct 2018 17:30:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728925AbeJ1CMH (ORCPT ); Sat, 27 Oct 2018 22:12:07 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:40958 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728610AbeJ1CMG (ORCPT ); Sat, 27 Oct 2018 22:12:06 -0400 Received: by mail-lj1-f193.google.com with SMTP id t22-v6so4013837lji.7 for ; Sat, 27 Oct 2018 10:30:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=34AlMYInjUJvKBJ83Ba7wlLqRcceLi+ycsU6IviV8ho=; b=Nm1IhKdv44uK25Nb1C8Wg+IAquFSmo7iwESwtovJ8kT5zGHcPAZYEExzlalqNoaLjU ufYNa44hYKRbPwlaJZsAhkFyHYWlGI3iKBnXpz4I2V8RjLglZiNorgnu/51KChzFjGt9 zUPdq4hm4xUdkZ3XSWkDxMlI+WO4v7NEJxwkMm435oM9IBEChucG3p5QvPx0Sxax3ll6 zKoKiPRa6DHaWkicx39mb0CkwfiKZ0LNdhNDC+hbbeqfB14lHRfsBuE/gD8TrjANLfyL VDF3B/H5579TGoHu/hbqU17SQyWggMWBspKB6PmI5CUHpdbr6L1nbahFZkeEXQeEi0X0 z14w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=34AlMYInjUJvKBJ83Ba7wlLqRcceLi+ycsU6IviV8ho=; b=Yl9MoEqOKKzpQfoWAhZBxfP49pZExOjZVD9WhTBTOOF4CfT/fgw3ylt/gwk+reTjcc lLj/QPUjUm/gKFh2Bz6leetJ5YA9BkWMU7cCKT4H7bnQ8QjQqURpFILBdswitoewRofO wHgQ+U0+tdlqFDy1fSV/OrbLHGuLbI+Qdt6SAI0XLXWQs9aThz1knXFWefiRE/a76Kzp iA5QOKNfo7guAS6F5jj/zzt4F1eKtqJAwL953ughLgcll9QP8RXS8boztx64Gf4TiniT kPE/XTbIwfRnKCmELR4trXx8NU6XQd79xruM4M2mJiNyt+wlW+hWzN/NPKN56EvpkVzV 0TKA== X-Gm-Message-State: AGRZ1gJFP/4qeR/nIMVn2zE72iaBjjWjtGvphCipkAx3o5IBCJpOhcfR DSNiSlZsYt6oTetEc34f2DU= X-Google-Smtp-Source: AJdET5fF+YeX8cFOD7I8YpcKd2nPAivwa9EThosySooJimNxAZZs4x8K6CB6Ww6DUH+wa62fssUAuQ== X-Received: by 2002:a2e:21d2:: with SMTP id h79-v6mr5292594lji.46.1540661423781; Sat, 27 Oct 2018 10:30:23 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id i185-v6sm2333517lfg.89.2018.10.27.10.30.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 10:30:23 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: git@vger.kernel.org, gitster@pobox.com, peartben@gmail.com, peff@peff.net Subject: [PATCH v2 06/10] preload-index.c: remove #ifdef NO_PTHREADS Date: Sat, 27 Oct 2018 19:30:04 +0200 Message-Id: <20181027173008.18852-7-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181027173008.18852-1-pclouds@gmail.com> References: <20181027071003.1347-1-pclouds@gmail.com> <20181027173008.18852-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Nguyễn Thái Ngọc Duy --- preload-index.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/preload-index.c b/preload-index.c index 9e7152ab14..0e24886aca 100644 --- a/preload-index.c +++ b/preload-index.c @@ -7,17 +7,7 @@ #include "fsmonitor.h" #include "config.h" #include "progress.h" - -#ifdef NO_PTHREADS -static void preload_index(struct index_state *index, - const struct pathspec *pathspec, - unsigned int refresh_flags) -{ - ; /* nothing */ -} -#else - -#include +#include "thread-utils.h" /* * Mostly randomly chosen maximum thread counts: we @@ -108,7 +98,7 @@ static void preload_index(struct index_state *index, struct thread_data data[MAX_PARALLEL]; struct progress_data pd; - if (!core_preload_index) + if (!HAVE_THREADS || !core_preload_index) return; threads = index->cache_nr / THREAD_COST; @@ -151,7 +141,6 @@ static void preload_index(struct index_state *index, trace_performance_leave("preload index"); } -#endif int read_index_preload(struct index_state *index, const struct pathspec *pathspec, From patchwork Sat Oct 27 17:30:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10658413 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 420F314DE for ; Sat, 27 Oct 2018 17:30:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D2B42B007 for ; Sat, 27 Oct 2018 17:30:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 21C312B011; Sat, 27 Oct 2018 17:30:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B37C82B007 for ; Sat, 27 Oct 2018 17:30:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728931AbeJ1CMI (ORCPT ); Sat, 27 Oct 2018 22:12:08 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:33964 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728793AbeJ1CMH (ORCPT ); Sat, 27 Oct 2018 22:12:07 -0400 Received: by mail-lj1-f193.google.com with SMTP id g8-v6so1121812ljk.1 for ; Sat, 27 Oct 2018 10:30:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SF0N9DVdrmmyoJxDZIeToLkpdB5o/uj/ao+EU7EKPtg=; b=Fm3rLLWntHQMTAfFVBULFPO8lXTZAiJm8xhQiHeYwtmgKiC3vHy2br+tyT+VztZIWc EDVjij3UIVOutUvAU6eZtoqpEKvnNd1xh+M40BNnlJcLDf+wL2vE4by5gnJ+PvMwIs3j N+nE90w9xldsSYiap9G22vpdltOoiO5MmU/BhbEn5xLxfXd7LPwVWtr4akBd0hbi9Juz ZoqxJn38OItqcFlPmH/NyjocJjvBNyJaTGAxMcT6jgbN2JOmbl6wap7E9cZRrRKeA9wq eBwVAxj0qv6gpWLYObfSlLB716sMJHPntYGZUKf4ICS7wSd2WDqH6idpta8+ujKpLKxn ti9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SF0N9DVdrmmyoJxDZIeToLkpdB5o/uj/ao+EU7EKPtg=; b=IOaN4gieqOH2qSI+Eo1ygMIHavBWmZDHeqQtLmNArXRyEyEcKjg3Sf6Emin7dhNbSE htJw2lEDh8+SO7l3qMsHVu6EVU5Npdinu4tNA2GFGpssWcq/Lph822o/PEd83YeqNnDI w35Ne2ntnOZrh2fQb8I1meR9WnwKGjC/60Ie+qLL/v6temtccjfCpV0iosttoZzOdXI2 CdCv1yGO5FzOtIiwNsAH/BiS65f2YEFrB28jv8bgVLArl50Mw9aTa4x4FE9+Pci6n6Et 5Y8/an3RcQcuV+iGOnclK4Zjw6SMZcbTIQNfa2lpw9RG/odQv+qdp5fTtPXt2PJz380t UhcA== X-Gm-Message-State: AGRZ1gILe7Dtm0OPNXUTZ24MC2/QgNxv4hlaXu9SEX3oNtXwO7UVDiom +B7OwhiSQdQCEhU1jTSZoCg= X-Google-Smtp-Source: AJdET5dETVAtmue6+NQw26b3FbcdIsaJGnBJiAm5AyeU9pvKw7usHJgmsN01AQS046AFvF4IR8u/mQ== X-Received: by 2002:a2e:20da:: with SMTP id g87-v6mr4643910lji.88.1540661424958; Sat, 27 Oct 2018 10:30:24 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id i185-v6sm2333517lfg.89.2018.10.27.10.30.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 10:30:24 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: git@vger.kernel.org, gitster@pobox.com, peartben@gmail.com, peff@peff.net Subject: [PATCH v2 07/10] pack-objects: remove #ifdef NO_PTHREADS Date: Sat, 27 Oct 2018 19:30:05 +0200 Message-Id: <20181027173008.18852-8-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181027173008.18852-1-pclouds@gmail.com> References: <20181027071003.1347-1-pclouds@gmail.com> <20181027173008.18852-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/pack-objects.c | 26 ++------------------------ pack-objects.h | 6 ------ 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index b059b86aee..12edd6da16 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1953,8 +1953,6 @@ static int delta_cacheable(unsigned long src_size, unsigned long trg_size, return 0; } -#ifndef NO_PTHREADS - /* Protect access to object database */ static pthread_mutex_t read_mutex; #define read_lock() pthread_mutex_lock(&read_mutex) @@ -1979,16 +1977,6 @@ static pthread_mutex_t progress_mutex; * ahead in the list because they can be stolen and would need * progress_mutex for protection. */ -#else - -#define read_lock() (void)0 -#define read_unlock() (void)0 -#define cache_lock() (void)0 -#define cache_unlock() (void)0 -#define progress_lock() (void)0 -#define progress_unlock() (void)0 - -#endif /* * Return the size of the object without doing any delta @@ -2347,8 +2335,6 @@ static void find_deltas(struct object_entry **list, unsigned *list_size, free(array); } -#ifndef NO_PTHREADS - static void try_to_free_from_threads(size_t size) { read_lock(); @@ -2578,10 +2564,6 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size, free(p); } -#else -#define ll_find_deltas(l, s, w, d, p) find_deltas(l, &s, w, d, p) -#endif - static void add_tag_chain(const struct object_id *oid) { struct tag *tag; @@ -2734,12 +2716,10 @@ static int git_pack_config(const char *k, const char *v, void *cb) if (delta_search_threads < 0) die(_("invalid number of threads specified (%d)"), delta_search_threads); -#ifdef NO_PTHREADS - if (delta_search_threads != 1) { + if (!HAVE_THREADS && delta_search_threads != 1) { warning(_("no threads support, ignoring %s"), k); delta_search_threads = 0; } -#endif return 0; } if (!strcmp(k, "pack.indexversion")) { @@ -3402,10 +3382,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) if (!delta_search_threads) /* --threads=0 means autodetect */ delta_search_threads = online_cpus(); -#ifdef NO_PTHREADS - if (delta_search_threads != 1) + if (!HAVE_THREADS && delta_search_threads != 1) warning(_("no threads support, ignoring --threads")); -#endif if (!pack_to_stdout && !pack_size_limit) pack_size_limit = pack_size_limit_cfg; if (pack_to_stdout && pack_size_limit) diff --git a/pack-objects.h b/pack-objects.h index 2ca39cfcfe..3a42727c7d 100644 --- a/pack-objects.h +++ b/pack-objects.h @@ -145,9 +145,7 @@ struct packing_data { struct packed_git **in_pack_by_idx; struct packed_git **in_pack; -#ifndef NO_PTHREADS pthread_mutex_t lock; -#endif /* * This list contains entries for bases which we know the other side @@ -169,15 +167,11 @@ void prepare_packing_data(struct packing_data *pdata); static inline void packing_data_lock(struct packing_data *pdata) { -#ifndef NO_PTHREADS pthread_mutex_lock(&pdata->lock); -#endif } static inline void packing_data_unlock(struct packing_data *pdata) { -#ifndef NO_PTHREADS pthread_mutex_unlock(&pdata->lock); -#endif } struct object_entry *packlist_alloc(struct packing_data *pdata, From patchwork Sat Oct 27 17:30:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10658415 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 88D1413A4 for ; Sat, 27 Oct 2018 17:30:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 744722B007 for ; Sat, 27 Oct 2018 17:30:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 685842B011; Sat, 27 Oct 2018 17:30:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54E1C2B007 for ; Sat, 27 Oct 2018 17:30:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728939AbeJ1CMI (ORCPT ); Sat, 27 Oct 2018 22:12:08 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:46451 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728610AbeJ1CMI (ORCPT ); Sat, 27 Oct 2018 22:12:08 -0400 Received: by mail-lj1-f195.google.com with SMTP id x3-v6so4000131lji.13 for ; Sat, 27 Oct 2018 10:30:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xLCcqTzF++H24RbkSBiziTtVjx4je/Bxw9RWY3pqi9k=; b=bZhRnU9eo8uVq31+urK7rSLgWmqrg3BR0lyWfVwFxEezuOUKXdgK9QYIejbMR8jFak OUsjP3WrzAUn3X5MwC2TZgPguXLHFVhonIMvEw7LnLvu225bBsfKHXn85G26O1t44ogj E8ok/CTXT3cdqhd9EvfpS0HPbtJ+v3OLSNkisrzxAY78IcHWMb3/FA2/7FhCSGwdU0O9 Pkg9lLx2WXyq6eL6LHeCnfjVxJKl+jg0oVaS6nNqR9nGogpF9k6kG/QG02Dir0NDjgLP I0kgEKHmOy+rjcPftM+kzIEmRb19MNeakf/Zqs6W4scUVK9zFgkIIp3mZSYai+UpyUpP MTFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xLCcqTzF++H24RbkSBiziTtVjx4je/Bxw9RWY3pqi9k=; b=TSsip9vzIAw8zAZ9MSYxnib7ke3MnYdfTCBuZV+2DCVHhoyPWhUpckOCum7yt8QxaW K3VZTzHwHNwhbltlSuc4em3MtuCo8LCKDYm+BoZJzEikhXBSUO63/VGkHToHHV2q6RdZ KEqcwp/LxgCvFi3DoHqrFBLXQByrveo5EyazhYLgunPYWCIgaD1wAs2Uvgr47gRqLhRi gNrDePrpHbRSaXKMgv9NkaT0zDkK4yyONSc1TPg5YLBTu/N7BLhYQsrlBp37jl0vXFQY x7TF4yvva42Ng5G9L9eq3BTPEn20PYRRXxVre470GD3/sv37JAvM6w9dZSV5s0zGOg2M Ovzg== X-Gm-Message-State: AGRZ1gJJbmVWCQeiNMg+SgnMnyFFPKB2XXXU1PjXkkpHTuzmktj2TzDr SlGFSChMBdKyb9nkbulk5S4= X-Google-Smtp-Source: AJdET5eaEuEw3kQujV+NtpD9A3mVUqwULpTYH8q33wuJoqA3eIdjLRoF4C/62l1RhVqyIDLKazprKw== X-Received: by 2002:a2e:5054:: with SMTP id v20-v6mr5201628ljd.45.1540661426309; Sat, 27 Oct 2018 10:30:26 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id i185-v6sm2333517lfg.89.2018.10.27.10.30.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 10:30:25 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: git@vger.kernel.org, gitster@pobox.com, peartben@gmail.com, peff@peff.net Subject: [PATCH v2 08/10] read-cache.c: remove #ifdef NO_PTHREADS Date: Sat, 27 Oct 2018 19:30:06 +0200 Message-Id: <20181027173008.18852-9-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181027173008.18852-1-pclouds@gmail.com> References: <20181027071003.1347-1-pclouds@gmail.com> <20181027173008.18852-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Nguyễn Thái Ngọc Duy --- read-cache.c | 49 ++++++++++++++++++------------------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/read-cache.c b/read-cache.c index d57958233e..ba870bc3fd 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1920,19 +1920,15 @@ struct index_entry_offset_table struct index_entry_offset entries[FLEX_ARRAY]; }; -#ifndef NO_PTHREADS static struct index_entry_offset_table *read_ieot_extension(const char *mmap, size_t mmap_size, size_t offset); static void write_ieot_extension(struct strbuf *sb, struct index_entry_offset_table *ieot); -#endif static size_t read_eoie_extension(const char *mmap, size_t mmap_size); static void write_eoie_extension(struct strbuf *sb, git_hash_ctx *eoie_context, size_t offset); struct load_index_extensions { -#ifndef NO_PTHREADS pthread_t pthread; -#endif struct index_state *istate; const char *mmap; size_t mmap_size; @@ -2010,8 +2006,6 @@ static unsigned long load_all_cache_entries(struct index_state *istate, return consumed; } -#ifndef NO_PTHREADS - /* * Mostly randomly chosen maximum thread counts: we * cap the parallelism to online_cpus() threads, and we want @@ -2122,7 +2116,6 @@ static unsigned long load_cache_entries_threaded(struct index_state *istate, con return consumed; } -#endif /* remember to discard_cache() before reading a different cache! */ int do_read_index(struct index_state *istate, const char *path, int must_exist) @@ -2135,10 +2128,8 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist) size_t mmap_size; struct load_index_extensions p; size_t extension_offset = 0; -#ifndef NO_PTHREADS int nr_threads, cpus; struct index_entry_offset_table *ieot = NULL; -#endif if (istate->initialized) return istate->cache_nr; @@ -2181,15 +2172,18 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist) src_offset = sizeof(*hdr); -#ifndef NO_PTHREADS - nr_threads = git_config_get_index_threads(); + if (HAVE_THREADS) { + nr_threads = git_config_get_index_threads(); - /* TODO: does creating more threads than cores help? */ - if (!nr_threads) { - nr_threads = istate->cache_nr / THREAD_COST; - cpus = online_cpus(); - if (nr_threads > cpus) - nr_threads = cpus; + /* TODO: does creating more threads than cores help? */ + if (!nr_threads) { + nr_threads = istate->cache_nr / THREAD_COST; + cpus = online_cpus(); + if (nr_threads > cpus) + nr_threads = cpus; + } + } else { + nr_threads = 1; } if (nr_threads > 1) { @@ -2219,21 +2213,16 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist) } else { src_offset += load_all_cache_entries(istate, mmap, mmap_size, src_offset); } -#else - src_offset += load_all_cache_entries(istate, mmap, mmap_size, src_offset); -#endif istate->timestamp.sec = st.st_mtime; istate->timestamp.nsec = ST_MTIME_NSEC(st); /* if we created a thread, join it otherwise load the extensions on the primary thread */ -#ifndef NO_PTHREADS - if (extension_offset) { + if (HAVE_THREADS && extension_offset) { int ret = pthread_join(p.pthread, NULL); if (ret) die(_("unable to join load_index_extensions thread: %s"), strerror(ret)); } -#endif if (!extension_offset) { p.src_offset = src_offset; load_index_extensions(&p); @@ -2756,8 +2745,11 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, if (ce_write(&c, newfd, &hdr, sizeof(hdr)) < 0) return -1; -#ifndef NO_PTHREADS - nr_threads = git_config_get_index_threads(); + if (HAVE_THREADS) + nr_threads = git_config_get_index_threads(); + else + nr_threads = 1; + if (nr_threads != 1) { int ieot_blocks, cpus; @@ -2787,7 +2779,6 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, ieot_entries = DIV_ROUND_UP(entries, ieot_blocks); } } -#endif offset = lseek(newfd, 0, SEEK_CUR); if (offset < 0) { @@ -2871,8 +2862,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, * strip_extensions parameter as we need it when loading the shared * index. */ -#ifndef NO_PTHREADS - if (ieot) { + if (HAVE_THREADS && ieot) { struct strbuf sb = STRBUF_INIT; write_ieot_extension(&sb, ieot); @@ -2883,7 +2873,6 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, if (err) return -1; } -#endif if (!strip_extensions && istate->split_index) { struct strbuf sb = STRBUF_INIT; @@ -3469,7 +3458,6 @@ static void write_eoie_extension(struct strbuf *sb, git_hash_ctx *eoie_context, strbuf_add(sb, hash, the_hash_algo->rawsz); } -#ifndef NO_PTHREADS #define IEOT_VERSION (1) static struct index_entry_offset_table *read_ieot_extension(const char *mmap, size_t mmap_size, size_t offset) @@ -3542,4 +3530,3 @@ static void write_ieot_extension(struct strbuf *sb, struct index_entry_offset_ta strbuf_add(sb, &buffer, sizeof(uint32_t)); } } -#endif From patchwork Sat Oct 27 17:30:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10658417 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 582CE13A4 for ; Sat, 27 Oct 2018 17:30:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 439A22B007 for ; Sat, 27 Oct 2018 17:30:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3801B2B011; Sat, 27 Oct 2018 17:30:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98F9F2B007 for ; Sat, 27 Oct 2018 17:30:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728944AbeJ1CMK (ORCPT ); Sat, 27 Oct 2018 22:12:10 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:39938 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728793AbeJ1CMJ (ORCPT ); Sat, 27 Oct 2018 22:12:09 -0400 Received: by mail-lj1-f195.google.com with SMTP id t22-v6so4013908lji.7 for ; Sat, 27 Oct 2018 10:30:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6Qk+6dxMRf1uSVCWaRLkgpXbfUTW045jwm0hjrNlab0=; b=Fan2DCy+BeZ7Sw6Q5IYj/LTTjJ3a3qb4ixPFDjjIHsN9bzDPa96Frq6FkMqiKwZlWK 1ZjKUALeaHDIRNmmE8zZqKXNXAjd/B5zD4TDBrVcD7M2Y9rzWwTbRHqlOc9OZd2PwKIj r4d3eS7PO/VUtfntt+wPvI81b/mJfE0VYcdspl3Z8im287gQTbyba27o/X5QqKXL5CxZ CP70zz0/I5rydklLhb+M7nHcwfRnHQ/T40U4gJ28g6YiM389SL5iJcySct+Q8aKHjgRe fe0kC7F3A7auu9zhsiF0eN4GBXAfOq5ffdJnOpsXgX95YzCuypiwzPxatj2F0HM+sD0T kOaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6Qk+6dxMRf1uSVCWaRLkgpXbfUTW045jwm0hjrNlab0=; b=jXlK3VaURUoBnhPItvHGjO0tjP7eilyR+tBNm2GqEYE+LSBrGtWAdleUQoZ2fD2Kr1 o2g+2hZ2DFRHXbntFyZVUOTeouACQPCAqGbhlzXuDupwfpWq1UAlnBRZhSaCPojRDGsi MDWG/dbzn7pICGdj936AoxiykuBa2Y6Avnos0I8WXdmHWsyH67BWHU6utQ9yqS3SBaf0 dQ886ZxO7hQF1lZonVaxX1pXJoiHtrg4dky/fbJE2DWBe09Ktx4fUowDUnW3wlSkJcDW xSeUll4bJxocF/S2cr2RCatjKIN1175+1fY6qYCtCEYaSPfWMD1dNu8DBa3YpsX3/Who TfNg== X-Gm-Message-State: AGRZ1gJVaTyX1iNiALAuvOUF0XQ7y6nY8QBYK9cIF2FxoPHevfPVHmxS k1HMfhg+guAnwvO8DmmGO04= X-Google-Smtp-Source: AJdET5c0Whua4e4JRAMa8fXijLVZNMCFysOhoXQG/sHydxLyb3xXwqJ+Db9MH9yztseaTCd61ymNfw== X-Received: by 2002:a2e:8457:: with SMTP id u23-v6mr4584344ljh.154.1540661427381; Sat, 27 Oct 2018 10:30:27 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id i185-v6sm2333517lfg.89.2018.10.27.10.30.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 10:30:26 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: git@vger.kernel.org, gitster@pobox.com, peartben@gmail.com, peff@peff.net Subject: [PATCH v2 09/10] Clean up pthread_create() error handling Date: Sat, 27 Oct 2018 19:30:07 +0200 Message-Id: <20181027173008.18852-10-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181027173008.18852-1-pclouds@gmail.com> References: <20181027071003.1347-1-pclouds@gmail.com> <20181027173008.18852-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Normally pthread_create() rarely fails and sometimes error handling can be neglected. But with new pthreads wrapper, pthread_create() will return ENOSYS on a system without thread support. Threaded code _is_ protected by HAVE_THREADS and pthread_create() should never run in the first place. But the situation could change in the future and bugs may sneak in. Make sure that all pthread_create() checks and handles the result. While at there, mark these strings for translation if they aren't. Signed-off-by: Nguyễn Thái Ngọc Duy --- name-hash.c | 16 ++++++++++------ preload-index.c | 8 ++++++-- run-command.c | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/name-hash.c b/name-hash.c index b3c9ac791d..623ca6923a 100644 --- a/name-hash.c +++ b/name-hash.c @@ -494,6 +494,7 @@ static inline void lazy_update_dir_ref_counts( static void threaded_lazy_init_name_hash( struct index_state *istate) { + int err; int nr_each; int k_start; int t; @@ -526,8 +527,9 @@ static void threaded_lazy_init_name_hash( if (k_start > istate->cache_nr) k_start = istate->cache_nr; td_dir_t->k_end = k_start; - if (pthread_create(&td_dir_t->pthread, NULL, lazy_dir_thread_proc, td_dir_t)) - die("unable to create lazy_dir_thread"); + err = pthread_create(&td_dir_t->pthread, NULL, lazy_dir_thread_proc, td_dir_t); + if (err) + die(_("unable to create lazy_dir thread: %s"), strerror(err)); } for (t = 0; t < lazy_nr_dir_threads; t++) { struct lazy_dir_thread_data *td_dir_t = td_dir + t; @@ -547,13 +549,15 @@ static void threaded_lazy_init_name_hash( */ td_name->istate = istate; td_name->lazy_entries = lazy_entries; - if (pthread_create(&td_name->pthread, NULL, lazy_name_thread_proc, td_name)) - die("unable to create lazy_name_thread"); + err = pthread_create(&td_name->pthread, NULL, lazy_name_thread_proc, td_name); + if (err) + die(_("unable to create lazy_name thread: %s"), strerror(err)); lazy_update_dir_ref_counts(istate, lazy_entries); - if (pthread_join(td_name->pthread, NULL)) - die("unable to join lazy_name_thread"); + err = pthread_join(td_name->pthread, NULL); + if (err) + die(_("unable to join lazy_name thread: %s"), strerror(err)); cleanup_dir_mutex(); diff --git a/preload-index.c b/preload-index.c index 0e24886aca..ddca1c216e 100644 --- a/preload-index.c +++ b/preload-index.c @@ -121,6 +121,8 @@ static void preload_index(struct index_state *index, for (i = 0; i < threads; i++) { struct thread_data *p = data+i; + int err; + p->index = index; if (pathspec) copy_pathspec(&p->pathspec, pathspec); @@ -129,8 +131,10 @@ static void preload_index(struct index_state *index, if (pd.progress) p->progress = &pd; offset += work; - if (pthread_create(&p->pthread, NULL, preload_thread, p)) - die("unable to create threaded lstat"); + err = pthread_create(&p->pthread, NULL, preload_thread, p); + + if (err) + die(_("unable to create threaded lstat: %s"), strerror(err)); } for (i = 0; i < threads; i++) { struct thread_data *p = data+i; diff --git a/run-command.c b/run-command.c index 84b883c213..26154ba257 100644 --- a/run-command.c +++ b/run-command.c @@ -1213,7 +1213,7 @@ int start_async(struct async *async) { int err = pthread_create(&async->tid, NULL, run_thread, async); if (err) { - error_errno("cannot create thread"); + error(_("cannot create async thread: %s"), strerror(err)); goto error; } } From patchwork Sat Oct 27 17:30:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10658419 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 960BC14DE for ; Sat, 27 Oct 2018 17:30:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 806FD2B007 for ; Sat, 27 Oct 2018 17:30:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 745152B011; Sat, 27 Oct 2018 17:30:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26B792B007 for ; Sat, 27 Oct 2018 17:30:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728946AbeJ1CML (ORCPT ); Sat, 27 Oct 2018 22:12:11 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:39232 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728610AbeJ1CMK (ORCPT ); Sat, 27 Oct 2018 22:12:10 -0400 Received: by mail-lj1-f196.google.com with SMTP id a28-v6so989234ljd.6 for ; Sat, 27 Oct 2018 10:30:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=t07LjXaIVGSwXKRFYZianmEQvgudAPAVe9JpwwNL98U=; b=V2Q/WkjR7zExT03WuU/vjr8xmU/hjvmeb7QQM2E1sOUCjQsIdzWfEjMHY/3EgyL6eH vQpsd8KZZvgRBfhs9bmAO84/HdvUP/o8EUdfoKOb1eLBPP+nAN0UmoYIItTARJC7kLJw /xt2E1KO6iQKzM+43DskUgFDDh2BT5X7/2Wo1gOK4kOOh5QP245xqzG3LDEtwxCr+5JK 6CYu+4QgihFa3N2ft4G7UsC0Q3/fcHmKt8rLji509fwhHgljECZVHmiM0mUgVnt2vc3N BZyxpCTLWThfPw84tyYwXxnDa4k40ymOwbQYbQcphY+fqCSByyDrb3h2AL/hbiuoQckV Ljng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=t07LjXaIVGSwXKRFYZianmEQvgudAPAVe9JpwwNL98U=; b=oORy21Tjp/a3V+cokyYqnfiVDKj+5jcD1ndjA3tGp0J4Y7XIG8V3tGyeO1sWXHp70S zO05y3wQRAvGaDYbtbJ9qON1WzcKeD4g9YNtfPoFwTuu+3HUSkSpZ03VO0IHFWc0by7i hodPle5biFzpgRMUrXas6bp68YpyBJghpE/gTgFC4TX1PRACqqG2FyRF5aQ+RbMGruop 6MgyDoWyTuXKn2tkvCML6+QJJIvpS7KiyTwFXZ/W5UqIwR+w5aYzr4zw7Fv3oSHEKEI0 Qllwa/LLzEuctGyTY49htUddAtF7Tt3cSZWVp+gZBBAb9BfACTh/l4KJT11BiDYDp3Xa kiHg== X-Gm-Message-State: AGRZ1gKxmGZGNhWqjc+ruzgScole0Rde5lPIvlpQTod3keYHj2MJVuSr hRKfZtyOVv548r/JUyOqxkvOiWfn X-Google-Smtp-Source: AJdET5ejd30732ImYKOrqT1BxWtk5XfClcVtAYgbeej58vFgfx/o1mVzMdzbC2uVMjxjKuZ3TAFOWw== X-Received: by 2002:a2e:458b:: with SMTP id s133-v6mr5759635lja.60.1540661428354; Sat, 27 Oct 2018 10:30:28 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id i185-v6sm2333517lfg.89.2018.10.27.10.30.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 10:30:27 -0700 (PDT) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: git@vger.kernel.org, gitster@pobox.com, peartben@gmail.com, peff@peff.net Subject: [PATCH v2 10/10] read-cache.c: initialize copy_len to shut up gcc 8 Date: Sat, 27 Oct 2018 19:30:08 +0200 Message-Id: <20181027173008.18852-11-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.647.g708186aaf9 In-Reply-To: <20181027173008.18852-1-pclouds@gmail.com> References: <20181027071003.1347-1-pclouds@gmail.com> <20181027173008.18852-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It was reported that when building with NO_PTHREADS=1, -Wmaybe-uninitialized is triggered. Just initialize the variable from the beginning to shut the compiler up (because this warning is enabled in config.dev) Signed-off-by: Nguyễn Thái Ngọc Duy --- read-cache.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/read-cache.c b/read-cache.c index ba870bc3fd..4307b9a7bf 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1746,7 +1746,7 @@ static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool, size_t len; const char *name; unsigned int flags; - size_t copy_len; + size_t copy_len = 0; /* * Adjacent cache entries tend to share the leading paths, so it makes * sense to only store the differences in later entries. In the v4 @@ -1786,8 +1786,6 @@ static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool, die(_("malformed name field in the index, near path '%s'"), previous_ce->name); copy_len = previous_len - strip_len; - } else { - copy_len = 0; } name = (const char *)cp; }