From patchwork Sat Nov 3 08:48:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10666553 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 77AAB17D5 for ; Sat, 3 Nov 2018 08:49:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B3272AC73 for ; Sat, 3 Nov 2018 08:49:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E5CC2AC75; Sat, 3 Nov 2018 08:49:07 +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 D52542AC6D for ; Sat, 3 Nov 2018 08:49:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726711AbeKCR7l (ORCPT ); Sat, 3 Nov 2018 13:59:41 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:37262 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726316AbeKCR7k (ORCPT ); Sat, 3 Nov 2018 13:59:40 -0400 Received: by mail-lj1-f195.google.com with SMTP id c4-v6so3738288lja.4 for ; Sat, 03 Nov 2018 01:49:03 -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=LOrJk/bklnW/yeksfRirv+6A+Y2dqd3zhyRXgtJR194=; b=spuWBae+0LY+syBXMEDfYu4aFt63jRCHCovA3HPsvkY4kspG9WwkLJEs5oU8nUFHEH YNgl60xJU134xNTYq4yaagV4o0OZ4lbsn6ea9aqoXPRUHKHZjUFYvnFllyMPb6jbIdm+ fzPkB7pvX6i+IWtWneRj/FnIi6pU0fM7o6gUOP5tNv9E7Ps//9G59VcyC1wnsFLvXvuB lM5fjIV0YkqrKGUb7v6lWP5STp2bSgOXhzwTTUwC05N4dDLtEhFYYUOL9PXjAnBBe7px Ax4oi89l6T0ZOppNPGKECfYlujfTNFfNMyk91Ne4e6VnMQTQKKencdgZTTUBPsKXiMV8 4IRA== 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=LOrJk/bklnW/yeksfRirv+6A+Y2dqd3zhyRXgtJR194=; b=apYKFI2+zG4SnLM45E01ll8AGOlPJcp4YAr2lJX1Uke+szomI3cNpGbeHPRxnHRdsK Thx0CbIItgyLwlHWmohYDF3Ff4ZS6gmm1AxBPepdZpEJSJUkQIFbLsZqaQj50rQ1PbZL 0022RaRAUufExuQ8ygLtBZdw4GVJlKwk8WTAba0fYF3oqU3xanNvkEBgUbGkbLmhI7LL slB++TZXPVqJLE43oh/U0r7zlPCEaAneFBRaGv/fXtOKjuA12itNIi8tQg5MHQglha0P D3hzavmXvvbtEzQUfJkWFkkiZ/FsI3byY8/kAm14XS2MkMU7G1mpG3Vfhnoyoa8OTgIx wo/w== X-Gm-Message-State: AGRZ1gLTR8IzwZCGS3NBVr5HE+fcKzShOGCg/fBpnWNJwqOxktleYYnr TdPbgEaz3Tsu5wyawsBlXZo= X-Google-Smtp-Source: AJdET5cnSZ180wPWNcBUJMhetGpFDH+8CFG9l1NRihRGQxMJjB70oTAKC7ryEiC65gIwMWqKhiBsgQ== X-Received: by 2002:a2e:145a:: with SMTP id 26-v6mr2090455lju.116.1541234942513; Sat, 03 Nov 2018 01:49:02 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id s191-v6sm657373lfe.17.2018.11.03.01.49.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Nov 2018 01:49:01 -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 v3 01/14] thread-utils: macros to unconditionally compile pthreads API Date: Sat, 3 Nov 2018 09:48:37 +0100 Message-Id: <20181103084850.9584-2-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.1005.gac84295441 In-Reply-To: <20181103084850.9584-1-pclouds@gmail.com> References: <20181027173008.18852-1-pclouds@gmail.com> <20181103084850.9584-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 Nov 3 08:48:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10666557 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 B1958109C for ; Sat, 3 Nov 2018 08:49:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC9FE2AC69 for ; Sat, 3 Nov 2018 08:49:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A119D2AC75; Sat, 3 Nov 2018 08:49:08 +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 593362AC69 for ; Sat, 3 Nov 2018 08:49:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726770AbeKCR7m (ORCPT ); Sat, 3 Nov 2018 13:59:42 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:37264 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726550AbeKCR7l (ORCPT ); Sat, 3 Nov 2018 13:59:41 -0400 Received: by mail-lj1-f194.google.com with SMTP id c4-v6so3738330lja.4 for ; Sat, 03 Nov 2018 01:49:04 -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=mEvviRJvKR2A2kQsNmxIWhLTy4AD0vSBWn5dZRTicao=; b=uUh1IqD0+iYKMs28e3GSnFtNrFME+p62ifrw2rfmLzjC62FOVGwQIjcW5aceAWpTIr F5WwnhdZvbXXctZBm6bXmkDkRzDmnXda3id3KNWXRc1TPZ9OHcnvyxs1Cql7xAMOjvZH JBWENmPLjwJEz5nrqJG1ibhkEwroXud+RbnKka3CovhT5vxWd1Kry51FD/0x3EmuL+wJ GgWxOrP1Hx/fcKRyLk2q+pVdyYmeNakU/IEd6tLiRjuWfHaB+dvYbiCug9FbFSfnIzX7 5tljrx7wrbBLCDt8wKvFUfViFyCADrt+68vd1SatAlvfYQTgdVrYcQ2u9ZZsaBAcJDZn +I9g== 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=mEvviRJvKR2A2kQsNmxIWhLTy4AD0vSBWn5dZRTicao=; b=OKhVY0J3rGcX7t8LE3kmRscNxcn2HmSXctB8RVE7ACKpCsC3PwMW0iyp/ZuVbHR5d4 Ay7xPawrRH56CktwHNJgL68BeMnHV3vpsF5NrPfMU8XEGj8AoCCkoOtbPfGXX0RpEvuT U6yT7YTJHxLn4ONZaq9cziU+j1TMqSErsLK/2xg4aF5VJnxMlgAVzFKG+xg0mPUX+Lop hzDRz2p/8P5TA74pCuDXiwpsWmUq4su/yD8ws6mrAPVCvxH8e0tNKx6a4xGf8cyBP4FQ tV6P0+gBXHeOejX2CIZbwLElN/tdsTvxzOav20tCw/0UXYniZroxUB6oslDFjfV6uG4b KgGA== X-Gm-Message-State: AGRZ1gIDeKDts7oIhtwpAPfJ6MbWApuMY3Us4z5PrUuba2CJGZ+LPmYU yJqPMszbCV7zfmrTCzjJfgA= X-Google-Smtp-Source: AJdET5e1vpLKaeXWbgKF5Ir/5zgd8VcUC8BNmmT6tjAT0xOpYjhGQEHPc9kmRERSncYL3k5PCil92w== X-Received: by 2002:a2e:7217:: with SMTP id n23-v6mr8316220ljc.71.1541234943694; Sat, 03 Nov 2018 01:49:03 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id s191-v6sm657373lfe.17.2018.11.03.01.49.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Nov 2018 01:49:02 -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 v3 02/14] run-command.h: include thread-utils.h instead of pthread.h Date: Sat, 3 Nov 2018 09:48:38 +0100 Message-Id: <20181103084850.9584-3-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.1005.gac84295441 In-Reply-To: <20181103084850.9584-1-pclouds@gmail.com> References: <20181027173008.18852-1-pclouds@gmail.com> <20181103084850.9584-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 run-command.c may use threads for its async support. But instead of including pthread.h directly, let's include thread-utils.h. run-command.c probably never needs the dummy bits in thread-utils.h when NO_PTHREADS is defined. But this makes sure we have consistent HAVE_THREADS behavior everywhere. From now on outside compat/, thread-utils.h is the only place that includes pthread.h Signed-off-by: Nguyễn Thái Ngọc Duy --- run-command.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/run-command.h b/run-command.h index 3932420ec8..9b7f38202c 100644 --- a/run-command.h +++ b/run-command.h @@ -1,9 +1,7 @@ #ifndef RUN_COMMAND_H #define RUN_COMMAND_H -#ifndef NO_PTHREADS -#include -#endif +#include "thread-utils.h" #include "argv-array.h" From patchwork Sat Nov 3 08:48:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10666559 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 DFCEC17DB for ; Sat, 3 Nov 2018 08:49:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D98D52AC69 for ; Sat, 3 Nov 2018 08:49:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE1D42AC73; Sat, 3 Nov 2018 08:49:08 +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 7A23E2AC6D for ; Sat, 3 Nov 2018 08:49:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726985AbeKCR7m (ORCPT ); Sat, 3 Nov 2018 13:59:42 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:39843 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726290AbeKCR7m (ORCPT ); Sat, 3 Nov 2018 13:59:42 -0400 Received: by mail-lj1-f193.google.com with SMTP id t9-v6so532222ljh.6 for ; Sat, 03 Nov 2018 01:49:05 -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=7ewvVqGtNQTgW7o15Xejp+IrBT4QbCBPgLeCwuYv68M=; b=PuWMrjzzUaK/2aeeTFKyQZN/iQ5c2X3grP4+Zm+d80rexXJ5tsPrhap03CvyuYnWgC Q6s13EJfgYDTFIRvr7kG6l2+JQO2Xaz8bVqBp9hf2EFnOpyW0CIUnrPPN89M3/W28mA4 c346BwnfUhOFmfkgDn1YSuwDzMxWHu2GZsywoFodI6Uin16X0b+1mBBszBO4ODosvcs7 fPrFi6fzDxgvTrvGLbpeDEoddQY4CVIp+dtECo6kKV1Y/rfiH3Nqsu0oQZOWwj+kn2GW RBXaREdln391OOjGC/I23Lxg4PPCJgG7TzdsPUnpGz2lFJ8hHKgnv04aCxdCHmI3dv4L gZKA== 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=7ewvVqGtNQTgW7o15Xejp+IrBT4QbCBPgLeCwuYv68M=; b=s5JV9jtHRQx3c5/pQfMG47RZpIpR3nMiHULLTh0KlvWGFw9WxHxa/RjUG5FSnMlYNO ozaWDsNebCcLwZeo25f+g4MWjZI6lguNUViKzf0v4eCNbudI1PB6PtqXW5coFpwIlNFF iKzF1M8aauKwcrbI7vPM7K6Ozsg6EKMTRLd8qXOEPJHU0vZVBZ/YMMyJ7WeYjpo7GbEp RLYrICCok37ap5Y59D5xc4uW7fJX5+vBLXhZ9uvnPMBGOJxwcTKBY9+7J/CLE0EVSBl8 Xa30IQWMPXonVu/NSKCx1b5fXgMZLG0OQRu3aAYru4krcr511KarvX8pF4NfPlQXKRm4 FF2Q== X-Gm-Message-State: AGRZ1gLNPUluCW+5cfSRmRM3F3WSA13kF92qNIaBSQfDCpetApSxy3BI MqBF80dyV9bwdZpmVP4KSqA= X-Google-Smtp-Source: AJdET5c+3FYxyO2BCXUug/oWEojg+xuBtBG+QN7ZG5U/IFy0lN/IAanCScsYebh7eHkamD4RwVy59g== X-Received: by 2002:a2e:2a46:: with SMTP id q67-v6mr2988840ljq.38.1541234944695; Sat, 03 Nov 2018 01:49:04 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id s191-v6sm657373lfe.17.2018.11.03.01.49.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Nov 2018 01:49:04 -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 v3 03/14] send-pack.c: move async's #ifdef NO_PTHREADS back to run-command.c Date: Sat, 3 Nov 2018 09:48:39 +0100 Message-Id: <20181103084850.9584-4-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.1005.gac84295441 In-Reply-To: <20181103084850.9584-1-pclouds@gmail.com> References: <20181027173008.18852-1-pclouds@gmail.com> <20181103084850.9584-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 On systems that do not support multithread, start_async() is implemented with fork(). This implementation details unfortunately leak out at least in send-pack.c [1]. To keep the code base clean of NO_PTHREADS, move the this #ifdef back to run-command.c. The new wrapper function async_with_fork() at least helps suggest that this special "close()" is related to async in fork mode. [1] 09c9957cf7 (send-pack: avoid deadlock when pack-object dies early - 2011-04-25) Signed-off-by: Nguyễn Thái Ngọc Duy --- run-command.c | 9 +++++++++ run-command.h | 1 + send-pack.c | 5 ++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/run-command.c b/run-command.c index 84b883c213..3c3b8814df 100644 --- a/run-command.c +++ b/run-command.c @@ -1246,6 +1246,15 @@ int finish_async(struct async *async) #endif } +int async_with_fork(void) +{ +#ifdef NO_PTHREADS + return 1; +#else + return 0; +#endif +} + const char *find_hook(const char *name) { static struct strbuf path = STRBUF_INIT; diff --git a/run-command.h b/run-command.h index 9b7f38202c..68f5369fc2 100644 --- a/run-command.h +++ b/run-command.h @@ -141,6 +141,7 @@ struct async { int start_async(struct async *async); int finish_async(struct async *async); int in_async(void); +int async_with_fork(void); void check_pipe(int err); /** diff --git a/send-pack.c b/send-pack.c index e920ca57df..f692686770 100644 --- a/send-pack.c +++ b/send-pack.c @@ -203,9 +203,8 @@ static int receive_status(int in, struct ref *refs) static int sideband_demux(int in, int out, void *data) { int *fd = data, ret; -#ifdef NO_PTHREADS - close(fd[1]); -#endif + if (async_with_fork()) + close(fd[1]); ret = recv_sideband("send-pack", fd[0], out); close(out); return ret; From patchwork Sat Nov 3 08:48:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10666561 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 06E2F17D5 for ; Sat, 3 Nov 2018 08:49:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 025B92AC73 for ; Sat, 3 Nov 2018 08:49:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB13F2AC75; Sat, 3 Nov 2018 08:49:10 +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 77A2C2AC69 for ; Sat, 3 Nov 2018 08:49:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727602AbeKCR7o (ORCPT ); Sat, 3 Nov 2018 13:59:44 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:42244 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726550AbeKCR7o (ORCPT ); Sat, 3 Nov 2018 13:59:44 -0400 Received: by mail-lf1-f65.google.com with SMTP id q6-v6so2859087lfh.9 for ; Sat, 03 Nov 2018 01:49:06 -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=ENhCg1Og5kPXga7lxyDMAm+nbsh1TOY+M2fh2RfDQIM=; b=i6RQaoRlZF66BEUL8fccDGxNJckXzQ7fnj0Gy60UaZv6d1Zlrjv2NlgHYz5jmjs859 Gq7FAx7BPYqzuW3Vyf7VYTOmwfkIcHu2aJWTqvvdks6XDWoortxkO1nOM2jtWiaMz4+o fdUNjJFdqOSKi14BksS7f8GLC9zJePyLtXRV1fVn6IFthJN+dNHKG1Kpac4Y1N7QPpqd XiGk/a9J14dFelSyXEv2QbTAnTNGT6fkJxGDD8EH9INhjTNtwl+0PFeHkQjqIbA90I7n NqTXNNHTKMJGgqpFBzS69AnazV4VSFrWkpM4xD4mo3FxaxfjKfXAZVNU7xnjHDJWaFYN Seog== 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=ENhCg1Og5kPXga7lxyDMAm+nbsh1TOY+M2fh2RfDQIM=; b=Yj8Dr8KWOHGDybK01IvSseidL19OKdZx54WLki4yder1UiilE4fhlmbjz8B51yoJCQ r+QkJOuJa0DGN93HjHmCoVH7O0YCfYXIR3OI0DDEZ2NqGuP9lOTVfVBEEBqu0N/RI5Uz JXFC256+It4Koojmd5J4QsGmuU4c5MOEzAH4zY2iuha1M8s0nhetWA9BM0i1rFxHF6jq DAcpfh9dJq5b1SOFj2NfGkNxSa6orFuh43VnDJaVKfCXH7F2rtpaCs1odnTLdpSw1yaH nIu/r5kqaq4qtf5CbEaJlqKHFu4dU3k3XphJ4Ry0OSo961yWAsWn7odNA6OiPnhtDUEr bDdw== X-Gm-Message-State: AGRZ1gL+9vKWZM/ChFxAIMl8ryRQ1J9zClYjdaGvgZ1thTJg82uiN7Eg 0noU5TzaRzqjC0ym1ooocQM= X-Google-Smtp-Source: AJdET5culwsu7ks7PBreJKixZuZZ8ffcI9WhRmYwFwNuiwOaMH+J3CsUa35JPF0viwUa9qgUgrVv5g== X-Received: by 2002:a19:d78c:: with SMTP id q12mr8270019lfi.27.1541234945847; Sat, 03 Nov 2018 01:49:05 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id s191-v6sm657373lfe.17.2018.11.03.01.49.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Nov 2018 01:49:05 -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 v3 04/14] index-pack: remove #ifdef NO_PTHREADS Date: Sat, 3 Nov 2018 09:48:40 +0100 Message-Id: <20181103084850.9584-5-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.1005.gac84295441 In-Reply-To: <20181103084850.9584-1-pclouds@gmail.com> References: <20181027173008.18852-1-pclouds@gmail.com> <20181103084850.9584-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/index-pack.c | 63 ++++++++++---------------------------------- 1 file changed, 14 insertions(+), 49 deletions(-) diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 2004e25da2..682042579b 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -42,9 +42,7 @@ struct base_data { }; struct thread_local { -#ifndef NO_PTHREADS pthread_t thread; -#endif struct base_data *base_cache; size_t base_cache_used; int pack_fd; @@ -98,8 +96,6 @@ static uint32_t input_crc32; static int input_fd, output_fd; static const char *curr_pack; -#ifndef NO_PTHREADS - static struct thread_local *thread_data; static int nr_dispatched; static int threads_active; @@ -179,26 +175,6 @@ static void cleanup_thread(void) free(thread_data); } -#else - -#define read_lock() -#define read_unlock() - -#define counter_lock() -#define counter_unlock() - -#define work_lock() -#define work_unlock() - -#define deepest_delta_lock() -#define deepest_delta_unlock() - -#define type_cas_lock() -#define type_cas_unlock() - -#endif - - static int mark_link(struct object *obj, int type, void *data, struct fsck_options *options) { if (!obj) @@ -364,22 +340,20 @@ static NORETURN void bad_object(off_t offset, const char *format, ...) static inline struct thread_local *get_thread_data(void) { -#ifndef NO_PTHREADS - if (threads_active) - return pthread_getspecific(key); - assert(!threads_active && - "This should only be reached when all threads are gone"); -#endif + if (HAVE_THREADS) { + if (threads_active) + return pthread_getspecific(key); + assert(!threads_active && + "This should only be reached when all threads are gone"); + } return ¬hread_data; } -#ifndef NO_PTHREADS static void set_thread_data(struct thread_local *data) { if (threads_active) pthread_setspecific(key, data); } -#endif static struct base_data *alloc_base_data(void) { @@ -1092,7 +1066,6 @@ static void resolve_base(struct object_entry *obj) find_unresolved_deltas(base_obj); } -#ifndef NO_PTHREADS static void *threaded_second_pass(void *data) { set_thread_data(data); @@ -1116,7 +1089,6 @@ static void *threaded_second_pass(void *data) } return NULL; } -#endif /* * First pass: @@ -1213,7 +1185,6 @@ static void resolve_deltas(void) progress = start_progress(_("Resolving deltas"), nr_ref_deltas + nr_ofs_deltas); -#ifndef NO_PTHREADS nr_dispatched = 0; if (nr_threads > 1 || getenv("GIT_FORCE_THREADS")) { init_thread(); @@ -1229,7 +1200,6 @@ static void resolve_deltas(void) cleanup_thread(); return; } -#endif for (i = 0; i < nr_objects; i++) { struct object_entry *obj = &objects[i]; @@ -1531,11 +1501,10 @@ static int git_index_pack_config(const char *k, const char *v, void *cb) if (nr_threads < 0) die(_("invalid number of threads specified (%d)"), nr_threads); -#ifdef NO_PTHREADS - if (nr_threads != 1) + if (!HAVE_THREADS && nr_threads != 1) { warning(_("no threads support, ignoring %s"), k); - nr_threads = 1; -#endif + nr_threads = 1; + } return 0; } return git_default_config(k, v, cb); @@ -1723,12 +1692,10 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) nr_threads = strtoul(arg+10, &end, 0); if (!arg[10] || *end || nr_threads < 0) usage(index_pack_usage); -#ifdef NO_PTHREADS - if (nr_threads != 1) - warning(_("no threads support, " - "ignoring %s"), arg); - nr_threads = 1; -#endif + if (!HAVE_THREADS && nr_threads != 1) { + warning(_("no threads support, ignoring %s"), arg); + nr_threads = 1; + } } else if (starts_with(arg, "--pack_header=")) { struct pack_header *hdr; char *c; @@ -1791,14 +1758,12 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) if (strict) opts.flags |= WRITE_IDX_STRICT; -#ifndef NO_PTHREADS - if (!nr_threads) { + if (HAVE_THREADS && !nr_threads) { nr_threads = online_cpus(); /* An experiment showed that more threads does not mean faster */ if (nr_threads > 3) nr_threads = 3; } -#endif curr_pack = open_pack_file(pack_name); parse_pack_header(); From patchwork Sat Nov 3 08:48:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10666563 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 20D8B17DB for ; Sat, 3 Nov 2018 08:49:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B95B2AC69 for ; Sat, 3 Nov 2018 08:49:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F72E2AC6D; Sat, 3 Nov 2018 08:49:11 +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 B560F2AC6D for ; Sat, 3 Nov 2018 08:49:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727644AbeKCR7p (ORCPT ); Sat, 3 Nov 2018 13:59:45 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:45170 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726290AbeKCR7o (ORCPT ); Sat, 3 Nov 2018 13:59:44 -0400 Received: by mail-lj1-f196.google.com with SMTP id j4-v6so3700126ljc.12 for ; Sat, 03 Nov 2018 01:49:07 -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=GdcFxYhrvVHOOkVUtpi6izgL786iaIL3UhH8k7T+OQU=; b=O8ympxlZRUYwkihRGgdCMH43v3Ua87/BsIpjIYJ6yLbQcBC4WsP2uc0GrrQWSVgzg+ xhj0DRdTslOGOuDzff4w3Mv8m3xk3e0lkcXLtXIp5IQH2kgJQlG9ZvluMG1TK8SJRfZg dGWbX+cicpDPM5JUx3Cy1i2s4WKfivSTg0dePPuX/uKBe5JdnSpxcmaTe4CRSKdmP3s+ ntXOtLhabP7mKbDO2hz3pIJDCeKeXvaIFwO5oeGCUKwzfX4uLwx4QNlgzBensCxl1GoW FpnIQoX1RyTJa5FwnQz0OeYIM2cvL9AypKHlvepsgEjJFtIkU5OPz77vMWT8ewjruQU/ KJsA== 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=GdcFxYhrvVHOOkVUtpi6izgL786iaIL3UhH8k7T+OQU=; b=O7GUniTCQxrjlpNF4i2jEXpNLC/JOD/nho+Vtv0Urho16/G7AyZm+joosGv/EL9dWi RaDUQG51K4xRdOHqXhDVYIiG4G/KHwF6QKaEdp13IL1uFLLOgri9ZDKYf78x1BqtDTgT HDDyYSWOT2D8kJt+1Y3wgsidKVhHXJZWVlBBXJ+YhGgLg9CIpkodSBTTE6hK3E6Gwqfc EbvYGbCyBliPIKsOXNkRUlZ8jRG5FYurDhAYHhPhg3o2TFA3W+Vv5YA6Jr85lfPOeyG8 fOTS9GjUc4BzvlW40HgIK5u7UHt7fJayciQqNA3gfInc4n/Fyhrz9/7JlqB5TA4gFMMw cYHw== X-Gm-Message-State: AGRZ1gLml/ENHow1SJmk+RsKTpIhl2wLlNBeI32XLdx8nKcBlOzeAQSA wO38tElDHSP+uKaaQ0FzuHQ= X-Google-Smtp-Source: AJdET5coVIbRvXmmN46BWocgqK/YAaGPh0t+xCyJ+BAPIOXQI27fYAU0g+izebB/iPUyuqoHKdcKag== X-Received: by 2002:a2e:9059:: with SMTP id n25-v6mr6616967ljg.155.1541234947061; Sat, 03 Nov 2018 01:49:07 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id s191-v6sm657373lfe.17.2018.11.03.01.49.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Nov 2018 01:49:06 -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 v3 05/14] name-hash.c: remove #ifdef NO_PTHREADS Date: Sat, 3 Nov 2018 09:48:41 +0100 Message-Id: <20181103084850.9584-6-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.1005.gac84295441 In-Reply-To: <20181103084850.9584-1-pclouds@gmail.com> References: <20181027173008.18852-1-pclouds@gmail.com> <20181103084850.9584-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 Nov 3 08:48:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10666565 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 0DDF6109C for ; Sat, 3 Nov 2018 08:49:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 085222AC69 for ; Sat, 3 Nov 2018 08:49:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0F142AC73; Sat, 3 Nov 2018 08:49:12 +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 99F9B2AC69 for ; Sat, 3 Nov 2018 08:49:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727689AbeKCR7q (ORCPT ); Sat, 3 Nov 2018 13:59:46 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:42829 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726550AbeKCR7q (ORCPT ); Sat, 3 Nov 2018 13:59:46 -0400 Received: by mail-lj1-f195.google.com with SMTP id f3-v6so3716215ljk.9 for ; Sat, 03 Nov 2018 01:49:09 -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=HIuouUZtGpLfggu6yazomKtoLyzAYkfMX0xVLEOsNn4=; b=Kkvv1EKgq7HKL2cS3zO25Ck269b2pvlt4qZYdrXP71Vzg7hElkCO0uOhujAD7LTBL0 BRLh1YZi3TYymjg74QSmR9PwQ1SRTBsqvR7+0JzbTjHWSCNViY1n+mgFZNg8KmfbcyLA h/SI4AwANtiqrNikqvySNoTc71vCNvOmMVj8W2YMXiECniZQJkAtkyq8EXw0HH3cibse miVRLfu+JqGNkzvUF+LiFJuRQIv1njCgOS/iaIxLCzYR1v0LzXAglZNvxG0HjzaoNX+I 3VfNdS82oxjK1gGQM7q4Z5E42Cbec8vE3eMpRCfnSASDDCYTYSOW+AYfiT+HYdLsJNpn /Z9w== 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=HIuouUZtGpLfggu6yazomKtoLyzAYkfMX0xVLEOsNn4=; b=N7UIpOwp8ArFMrQiGYWv/oNxlre/HTu2t25iQ5h1Yy/vNX0yTbKhGLZy/BBrczfPit 7hcwzSOTyqn4aExaNCIaYIzm2AoNB4ETz0D/mAHE6vFpD2BDr/i7zZdAIHpv2s8dF3xk X1BP5B14d7oyAZpGN4y5gdROQ1c49rrMNuyY0Evdonpt+HGSIM0wgmRoNw84HPELf/lb SqXd6FXt+LeVWT6DbzOsVtXzG/DxuyUodvgZzyrLlMbDvPa39mwUU4uEN5P2NYYnWZB3 /gJFG0iVrBJVB40mb2FT7PcpoREu8Whntu+7NTTriZUO1AFyKHQQ31bbdLKrI094gvEy VEOg== X-Gm-Message-State: AGRZ1gJJdYxQHxZHOHlOtShDLkqYl1mEQjszoI0A78PYhuLrPATJgNhd sqxE50XnvAEaWXx3KSGL2W4= X-Google-Smtp-Source: AJdET5cC3ri/m40j1HO0DTvnUh7HoGjApSFjUC36Qw7bybNKIk3OZrxrB7Uef/yrG6uG8346RV8kAg== X-Received: by 2002:a2e:87da:: with SMTP id v26-v6mr10415637ljj.13.1541234948284; Sat, 03 Nov 2018 01:49:08 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id s191-v6sm657373lfe.17.2018.11.03.01.49.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Nov 2018 01:49:07 -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 v3 06/14] attr.c: remove #ifdef NO_PTHREADS Date: Sat, 3 Nov 2018 09:48:42 +0100 Message-Id: <20181103084850.9584-7-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.1005.gac84295441 In-Reply-To: <20181103084850.9584-1-pclouds@gmail.com> References: <20181027173008.18852-1-pclouds@gmail.com> <20181103084850.9584-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 Nov 3 08:48:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10666567 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 CA25B17D5 for ; Sat, 3 Nov 2018 08:49:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C448C2AC69 for ; Sat, 3 Nov 2018 08:49:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B8DAD2AC73; Sat, 3 Nov 2018 08:49:13 +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 2D5DA2AC69 for ; Sat, 3 Nov 2018 08:49:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727719AbeKCR7r (ORCPT ); Sat, 3 Nov 2018 13:59:47 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:35901 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726290AbeKCR7r (ORCPT ); Sat, 3 Nov 2018 13:59:47 -0400 Received: by mail-lf1-f66.google.com with SMTP id h192so2866812lfg.3 for ; Sat, 03 Nov 2018 01:49:10 -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=jyWAAjGjlEN1T+6JeoB0reBdgnJUZzl736tZAXd5FJk=; b=OH3wRy/VEZAkaoTqnXv8DKdyAx3c0hbSbUrHUnQN3oGK1liDLlxRyodEDcRD5Fw3MH X1NvGN+QiuVCEDSHCmGotfZjepL0YuduJj9uXRe1TIqjg0LB7OirUe7yYhkTmcD4eBHp alGNteuKZ0nNZO3qpdlBilSrK6XHNljLDIOMW+ueMHhU+i94MzVtXRMZjKZDYAw90rSi 4strUy7y/PbIlgYQTPbRGbPTYdy1le0V6mes5XA6g7y+oQeOvL/LZScN9entYOOpjYII lMV81dByc0nekNk8j+AfIB5h+HS8GX+9g2lsGSY+JlQhlMRVPEg8G9WOkJIpyhHPVNyQ rtlA== 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=jyWAAjGjlEN1T+6JeoB0reBdgnJUZzl736tZAXd5FJk=; b=K5qa6jjNOCTYs/7MVTFg6pIHss70pWOcz01Hoie2UNhndi4ZxjVmCab+7ZgWFzYN7G aLXn6kzYA2vUw3XIrgi9uFHwvLCnze1jdTZdOTZ4bR/wFd17t5nuxtM8JJbGIoXT7w08 u2V3wzs7JxRqBefnBT0vomjrqJbL94/cpAvcPr0dtc8U3FohJtJGETNLWe/5mvmb3H4y PjnmIss4KrRHZwZd9ZJWKpoNhPL6CLOX50U72Kh2NTh8uDOun/xmYeam/3l5E44bVYd7 WgDGtOr2dPLqHFutFb+P7ehIOYHWEBQpg4XqHbg/vQ7ctkE0w7QtEBGVX/k0atT0lEI7 wYXA== X-Gm-Message-State: AGRZ1gL9XtudSK3qECW0oxOTHe0K3aWp9w9A1OJTpH9lsgx400Ka38Qi LKQr+5vywIsKJlzGEtG2eoo= X-Google-Smtp-Source: AJdET5cS2U9PFBiIzjwCTPQTwGQ47UNqRA2cBZyUXfj4NrUm04OqlhxobsaRgw/kLh/CWhl1liTn7w== X-Received: by 2002:a19:2203:: with SMTP id i3mr9217346lfi.2.1541234949619; Sat, 03 Nov 2018 01:49:09 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id s191-v6sm657373lfe.17.2018.11.03.01.49.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Nov 2018 01:49:08 -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 v3 07/14] grep: remove #ifdef NO_PTHREADS Date: Sat, 3 Nov 2018 09:48:43 +0100 Message-Id: <20181103084850.9584-8-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.1005.gac84295441 In-Reply-To: <20181103084850.9584-1-pclouds@gmail.com> References: <20181027173008.18852-1-pclouds@gmail.com> <20181103084850.9584-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 This is a faithful conversion without attempting to improve anything. That comes later. 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 Nov 3 08:48:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10666571 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 3BD60109C for ; Sat, 3 Nov 2018 08:49:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36DA62AC69 for ; Sat, 3 Nov 2018 08:49:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B2C52AC79; Sat, 3 Nov 2018 08:49:17 +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 97F1A2AC69 for ; Sat, 3 Nov 2018 08:49:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727760AbeKCR7t (ORCPT ); Sat, 3 Nov 2018 13:59:49 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:45170 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726550AbeKCR7s (ORCPT ); Sat, 3 Nov 2018 13:59:48 -0400 Received: by mail-lj1-f195.google.com with SMTP id j4-v6so3700180ljc.12 for ; Sat, 03 Nov 2018 01:49:11 -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=aT/1Iyw/Y6Bb7szL7iGILMKcKxPK4N5wgY8m72IgqVY=; b=bRYGJMCqr7fko8CLpdNGGf9M/9uLyJQ7ACjujAFMorLgiA3v2SNFhK89NlQyD5EVS4 u1lzKUwBhuuCxd32N2ihIqXH/35WOrYUam8XsAAuCNBuAgfznnjO7qVpuqRCA7jlAueW OaLxcklc9GF/aJr7djYDaH8cmaSY+DPfUbZ+De99WguLo7w32LjHHyPLdOZvdNG7YZ3h kK2KwQIi7dXtH2jHzgPT/d64ZiYQ+cKCeBs/GWaP55KPVwwKAgXZe0AKevZWYHUJTUJu uPKdA9PP8/vtWaxsLIjlIUzyx6MoXr5+GdFhHEz5jC5IxrTv6HDh86bzCoGfcxCQGK4r NcnQ== 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=aT/1Iyw/Y6Bb7szL7iGILMKcKxPK4N5wgY8m72IgqVY=; b=flghB6b+oFKGQQvrsS4MaWQLgpAew331iADCuDyLUsFpI7bUpX6EjgKPvSnefZIqxu nk3c6gGGlDfb6dvT3Gg9Ku96G3WCx+0ZDrP1wG+EliRF2Gd1jiNbW93yjtwxjod76juU dbfVN12Z704kitNfWoyK+dlhkzAgQ3CSExqokUbDAyIuZhrqfEgRFuf8g4kHJNyUnK5o iUrDPUE0H8Bj1Ui4Fkuf2BuH4z5OyaMf+Z91YMsnPUUCdOfhtCXCrg2Ac4Oy7OwN1smY 4ViFNtIlk8TkLa4mgPIqNojOSF9mIEFFi/gsrA30YJHjcc6aMQGNi3Gb09pplbLsoBHw IODA== X-Gm-Message-State: AGRZ1gJOJCtepJ3ct1cu9FgsfonWpHFTsEF1x/RfFUHqjDSLh5BZZayq DpY7CnILmxoO1AIYUkC/6b0= X-Google-Smtp-Source: AJdET5clyiATPrpvoPtL+6vlh+Ky9IGKlcPgeC+VNk166mc8K4dATZ78vVzOJJzJtrqpjy+N8E0GYA== X-Received: by 2002:a2e:4a19:: with SMTP id x25-v6mr9380791lja.19.1541234950790; Sat, 03 Nov 2018 01:49:10 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id s191-v6sm657373lfe.17.2018.11.03.01.49.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Nov 2018 01:49:10 -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 v3 08/14] grep: clean up num_threads handling Date: Sat, 3 Nov 2018 09:48:44 +0100 Message-Id: <20181103084850.9584-9-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.1005.gac84295441 In-Reply-To: <20181103084850.9584-1-pclouds@gmail.com> References: <20181027173008.18852-1-pclouds@gmail.com> <20181103084850.9584-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 NO_PTHREADS is still used in this file, we have two separate code paths for thread and no thread support. The latter will always have num_threads remain zero while the former uses num_threads zero as "default number of threads". With recent changes blur the line between thread and no-thread support, this num_threads handling becomes a bit strange so let's redefine it like this: - num_threads == 0 means default number of threads and should become positive after all configuration and option parsing is done if multithread is supported. - num_threads <= 1 runs no threads. It does not matter if the platform supports threading or not. - num_threads > 1 will run multiple threads and is invalid if HAVE_THREADS is false. pthread API is only used in this case. PS. a new warning is also added when num_threads is forced back to one because a thread-incompatible option is specified. Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/grep.c | 58 +++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/builtin/grep.c b/builtin/grep.c index 6dd15dbaa2..de3f568cee 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -69,13 +69,11 @@ static pthread_mutex_t grep_mutex; static inline void grep_lock(void) { - assert(num_threads); pthread_mutex_lock(&grep_mutex); } static inline void grep_unlock(void) { - assert(num_threads); pthread_mutex_unlock(&grep_mutex); } @@ -234,7 +232,7 @@ static int wait_all(void) int i; if (!HAVE_THREADS) - return 0; + BUG("Never call this function unless you have started threads"); grep_lock(); all_work_added = 1; @@ -279,14 +277,14 @@ 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); - else if (!HAVE_THREADS && num_threads && num_threads != 1) { + else if (!HAVE_THREADS && num_threads > 1) { /* * TRANSLATORS: %s is the configuration * variable for tweaking threads, currently * grep.threads */ warning(_("no threads support, ignoring %s"), var); - num_threads = 0; + num_threads = 1; } } @@ -323,7 +321,7 @@ 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); - if (HAVE_THREADS && num_threads) { + if (num_threads > 1) { /* * add_work() copies gs and thus assumes ownership of * its fields, so do not call grep_source_clear() @@ -353,7 +351,7 @@ 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); - if (HAVE_THREADS && num_threads) { + if (num_threads > 1) { /* * add_work() copies gs and thus assumes ownership of * its fields, so do not call grep_source_clear() @@ -1025,36 +1023,34 @@ int cmd_grep(int argc, const char **argv, const char *prefix) pathspec.recursive = 1; pathspec.recurse_submodules = !!recurse_submodules; - 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; + if (list.nr || cached || show_in_pager) { + if (num_threads > 1) + warning(_("invalid option combination, ignoring --threads")); + num_threads = 1; + } else if (!HAVE_THREADS && num_threads > 1) { + warning(_("no threads support, ignoring --threads")); + num_threads = 1; + } else if (num_threads < 0) + die(_("invalid number of threads specified (%d)"), num_threads); + else if (num_threads == 0) + num_threads = HAVE_THREADS ? GREP_NUM_THREADS_DEFAULT : 1; + + if (num_threads > 1) { + if (!HAVE_THREADS) + BUG("Somebody got num_threads calculation wrong!"); + 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); } else { - if (num_threads) - warning(_("no threads support, ignoring --threads")); - num_threads = 0; - } - - if (!num_threads) /* * The compiled patterns on the main path are only * used when not using threading. Otherwise - * start_threads() below calls compile_grep_patterns() + * start_threads() above calls compile_grep_patterns() * for each thread. */ compile_grep_patterns(&opt); - - 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); } if (show_in_pager && (cached || list.nr)) @@ -1106,7 +1102,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix) hit = grep_objects(&opt, &pathspec, &list); } - if (num_threads) + if (num_threads > 1) hit |= wait_all(); if (hit && show_in_pager) run_pager(&opt, prefix); From patchwork Sat Nov 3 08:48:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10666569 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 B8DFC17D5 for ; Sat, 3 Nov 2018 08:49:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B278D2AC69 for ; Sat, 3 Nov 2018 08:49:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A6F7F2AC73; Sat, 3 Nov 2018 08:49:15 +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 5BCEB2AC69 for ; Sat, 3 Nov 2018 08:49:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727820AbeKCR7t (ORCPT ); Sat, 3 Nov 2018 13:59:49 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:41922 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726290AbeKCR7t (ORCPT ); Sat, 3 Nov 2018 13:59:49 -0400 Received: by mail-lf1-f66.google.com with SMTP id c16so2849750lfj.8 for ; Sat, 03 Nov 2018 01:49:12 -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=4DbyoW90a68bGDlCFgtB/W4/tJnrKo9zwC/US+jgSaA=; b=jVqFebAE+ZaGdjnHcl0EaLjt3pfK1dj03WXirHdX9MYGmKf4unMOCTBxHMBtnwX+jt RsrFOtid6MWgMwlxlDd2mt3/5sgTclBZA5z5wM0zIGdXvpKm6caNmYTaI4b1F6UoH8Ic YmT+4ehC+9hCOPC5Wdea+QJS8j3Fd9/zys4Ig2VnJRmr+Wdx7opgqqGay+BvsaaArZVZ YgU57LwDvTClJpYUZwBp8gcAW4xPaUU/rkp4wxr9IVqRHydgTG3q5sdiRCphXGxIhWbK U31Ozju2b6OA6lPM0Z+IRzQ9Mov/hPL/PghbMcwr19GNV6u5ODGS0/3ln0ULVk+wQvtE vdYQ== 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=4DbyoW90a68bGDlCFgtB/W4/tJnrKo9zwC/US+jgSaA=; b=plr6iarlyXaUJy3ldZZMwhKlmsp72TgaqKl+kH8u8X8/lZXQvSv5rfktfd/U5Sm5Zo XqtZVNx8gkp3df/qTdJTLgoDZRulzo0qp2CbEsptHnX385Vds+gHIlaYMVA/8OLMky8V mb7cjfDzwA0hy7M8CfcEoNsBQISU14yphgb+lNpHZ7kDGl6G7cop7rBJSvkBaFTCozIv ZYFEwsgg43rnmuYHgpjScs/RqlcLIf1HiBVIVHeJDj7Uifemi8GiQVpZIt8QmmOhZFeM VxENMLOsk/qvOJgnbndRdx83jeoLe8OnQHS4xekYRR+urDT2EnL6fWyKpUEOdc6HaIj+ 5lbw== X-Gm-Message-State: AGRZ1gJbSNGk3xFgb9V7s5npfRc6Ty/gf+Ok6lTQzo120XtpCpg9ltAn 5Tj+3ivduMPan5Fzze1C++6qO1Z4 X-Google-Smtp-Source: AJdET5cDgQAUAyLfMJB7rH2TRbuWVj/BdaTO66eqLPYaN98y1BLI0/7Kn3o2Doz0Rbotq78t+di1dw== X-Received: by 2002:a19:a84e:: with SMTP id r75mr8126974lfe.18.1541234952057; Sat, 03 Nov 2018 01:49:12 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id s191-v6sm657373lfe.17.2018.11.03.01.49.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Nov 2018 01:49:11 -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 v3 09/14] preload-index.c: remove #ifdef NO_PTHREADS Date: Sat, 3 Nov 2018 09:48:45 +0100 Message-Id: <20181103084850.9584-10-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.1005.gac84295441 In-Reply-To: <20181103084850.9584-1-pclouds@gmail.com> References: <20181027173008.18852-1-pclouds@gmail.com> <20181103084850.9584-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 Nov 3 08:48:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10666573 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 830E217DB for ; Sat, 3 Nov 2018 08:49:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D4012AC69 for ; Sat, 3 Nov 2018 08:49:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 70DB32AC89; Sat, 3 Nov 2018 08:49:17 +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 082192AC6D for ; Sat, 3 Nov 2018 08:49:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727864AbeKCR7v (ORCPT ); Sat, 3 Nov 2018 13:59:51 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:43432 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727732AbeKCR7v (ORCPT ); Sat, 3 Nov 2018 13:59:51 -0400 Received: by mail-lj1-f194.google.com with SMTP id g26-v6so3715707lja.10 for ; Sat, 03 Nov 2018 01:49:14 -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=VLQ9JxryHxaM8p03XiMFucrsrJ5I0K2B3viP+y2dPqo=; b=EYzDJRLjxmpOBBnCWqT3gbFIiAM7Azt27vnfSAQC4Y1/32jqXkXs6knyD1CFZEzgGJ nq5Gf4Xgj6NGC8jNhhae61TAfUeUnworXz4P0HbGBH4triw/us/FTLf6RGaZw6a39VWF Gci9VNAtgAi/pb0shFGwQjFdBJp+ikGfJo4FcgksgFnf7XPZni2O4uoXUmf9Scmhz+iW 684LFB9kqZY3qKUk42S+1z2mtt3jG52CDmx1yMa5oZSzhig1c2CAHIwewwSpW68sG1Yv tq2UG7YxD55jJkYRHK+/jH5/zAfP/MnUHmnBjQFMmszDzXwmMSPbsKOwrjStDO/xXJfX iZuA== 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=VLQ9JxryHxaM8p03XiMFucrsrJ5I0K2B3viP+y2dPqo=; b=bsGgmgQyNDTniMA/cFEJnP+RpBvD27UiMJMdQsWyVqA5ABppiWqu5fDjvCgQz8ad7o Yz1KSTIhVOXznbEQ+XciDXv1HdtAqmClr+zTRf8rRHboDpGEoow2MRhKHm3eGa07AZ/0 lMQUPV2Y3aUdmgRB2BSFYdz2zlaRLtxAMMON+MD+rcLl2nGRv5JcVCiQWewC2fVlt9ka BZZjo8GjIamF1KeY8PTfa83Ja+Ly5+iMhSTvEa8vBmBD/aADK3jUFJ8VSkwLqIh+eO1/ qy9ImRG70PlooBbrAunG9eHm84AICrgsG0N22yum1mtFS6hd9/wPypKAPA0aofCds773 Yq/A== X-Gm-Message-State: AGRZ1gJlqlhg2J50dO2L+QQ0QczHY6GQZwchgbLkJPIyTfFz8xBO+X6w uNDFvddgBxl8V9+WbgjLjp1MJNvp X-Google-Smtp-Source: AJdET5f1ob89DoK7gGxcxZuyqndG+PSUu9MqMs0BB34Ix9A36NxJl5l8+O6zHUJsD75Ja23bpVmJVw== X-Received: by 2002:a2e:908b:: with SMTP id l11-v6mr9493236ljg.150.1541234953327; Sat, 03 Nov 2018 01:49:13 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id s191-v6sm657373lfe.17.2018.11.03.01.49.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Nov 2018 01:49:12 -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 v3 10/14] pack-objects: remove #ifdef NO_PTHREADS Date: Sat, 3 Nov 2018 09:48:46 +0100 Message-Id: <20181103084850.9584-11-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.1005.gac84295441 In-Reply-To: <20181103084850.9584-1-pclouds@gmail.com> References: <20181027173008.18852-1-pclouds@gmail.com> <20181103084850.9584-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 Nov 3 08:48:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10666575 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 E327517D5 for ; Sat, 3 Nov 2018 08:49:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DDAEE2AC69 for ; Sat, 3 Nov 2018 08:49:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D20D72AC79; Sat, 3 Nov 2018 08:49:18 +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 58AC02AC69 for ; Sat, 3 Nov 2018 08:49:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727957AbeKCR7x (ORCPT ); Sat, 3 Nov 2018 13:59:53 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:40530 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726290AbeKCR7w (ORCPT ); Sat, 3 Nov 2018 13:59:52 -0400 Received: by mail-lf1-f66.google.com with SMTP id n3-v6so2853414lfe.7 for ; Sat, 03 Nov 2018 01:49:15 -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=d9Zjbemurtm/J4rPnSra2wxipnG86UpHMBL/OMHW9IY=; b=AUYjt/zZIUQoB9thL9J01+T2HpEsU4LO7ISZzmYEhSAp//CkLWNPoLQLZhpcv2mxZX c0xpKp+F4B67+EhxaBhkPz6iAB1F6wd1hSu15mijKxBvzN9E1rqRVNn4fZXFFv97AoAc I8HB8eHd0nrTES9bvyPePLP5MzV8Pm5SD8jDVfYh7DK5H9VJwshFsolUsn0n2u5qpfgg UV+alLGH8S8f0hHaH+ZzQce0OrpwjQscRP3/Hw8pz9kTbb6WUIeTSjbdS0VObqGOjlHa u/8Nv+Jss1YG5KDqbolRnQAw7I1EQDyz7XM/OmOTD9+ZyBvqoVs7NyjuS32HQBBqjjfu q4BQ== 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=d9Zjbemurtm/J4rPnSra2wxipnG86UpHMBL/OMHW9IY=; b=QvC5GDD8Rqs1tIw98d6+O30/KxlIODLbbQNWpnGsfTqnPpQipaPnQxSpcTQeM+iCu3 mQOkNBxrbSYRgnAEX6KXcp7gdvUOylwbcDN3FjrIXWUeeK+fUxHcV0EUKip40kVlZtsy fcu52/KDeb9Q+csKLnX+AyybAbW5yEweNnFt3X9UMjrWb4YULDqjWyjDv9AhnAZlF0MX 7SlJfJNO2hSg58trZAo1V28BKY81yPusbPnk/nwGjBr30RP6GL4wxh84D/mLi4VNK0Kn Cpql0zY5nMjYKXRf3Y/ksQoaqQxjKM7fZ7A+dD4GoQZzmI9GRKmFCPnWBQbV3/jjA8CH ng0w== X-Gm-Message-State: AGRZ1gKdz7vibolwHIlpfzOoNTFOOWOUaIbDZoa44d2U0Lavsmkqfcmt FoPCvZ/tB5QbSClCGLY+YWs= X-Google-Smtp-Source: AJdET5dFHnqu4rNNE0VKd7AEZRl4+dGCx8N4yty+rLLV0AqsB+hfAvdfy9TfzweUlRF1PvcusfuTdg== X-Received: by 2002:a19:c7c2:: with SMTP id x185mr8949775lff.123.1541234954573; Sat, 03 Nov 2018 01:49:14 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id s191-v6sm657373lfe.17.2018.11.03.01.49.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Nov 2018 01:49:13 -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 v3 11/14] read-cache.c: remove #ifdef NO_PTHREADS Date: Sat, 3 Nov 2018 09:48:47 +0100 Message-Id: <20181103084850.9584-12-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.1005.gac84295441 In-Reply-To: <20181103084850.9584-1-pclouds@gmail.com> References: <20181027173008.18852-1-pclouds@gmail.com> <20181103084850.9584-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 This is a faithful conversion with no attempt to clean up whatsoever. Code indentation is left broken. There will be another commit to clean it up and un-indent if we just indent now. It's just more code noise. Signed-off-by: Nguyễn Thái Ngọc Duy --- read-cache.c | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/read-cache.c b/read-cache.c index d57958233e..40fc0cb65f 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,7 +2172,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist) src_offset = sizeof(*hdr); -#ifndef NO_PTHREADS + if (HAVE_THREADS) { nr_threads = git_config_get_index_threads(); /* TODO: does creating more threads than cores help? */ @@ -2219,21 +2210,19 @@ 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 + } else { + src_offset += load_all_cache_entries(istate, mmap, mmap_size, src_offset); + } 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,9 @@ 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(); + if (nr_threads != 1) { int ieot_blocks, cpus; @@ -2787,7 +2777,7 @@ 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 +2861,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 +2872,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 +3457,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 +3529,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 Nov 3 08:48:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10666577 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 B525817D5 for ; Sat, 3 Nov 2018 08:49:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF8CA2AC69 for ; Sat, 3 Nov 2018 08:49:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A410C2AC79; Sat, 3 Nov 2018 08:49:20 +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 494C02AC69 for ; Sat, 3 Nov 2018 08:49:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728020AbeKCR7y (ORCPT ); Sat, 3 Nov 2018 13:59:54 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:39677 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727732AbeKCR7w (ORCPT ); Sat, 3 Nov 2018 13:59:52 -0400 Received: by mail-lf1-f67.google.com with SMTP id n18so2856994lfh.6 for ; Sat, 03 Nov 2018 01:49:16 -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=euybIvld3AGWecuIQdcP0z0DGFyQP1DeyK47FQT4Byc=; b=ufctExuE0FEH2oebDcWRr5/mPlxZ+JwerZmfpPKiH044jS9NLvHeP0AXoB57Qb3qGE BUJbkctOtVC+Yv+AMZnqYZKGIr1Enc+zH/JXTwOruglgJOspVk3Bt/HxiDMrzhtXvdTd qcBuDYTiDUalutFpe1s09KhNtbcLCrag3lc3HwUDdcLqCuaZI7cyAK/8+x61Vio/Jjx/ PASKnhJeu+PzHlmBeWVrwBktEUpHe0HZmtJnyd0JOeZydv5EzrCutKWJd/Q+1NW8qJSO hs1i11qaOjTR/oxm0pGqE0VwGAocDo1oDinZwFotdPoQC2Hd0T4ir5CkOZk88oJq5K0t URuQ== 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=euybIvld3AGWecuIQdcP0z0DGFyQP1DeyK47FQT4Byc=; b=iAuU6fzeiJTjrlzUFhxRuOOnu26xXat7lBpl5tYVlWC4tVZwAgNZYEM9n51T0kAzFt kULCroI+fXkt5DcxQoNzfcqEPRIq69JGuE8znGqquHS0cGIM3kG470T3T0ZWIee8gc/0 OaLvOWViHbu26gTC44lZjUQCN8cBkruHCavkFv1RmgFAVTnlVhkmrdTKLBfqHou2wobt dwDEkqsh7boDIkjhM91lIo/iw/DjKok+mrs09iGKrQ3P+I7wHkxtodae+b43EsVy5kZJ GQKyh+VLZS9YVJL19QdM2sKLMCsjMlsq2kTmDZjCWvNEvOc+1RJDiARNfjxuE8Ad8Ve9 3sZQ== X-Gm-Message-State: AGRZ1gKz4+ANXOqeyP1JrKS9DYPRWTuQVvYJ5s6c1FOdFsTchWGGpCum sH07UIF+6YdhzjtLlsbwPXU= X-Google-Smtp-Source: AJdET5fDs6AWWpT4rICbhBQ+szWrichmG0HhaIq7kJGAN0grPUEgi5kTX1tSVz6lDM07qwjNhuenGw== X-Received: by 2002:a19:3b12:: with SMTP id i18mr8936340lfa.28.1541234955665; Sat, 03 Nov 2018 01:49:15 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id s191-v6sm657373lfe.17.2018.11.03.01.49.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Nov 2018 01:49:14 -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 v3 12/14] read-cache.c: reduce branching based on HAVE_THREADS Date: Sat, 3 Nov 2018 09:48:48 +0100 Message-Id: <20181103084850.9584-13-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.1005.gac84295441 In-Reply-To: <20181103084850.9584-1-pclouds@gmail.com> References: <20181027173008.18852-1-pclouds@gmail.com> <20181103084850.9584-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 | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/read-cache.c b/read-cache.c index 40fc0cb65f..00cd416816 100644 --- a/read-cache.c +++ b/read-cache.c @@ -2172,7 +2172,6 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist) src_offset = sizeof(*hdr); - if (HAVE_THREADS) { nr_threads = git_config_get_index_threads(); /* TODO: does creating more threads than cores help? */ @@ -2183,6 +2182,9 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist) nr_threads = cpus; } + if (!HAVE_THREADS) + nr_threads = 1; + if (nr_threads > 1) { extension_offset = read_eoie_extension(mmap, mmap_size); if (extension_offset) { @@ -2210,20 +2212,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); - } 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 */ - if (HAVE_THREADS && extension_offset) { + if (extension_offset) { int ret = pthread_join(p.pthread, NULL); if (ret) die(_("unable to join load_index_extensions thread: %s"), strerror(ret)); - } - if (!extension_offset) { + } else { p.src_offset = src_offset; load_index_extensions(&p); } @@ -2745,8 +2743,10 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, if (ce_write(&c, newfd, &hdr, sizeof(hdr)) < 0) return -1; - if (HAVE_THREADS) { + if (HAVE_THREADS) nr_threads = git_config_get_index_threads(); + else + nr_threads = 1; if (nr_threads != 1) { int ieot_blocks, cpus; @@ -2777,7 +2777,6 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, ieot_entries = DIV_ROUND_UP(entries, ieot_blocks); } } - } offset = lseek(newfd, 0, SEEK_CUR); if (offset < 0) { @@ -2861,7 +2860,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. */ - if (HAVE_THREADS && ieot) { + if (ieot) { struct strbuf sb = STRBUF_INIT; write_ieot_extension(&sb, ieot); From patchwork Sat Nov 3 08:48:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10666579 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 7B2E1109C for ; Sat, 3 Nov 2018 08:49:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7536D2AC69 for ; Sat, 3 Nov 2018 08:49:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 69BBA2AC79; Sat, 3 Nov 2018 08:49:21 +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 1EE6D2AC69 for ; Sat, 3 Nov 2018 08:49:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727984AbeKCR7y (ORCPT ); Sat, 3 Nov 2018 13:59:54 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:35171 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727966AbeKCR7y (ORCPT ); Sat, 3 Nov 2018 13:59:54 -0400 Received: by mail-lf1-f67.google.com with SMTP id d7-v6so2879396lfi.2 for ; Sat, 03 Nov 2018 01:49:17 -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=j/0KAxyqB/aKIJtaarDb/9ksbM8gHld0fkv9bregI0Y=; b=niJ4PtJ3RF2l8v7ikHPekXuYymgLkqaTnXvHXDzGONvoScZj/WzOw2NvT32njSw6yX BPVgqEOSmRmh0LVlY2Y5fJDmABPwuxldJkaS+TVINPlt9HMQ08BVkhpOPSDJMJ/rUG1h ZZVId/gtpV3vVVbICHY7zq8/ZLPpQdHkTzxtCw4C4vDDcGsX1ZGGGkRhYNiYN+YOtCcv 1pVOh9Tig453S6Nn6yTidKUpf9raWQuLhrO01cH9fmCoTLQmF90C9l/RcLoClFNho2sJ sHkbhCm32YQUpEw8VKGLhLKRn8kUl9s0L7XDaMM2OQ/+ZozHs3PSJvQEaarZq1k3kIhV h84w== 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=j/0KAxyqB/aKIJtaarDb/9ksbM8gHld0fkv9bregI0Y=; b=hjDGIRMDTRwQnbNRrR8ufZLiJ+pgbB5T1Qol+NyjrdGuryIZdxstcB29DyYG5y9r0/ 5jtMtFh/CQjf7Pitmq7sSOZ1HQfvwHnI7/koXqQfzb5FREXqvF1vS+uhLU1mmrDm6xiJ CwanzYund8hLylvadce1evQyZfsn56Fcac6NK0IwvnDPts6Two8eEcFFn0yCLZbcnZ17 tA3N3KilcJgxZLqXroFjQRO9JoiIsEYgoSC74iCMGCYXfXCOyNzmHB147lmIYlQMGR8m vg/3s8iIdfa2Kp1an69ZZjbk7NZQSBiYfmllgV/GC0s0rhzDEFkY5CAdho+zaCfzYtfy 6JRw== X-Gm-Message-State: AGRZ1gK7yiGsejCWMrfRjtpVzE+hAl5v3ykYM2O0nDQdpvbjno8RNCG+ ePLbEUtdtB33BRziaoGbYTk= X-Google-Smtp-Source: AJdET5cxoyC03J1v9jCKykY+qOdWDDqX/ycvDkfiTU4nL76d/3FBnwPUiX+AhmkoiSxe5xy9xJhTgg== X-Received: by 2002:a19:5186:: with SMTP id g6mr8297969lfl.143.1541234956923; Sat, 03 Nov 2018 01:49:16 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id s191-v6sm657373lfe.17.2018.11.03.01.49.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Nov 2018 01:49: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 v3 13/14] read-cache.c: initialize copy_len to shut up gcc 8 Date: Sat, 3 Nov 2018 09:48:49 +0100 Message-Id: <20181103084850.9584-14-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.1005.gac84295441 In-Reply-To: <20181103084850.9584-1-pclouds@gmail.com> References: <20181027173008.18852-1-pclouds@gmail.com> <20181103084850.9584-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 00cd416816..c510f598b1 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; } From patchwork Sat Nov 3 08:48:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10666581 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 2DEF417D5 for ; Sat, 3 Nov 2018 08:49:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27CCF2AC69 for ; Sat, 3 Nov 2018 08:49:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C17F2AC79; Sat, 3 Nov 2018 08:49:22 +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 AAB712AC69 for ; Sat, 3 Nov 2018 08:49:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728028AbeKCR74 (ORCPT ); Sat, 3 Nov 2018 13:59:56 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:40532 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726290AbeKCR7z (ORCPT ); Sat, 3 Nov 2018 13:59:55 -0400 Received: by mail-lf1-f67.google.com with SMTP id n3-v6so2853461lfe.7 for ; Sat, 03 Nov 2018 01:49: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=Ut5Bg3EmlKu6YigAMO4KRWJjmbiR4VAow+fxed/TxV0=; b=PkrfxrXcdlkfkemq/hM4otHAUQcleuy1ZcaCsNoe0t+69JF2f2vMiiFICEt20RpN+n mqU+nKWhgIgWmDgCzQb0o/hDha9ELpGhQOUQ/o14ECV/Ufk7CRkMs0emfLXsLCQnuACc nCoQjBIttbhvHBfgGu1j0i8qEDLAcVxwu9Bq5udRPqiQkfqJOZNDOuryDqAQf5Xt3RWa y6Mx+XDNL/sjoqruBfQTpn95288+KDX/eOzMYClNVetugPbr9uO7bWpLhfFCa6Q0xD8n 8A3/khcLG0t4EjxdxVxQKj+WKSiWJWaInnHDNaAso9mpG/LhP3Zfxoo9eVwLnCWSCN1T OQeQ== 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=Ut5Bg3EmlKu6YigAMO4KRWJjmbiR4VAow+fxed/TxV0=; b=arRWDnOzlNVe51e5DASF8GbrfliSVr5VlYjvzoy+E3Jzqs4nY1BqPl/WY8XUzGWTDT QEKEX3JElxf50JmYmlKJ0QyToQvMjewTAk8WeY2dUniodiFomiOE7cwEIrHB7glx/KbG PhMQ9ljmezGPXvSEwxHajriFR/lKrduXJgR8Z5DJ7cICasGge6Fh8loBji2fFlKEA+1z sb3PwlNuXdRqmadTtLEJuAWNCy7tL/AX7HTmQJhPfHR8LpglpZCOzZ5aHeG5/hETQGq6 jAlBrmEL++5w+QZu8YQVKEzRLosKeGYSejmUFM150RVgYEbLAWjEQNevZJ65aFFaDQbL 5qfQ== X-Gm-Message-State: AGRZ1gJNR3XCFFT4ZzkynoEzVeVPOrVkybZ9YQ8nREekzfCrEmrbkucQ eNoO4NhUvLgm/fpsvOm4lNrDMxpa X-Google-Smtp-Source: AJdET5fIDyTZZ3dajic88wF9koonLO2PRgPUvkywGuoQ3/VPvjJESqCIYo2CCWsu0K3w6sCB8ptVIw== X-Received: by 2002:a19:fc09:: with SMTP id a9mr9121568lfi.21.1541234958132; Sat, 03 Nov 2018 01:49:18 -0700 (PDT) Received: from localhost.localdomain (c80-216-12-205.bredband.comhem.se. [80.216.12.205]) by smtp.gmail.com with ESMTPSA id s191-v6sm657373lfe.17.2018.11.03.01.49.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Nov 2018 01:49:17 -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 v3 14/14] Clean up pthread_create() error handling Date: Sat, 3 Nov 2018 09:48:50 +0100 Message-Id: <20181103084850.9584-15-pclouds@gmail.com> X-Mailer: git-send-email 2.19.1.1005.gac84295441 In-Reply-To: <20181103084850.9584-1-pclouds@gmail.com> References: <20181027173008.18852-1-pclouds@gmail.com> <20181103084850.9584-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. 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() reports the error cause. 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 3c3b8814df..decf3239bd 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; } }