From patchwork Tue Jul 22 14:58:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dora, Sunil Kumar" X-Patchwork-Id: 116776 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 040623858C48 for ; Tue, 22 Jul 2025 14:59:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 040623858C48 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0b-0064b401.pphosted.com (mx0b-0064b401.pphosted.com [205.220.178.238]) by sourceware.org (Postfix) with ESMTPS id C8A533858CDA for ; Tue, 22 Jul 2025 14:58:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C8A533858CDA Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=windriver.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=windriver.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C8A533858CDA Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.178.238 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1753196323; cv=pass; b=p75gumEtWFQoKpaMUFJa+F6aepvEMTuj63fZx8hWgDDYRlw5ol0fo9OEzcJ2Gph64Bjx6HSlF+UGuKvf+5kUKeiIlT2gkB0+Bf28cIEWb1LF7v5jGImr9aoc82IwE7p/0K9CjRCwH42PSSMXLuj7+1LOJStPDP9Y6pt7hSq0oMQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1753196323; c=relaxed/simple; bh=Lvl7djokOREto+79fwYHHDnZDyNjByETV1nyHVaMMI0=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=KEiGXn7ixxkdBZsJYMQUEtJx/3PruLk5Cp4vI4uxSeaGg07ujSxqjRF3C45jleNGriIjdPcgnvL4bFniG9GKVwiXOFlCtcpKSV+iqseCF7EegjiuPqxOXBUZGjcpBQKCtmzefpJJTlOoGlTMOEhgzuUGTkTiJb1tQK4k13EtzV4= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C8A533858CDA Received: from pps.filterd (m0250811.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.8/8.18.1.8) with ESMTP id 56M5f5wW3558072; Tue, 22 Jul 2025 14:58:40 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12on2062.outbound.protection.outlook.com [40.107.244.62]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 481vqu8xc9-2 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 22 Jul 2025 14:58:40 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GU0GBY+I+QyYZNJ5BcbxXAegkZglTJ5gjXeKk0eSMnfa6RRZEOstB6kLvoiOSOQwtW4xqi/+7F6gG5Q0S+e48d66am5qgsgppuJfr+f78mnixo3/gsgLD0lEteLNQfRQL4rsUoGkJT6x9uZrKn2Mb7WqQr5/jixH1QXraf5w5Mwn8HcXEYVqMXpdIokGWmKTdLsI/NKU64y+4MbMbX1kyc5jnTOjcBo81yJx5dzrZJa7RUXZKCU72H0BgIjP0SxZjct00cQTOSIp8aPFkukTv817s3+8DVEDzlTTtIGlSNM4IsH/MK0NAvjVeAXhYE8Zxz/nqopX0+C6vT6FWqTJbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0KJuWHVQV11DIPhHERCgSiBWLfIljEHqlyc6CuSgVlw=; b=x6MEuAAgxUgrgbVg8IBfqxOOPV3lQ9Lpz4cRQf8joeDnSA9xBbozABxedjfMpst3R1Ej3Ysy1hA91uetn17+bFtstD0eufkF0ThL1Zamh0utM8qLZLsHRcKtrP1CkpXiIgcyE4u+rFu8eDu/vSzhrCK1J4xDEysYkn0aMWd0d/WxuCgWbcTYR1Ta7HCsTSNYa6IlrHmOsrwFRjKQ2o/dwRnDmQHaIskx9XKT+7mPtdUpnpX3eCK7gllTtWT4mi0U55mq8Xko0XsjAXMfyQYw9Q5H9iBXiqrZY8oQLwpbqYoDAlYUKyfb8TzwMu/Xwg5+Cn0WIWGKwfUaWiiteueVrQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none Received: from DS0PR11MB7901.namprd11.prod.outlook.com (2603:10b6:8:f4::20) by BL3PR11MB6313.namprd11.prod.outlook.com (2603:10b6:208:3b0::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8943.29; Tue, 22 Jul 2025 14:58:36 +0000 Received: from DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d]) by DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d%3]) with mapi id 15.20.8943.029; Tue, 22 Jul 2025 14:58:36 +0000 From: sunilkumar.dora@windriver.com To: libc-alpha@sourceware.org Cc: sunilkumar.dora@windriver.com, carlos@redhat.com, fweimer@redhat.com, Sundeep.Kokkonda@windriver.com Subject: [PATCH 02/10] [2.36] nptl: Update comments and indentation for new condvar implementation Date: Tue, 22 Jul 2025 07:58:13 -0700 Message-ID: <20250722145821.2214847-3-sunilkumar.dora@windriver.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250722145821.2214847-1-sunilkumar.dora@windriver.com> References: <20250722145821.2214847-1-sunilkumar.dora@windriver.com> X-ClientProxiedBy: SJ0PR13CA0232.namprd13.prod.outlook.com (2603:10b6:a03:2c1::27) To DS0PR11MB7901.namprd11.prod.outlook.com (2603:10b6:8:f4::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR11MB7901:EE_|BL3PR11MB6313:EE_ X-MS-Office365-Filtering-Correlation-Id: 551cce48-4f70-4b57-9169-08ddc9303c59 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|52116014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: E4q1I53DJZQMN54PK+0FtvmLDOvQJged+PzC1K9SuEs5VcqCdvUUyPSEZXMluQDj8kuqRNfSwu99Iv8iUVf5wcasYD03riMEOWp7zhwIsezTAtRAa2/LKHNxiruwkGiMRU+4bIP5D0/KsSEUtnzb6ctKu4We168IgVur1mplEONCMfOXe5gXpOUWncsec2OWX+wOefkxCeYbbWdizTDH22T3ftxoT/uAf/KZCHsyRRhSYiCsTmDH4CqSr9vyL//9eZq3m9N3Ps1KE+lmMl/dHRXPKoc6V23xneyQaw7SAbBq7qCSjsSdFbri2Aw8PLisE/5GQ7k2i9Quy6Tq31ObDPmepFXfwP2OArj2+lle+L0dy2gaI9Fb6u2LYrxVCe075kP9hbB3zHTGGWq7wXvheW68y76b1KKp25AOuz3Igt1OwXX133NZB7VMqo+dnhCoZudND/nwcbK38kF/hHx2tMJZMp9NOwH0iVuPxCl362MQinWUV0nXn+nkZqeDuZTaRC/0If6oNdX83o7vrHQZGD+IKOapJ1BRgJOPo8yHhQ4K3Bd4Jg9Wl8q/UCk5yP0pgIs/WGRYVa4CbnaWd7DWy2wr5TcvMWr5+OhJX5c21Q08GQJLUsOYX55jk7Z6ESSjOay7vd8PQ8oL401dsKeHb/G751axM+JyYtheJraKLH869hxDLxMgt0m5m8/e32ihIaB/O3RrL8PfJwVXa7B7E8w+LitQhhDufE6aeLALBGbU9X4aMLp6R7cnbLdX0s+qJnf7M1YNH62vOuQkcJFN8A9IZnVkykPb6qdpti1Fn1ZjwC0B6PvQUvUD9yZta1mbE1bM/DuDkKutYOWDl0f+OZOcMx4W/g7DPM2E6Z98DsnASwfcslelW3y+WMng8LHStnIzmncTPuZVY9Gn1GhIkVAS8x8Z6yKZf/mpJp0nOfXOV19xJf1rgx/sQ5QxNfg0KkPfa7/KUuI+xzVrdm3repf92J8SVvxRDHfwK487RhBS+EfAgX1vqrtBj0pn49lE0KTP2B1Xjk7KKqUjHRiLa64eLgTjr+lCKC8sDYzrJgvIm4vOm5HklEfwxeYOak/wor/C+AeHESAND8XMySdNrgdi88PP8qXq5DoRSdn6gUywebj0vshFqsMTKt7lGcoLGOBRHS7fVn6obcmuBmEy5wC3180+knekuagB36yEWZcaTUcr5V7AHah9hcu2o+sVlhFJHbkofOnADCXeLLT5wr6zbEpl0Y3u73Kbim/KMRQFcw7NARmAufyGof+gJsbarY4UPy3WMj/gzKRmvZZpL5eKKZyZFWL5ZHB0apqX+gVswR6QANF5tJsjGZNfljO2WHFlOyraWnv7MtKIiV2TDGK3vQkdTYYDbw7JQ8DUpanduPtjAIE62o9M/LRH9faNg/dBuG99zVYFFMW0VpshldYwRJuuiloNfa3YHqkjTbeZOftUprcma6BWmdqAsv8VIsp3MZ58bpZjcBBqo4bX3g== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR11MB7901.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(52116014)(1800799024)(366016)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: e1tJ8AdBYzn4kmufxqK+oxA4wDrrHMWR7h4hUHGDSNnJHNIETTYS9FhVVi8TF5ypDxmHSREL9RKpwGdfB9pmJ+AKyj6eQc1Kj1sf7NYTJ8IDpMtvm72tUItkKHRtRn8GKynBGEtCKxkXgRwIlzOcieIDFcfrvNb3ozKMKyg/kdg4veBwyyWK1v796tpFDhejj7yUX6Opr8kq5fkP6NA8zyYUZtIXSQblaaMBXkABmOZ2+4GSTQQnHQZUA/KScBw7MWUyW0QOxflJVdyqa4wJvU7oLs3NqnzZL12Ki41y98jsSa4p6lfEao8H2jDVJCt/KCrqJTiKTL0Nek8EZadB2/JwrwAjLTSBv2KN1kPp9Z+IdDv8dPjzF1FZMKtxMnGux61dHUdHETGrxgub5a8U7vD+P6gkPAg8LgeMdG0ZdPxM4OtGQoyr5dpj/CYqqwftBx3wGmeCnqOwjHCTzbv9mW5agxB+nqdgnZCSOce37k/D6Nc9J4m9+WBdXiDDwf5e7umsUpF4OjSfCZ9VkS/YmocvLXsDp1bJjFSmVrTKK9SUKtijCZMgSO3JZdkSxEJJojPa47jY5cYa2abOEudf4y+Q/HbRIRIkx8A5LkJHiOiCs5L+ScXA0yoZru4v3PA3rFYDHDG9ckoryzE0ccLRHb8Tt9R0sNiSkdpmSsTFhtJWQaRsIIGF4kITK/H3qF/FdtQaYyZSZRO1CKPz3e5rs/kfbZVq6ZxEqPZURylKoj/qla2zFjdxt3W9SXXkyYOjTbMPZI+M1VxKICiXQkccNoedNJUwiPSH8G5fDw6rvgRl3ktBPkaoUbComg02IXO2ChbkYKK4q5BXKek6U8rEoVHdLcAruOUAfcmt0JgcfCQ0vlxkM+cZayIR1+yKl482tnU4Jvat6HpE0UpePOhho0SPLrEzwHCvzr1Fy9IoSVd6jvkfnK7e92A+rengpnlqCcLKKJg2QKyjrs12JXyAEacetAwUi557jYhTom+qYwQnGxWF3KV5hQixdziJceNqf/A27+Upv0LAHe/bWuf09XIONhsrnir68QopWRpGWZQA9JO5cPwt/j2ph4fJXXFbWubEXMk+V73aBTjtjpYP/R8igtzs3KRLnDmPIsxwlZ14JiERU4uEz/wC0FZFcvKLH0H3WRBzCgF/bGRMcuMmh1HWXa6vcygRokMiC3pe5MhGEbN1vMPotAckWfFJxC6TBiSR52rOzppTL/u4FnV/uVbE6g98tpCFjMCl1IKI5nnYOrrJAE9Pl3FrtGJAak6NO92bG/ugK/9RI4PBi+KqCowtsgGO4ux/sCNyi48j6jpD3saOCVxAgNid+OjUZ3qM5K8rRLpkc7DnLENZ4sYbPbPmd/c+tA1KIqLCCUXgELRITEMw5gWzokd43zud7MetzCCLIdBgc8FSrrvwC7TQT4GGtWT0j/pgmVAiB+IxRBXBN+vulW6dmbM6j86/BNM73wKTMVyeVvWrLc0qnelEkczlOV3pHdEQkdmuLgNBPV6Rgem4Bwk0Ika+lGtW7SdLpwjhRbJf+JfAyHOwhTER3ta+i8/XlEV5xsUmVYEe0ojiwQF5/BgSO0QsYaQp62VgEsXWJtbpLQGrRIcXnK/Q9qyuydDfxLFnjoiBt6ZVUJE= X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 551cce48-4f70-4b57-9169-08ddc9303c59 X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7901.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2025 14:58:36.6427 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 25E45heWRjmsN2fqO5ucBSLXkkSOj6v0tf852zzsn/j8Huu/DrruP456wo2IuJmx+weSwo+tkbtNqgOl+DV2o84L2NFdAXvJizG83isRof0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR11MB6313 X-Proofpoint-GUID: ctQSpcZH38SL-fAv9oKgNu0Qz-P4CljW X-Proofpoint-ORIG-GUID: ctQSpcZH38SL-fAv9oKgNu0Qz-P4CljW X-Authority-Analysis: v=2.4 cv=AbqxH2XG c=1 sm=1 tr=0 ts=687fa720 cx=c_pps a=7j0Ltmo+QGRCGvpdpD29zg==:117 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=lCpzRmAYbLLaTzLvsPZ7Mbvzbb8=:19 a=wKuvFiaSGQ0qltdbU6+NXLB8nM8=:19 a=Ol13hO9ccFRV9qXi2t6ftBPywas=:19 a=xqWC_Br6kY4A:10 a=Wb1JkmetP80A:10 a=t7CeM3EgAAAA:8 a=UO6VkMP2561qkmehfEQA:9 a=FdTzh2GWekK77mhwV6Dw:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNzIyMDEyNCBTYWx0ZWRfX5siSNoR2arXU 8J6y1cWtePksqGex1ohCx7wd2/neEvvFR/EfAfin0Q+MsM3BlAUoTRTIYgsyIl4uEDFkfaphquF jj93wfaA5yzBEcWhHCfi+OoN74bOLtg/PScIPJ/NBUx7xNsOO8VA0RcsAuTmN7/a/i4wIkSmjvD Q9iRPb+wBGgw6xWWhm8QzoY1SCm+03hxrTaUXGNcSAYN9/5UOStGwuUNkBVUcF3sT1a7phwDQaP XdbDJFet9ebe1919DmWHyWEuSJKfE3cdOux5rr0270uygthCgiBbBQFKAl+Q1WKEDPb306oGW7n JiPqhV2F40PsbfE/qGWaPjHu8r1qk26ll5Tr2VzLJmlJeo8xqwOwirtO7Qv7f3b1nvJGkwdn6Nf 8z+gyIk/ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-07-22_02,2025-07-21_02,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 malwarescore=0 suspectscore=0 spamscore=0 phishscore=0 bulkscore=0 priorityscore=1501 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2507210000 definitions=main-2507210183 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: Malte Skarupke [BZ #25847] Some comments were wrong after the most recent commit. This fixes that. Also fixing indentation where it was using spaces instead of tabs. (cherry picked from commit 0cc973160c23bb67f895bc887dd6942d29f8fee3) Signed-off-by: Sunil Dora --- nptl/pthread_cond_common.c | 5 +++-- nptl/pthread_cond_wait.c | 39 +++++++++++++++++++------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/nptl/pthread_cond_common.c b/nptl/pthread_cond_common.c index a55eee3e6b..350a16fab2 100644 --- a/nptl/pthread_cond_common.c +++ b/nptl/pthread_cond_common.c @@ -221,8 +221,9 @@ __condvar_quiesce_and_switch_g1 (pthread_cond_t *cond, uint64_t wseq, * New waiters arriving concurrently with the group switching will all go into G2 until we atomically make the switch. Waiters existing in G2 are not affected. - * Waiters in G1 will be closed out immediately by the advancing of - __g_signals to the next "lowseq" (low 31 bits of the new g1_start), + * Waiters in G1 have already received a signal and been woken. If they + haven't woken yet, they will be closed out immediately by the advancing + of __g_signals to the next "lowseq" (low 31 bits of the new g1_start), which will prevent waiters from blocking using a futex on __g_signals since it provides enough signals for all possible remaining waiters. As a result, they can each consume a signal diff --git a/nptl/pthread_cond_wait.c b/nptl/pthread_cond_wait.c index 1cb3dbf7b0..cee1968756 100644 --- a/nptl/pthread_cond_wait.c +++ b/nptl/pthread_cond_wait.c @@ -249,7 +249,7 @@ __condvar_cleanup_waiting (void *arg) figure out whether they are in a group that has already been completely signaled (i.e., if the current G1 starts at a later position that the waiter's position). Waiters cannot determine whether they are currently - in G2 or G1 -- but they do not have too because all they are interested in + in G2 or G1 -- but they do not have to because all they are interested in is whether there are available signals, and they always start in G2 (whose group slot they know because of the bit in the waiter sequence. Signalers will simply fill the right group until it is completely signaled and can @@ -412,7 +412,7 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, } /* Now wait until a signal is available in our group or it is closed. - Acquire MO so that if we observe a value of zero written after group + Acquire MO so that if we observe (signals == lowseq) after group switching in __condvar_quiesce_and_switch_g1, we synchronize with that store and will see the prior update of __g1_start done while switching groups too. */ @@ -422,8 +422,8 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, { while (1) { - uint64_t g1_start = __condvar_load_g1_start_relaxed (cond); - unsigned int lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; + uint64_t g1_start = __condvar_load_g1_start_relaxed (cond); + unsigned int lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; /* Spin-wait first. Note that spinning first without checking whether a timeout @@ -447,21 +447,21 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, /* Reload signals. See above for MO. */ signals = atomic_load_acquire (cond->__data.__g_signals + g); - g1_start = __condvar_load_g1_start_relaxed (cond); - lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; + g1_start = __condvar_load_g1_start_relaxed (cond); + lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; spin--; } - if (seq < (g1_start >> 1)) + if (seq < (g1_start >> 1)) { - /* If the group is closed already, + /* If the group is closed already, then this waiter originally had enough extra signals to consume, up until the time its group was closed. */ goto done; - } + } /* If there is an available signal, don't block. - If __g1_start has advanced at all, then we must be in G1 + If __g1_start has advanced at all, then we must be in G1 by now, perhaps in the process of switching back to an older G2, but in either case we're allowed to consume the available signal and should not block anymore. */ @@ -483,22 +483,23 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, sequence. */ atomic_fetch_add_acquire (cond->__data.__g_refs + g, 2); signals = atomic_load_acquire (cond->__data.__g_signals + g); - g1_start = __condvar_load_g1_start_relaxed (cond); - lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; + g1_start = __condvar_load_g1_start_relaxed (cond); + lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; - if (seq < (g1_start >> 1)) + if (seq < (g1_start >> 1)) { - /* group is closed already, so don't block */ + /* group is closed already, so don't block */ __condvar_dec_grefs (cond, g, private); goto done; } if ((int)(signals - lowseq) >= 2) { - /* a signal showed up or G1/G2 switched after we grabbed the refcount */ + /* a signal showed up or G1/G2 switched after we grabbed the + refcount */ __condvar_dec_grefs (cond, g, private); break; - } + } // Now block. struct _pthread_cleanup_buffer buffer; @@ -536,10 +537,8 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, if (seq < (__condvar_load_g1_start_relaxed (cond) >> 1)) goto done; } - /* Try to grab a signal. Use acquire MO so that we see an up-to-date value - of __g1_start below (see spinning above for a similar case). In - particular, if we steal from a more recent group, we will also see a - more recent __g1_start below. */ + /* Try to grab a signal. See above for MO. (if we do another loop + iteration we need to see the correct value of g1_start) */ while (!atomic_compare_exchange_weak_acquire (cond->__data.__g_signals + g, &signals, signals - 2));