From nobody Tue Oct 28 18:18:55 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4cwzCr27wKz6DH3d; Tue, 28 Oct 2025 18:19:04 +0000 (UTC) (envelope-from zlei@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cwzCr0SVrz3N0j; Tue, 28 Oct 2025 18:19:04 +0000 (UTC) (envelope-from zlei@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1761675544; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0CaV2MlXt0jFrOdxezVXnxvQm3V0BCCZYxQg8Z3Uias=; b=x4PbjO8sIEvB4OJOG68bP/u9f19pudvgCQ5NZA/Dx1GIRI1xMSz2QPkmIB1X1CBZ+6JWDt IjM8wqg+iHAbHlziUfKwvAOcFomVa/OrkzTRAXi2ODRCcdmLY4hBGYf3cIZMODX1e1YTpZ iRzLcyEkjAs7aYggB07vqhtOulP3ZAbc5xHfCyrrgo9PiPRoci4Fkia9oyU7MMG402dQ+R oeOp/wwfkFj4MgQ0fHhddw5erfaLT/gpt0LC22JaKdkPWUL4u/w4GV+yV3czUaZVEwh03k F/fcTrjftjpL6omS7HDhS/scCrKIwfJGMfqB0HI2L7zg3gi3LWADHxtvAVp3tQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1761675544; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0CaV2MlXt0jFrOdxezVXnxvQm3V0BCCZYxQg8Z3Uias=; b=Ybjv5m1a+ivNeRzjdTPBcd5G9w54gZyGSV5A+ykKT+i7ZNSxX0RuGiM0hLa2JrTL0ZS2+7 SEUopJmSUHR2mjSxBS+DRRO7wCKSYwC1GwBUa/Jo8b3AUyQj4zwhFpzZfd73iMMAzzN+q4 xnWhI9XUfNwdu/TjOx3PRzCZwidMYUBMEBydywSlkdH2erx+J8x8a5abPwEEVrRLFWynAA KTLl7xVD8JYIn63ZhSu9ClHHOaA5oLJ4LQa1MnKrK1LDoGSRBqrm62j34gY4TVQyHVNWOz +RYQFCaLSWdMHcgeMTAd16/8s5UZsPJiJSWQqcMnWd0hgvIApNgRj+Rp19Cyzw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1761675544; a=rsa-sha256; cv=none; b=M/FOdJY0n+CXxMqBjgz51KIVQVxFCv+wJGmNGB8LqU1/89gC7wA/0/GZumEj++QPszA3KD 7C4pq5TaV48uyi69Gfn/YNstXJfI8iIqXtZN/2ZqVBd/hbaCT5eiTtxkvLSD5FCqfeAbhh yq5dvvpNAUy3QhpbdQ9WCsL60e+8w8DNQi8lzNWHp3pXPCtOYO3kZVL45Mj8TZRzeisMdi DLfNLhqeGP4dfBW7IrJxmcxo1Z6QIco/+ofOgO8SWOja59jC1H55fVCa6SpemB11OWqhbr Ukl7LrmVDKp0B6ewloErd7IA00dK/fIfoRN8qnAgZQk4PyHqQ2I1/2+NS+CgQA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from smtpclient.apple (unknown [IPv6:2001:19f0:6001:9db:98f0:9fe0:3545:10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: zlei/mail) by smtp.freebsd.org (Postfix) with ESMTPSA id 4cwzCp3TMDzyr; Tue, 28 Oct 2025 18:19:02 +0000 (UTC) (envelope-from zlei@FreeBSD.org) Content-Type: text/plain; charset=utf-8 List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.10\)) Subject: Re: git: 3d73146baeb9 - main - pwait: Add an option to print remaining processes From: Zhenlei Huang In-Reply-To: Date: Wed, 29 Oct 2025 02:18:55 +0800 Cc: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= , src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <202510281157.59SBvhNB002870@gitrepo.freebsd.org> To: Gleb Smirnoff X-Mailer: Apple Mail (2.3696.120.41.1.10) > On Oct 29, 2025, at 1:28 AM, Gleb Smirnoff = wrote: >=20 > On Tue, Oct 28, 2025 at 11:57:43AM +0000, Dag-Erling Sm=C3=B8rgrav = wrote: > D> +static int > D> +pidcmp(const struct pid *a, const struct pid *b) > D> +{ > D> + return (a->pid > b->pid ? 1 : a->pid < b->pid ? -1 : 0); > D> +} > D> + > D> +RB_HEAD(pidtree, pid); > D> +static struct pidtree pids =3D RB_INITIALIZER(&pids); > D> +RB_GENERATE_STATIC(pidtree, pid, entry, pidcmp); >=20 > We have a nice trick in our tree(3) that allows to use lighter compare > functions. The function can return any signed integer type, thus we > can: >=20 > static pid_t > pidcmp(const struct pid *a, const struct pid *b) > { > return (a->pid - b->pid); > } I'd prefer to return const 1 / -1 / 0, that is straight forward of a = comparator. Also the compiler is smart enough to catch this pattern and generate optimized code, from my = experiment which is long long time ago. The pid has type pid_t which is a type redefinition of __int32_t. = Although the pid will not reach 2^31 or -2^31 - 1, in principle the computing of the delta of the two = signed integers may overflow and that is bad smell. Best regards, Zhenlei >=20 > --=20 > Gleb Smirnoff