Received: by 2002:a05:7412:d002:b0:f9:9049:d2ea with SMTP id bd2csp43887rdb; Wed, 20 Dec 2023 03:33:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IFqhrBnQb2mlkVVcBqQ7ABFvR0NR2TasGrY5IXfkvUthblMxtQ5MTIJT9Sg9pjq61Yyarxk X-Received: by 2002:a05:6214:226f:b0:67f:43dc:f666 with SMTP id gs15-20020a056214226f00b0067f43dcf666mr6756110qvb.52.1703071985080; Wed, 20 Dec 2023 03:33:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703071985; cv=none; d=google.com; s=arc-20160816; b=hZfPrcutlRUVOQ9Rcw3REvTT8gpx5nbsuVpZfMybkdZPVzCpG+JFbXhY1ux42PjLBB q/FQ75YKotUs/iiopS6PWFD4BgNbPGVlDh/dzju754xHYhc+NsmETAsTgiHlD6iQSeLq LA8jHAti9vdHPZNKHZTNW+4nqrANWtGZBRWjPg8cQMMB9AihZZocZmjvvibBP+laKF8Q ihExhsA6MiAu4TOpIaZaN6HQTKc9/6IihmPoYsc+9i99y/lTk+HIdpRVnQqrsX2cl0gu qQrzd38YKwqRo/GHzk86C6BaasXunKyWKo15eSR8MWe9vVhy9Wc4L9O4s3EU6N3Qvkb3 xk0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:feedback-id:references :in-reply-to:message-id:subject:cc:from:to:date:dkim-signature; bh=wY3jU3FbByIfLUACfIHBmNS2cVGtxbGw94BOjG8I3wE=; fh=CsWGf/Awp6f0EAdsmy2FNMWdLtyOQt3rLrP7qNIXUTE=; b=n5o+pazBanrSlB84GWTVSQ8xqPgvLC7QvzJ5JEaZKm37Xj91Vkhh57I2MhU0vzj/Wb LZXV+MgD3w0r2mR6YqFgzGyEZmK4ZHRuWGLHY7nRmhbTrLfSLxIR79vl4CdJEt1jpOHF DCJlRnKgGGHBCBHzANC9I3iBAHUFv+5813y3x0t75p7ynfFNshBcGErd351sTO5KNjFQ EbE9fUZ5JG1HAVNrpM7SgBRKArLN9/pV9md5M5Fneh5LDgdO5s6z93yalxgfbV/rTw2W do4KgjRUEbaSzuwlZG2kU/PMEz5PoSgJ6Zz8PnCBzuy46AR+3RtQ7ONfK3vNWIhv4oGH XHiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=lecIb3gz; spf=pass (google.com: domain of linux-kernel+bounces-6824-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6824-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id r17-20020a0c9e91000000b0067f79531c05si15149qvd.593.2023.12.20.03.33.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 03:33:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6824-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=lecIb3gz; spf=pass (google.com: domain of linux-kernel+bounces-6824-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6824-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id CF44E1C25CD0 for ; Wed, 20 Dec 2023 11:33:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 050AB2137E; Wed, 20 Dec 2023 11:32:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="lecIb3gz" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 076DC21358; Wed, 20 Dec 2023 11:32:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1703071972; x=1703331172; bh=wY3jU3FbByIfLUACfIHBmNS2cVGtxbGw94BOjG8I3wE=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=lecIb3gzq3o0k9XNQ0qFEvRdz6/kwTysT8BMsZJYPJovJN3pxDoLl4eOsW9HmHJXx BqFUVBBmWvT7/onEM12C3Gfv8fEOM2hblhbVuucilMmFJIevTKLpNWugApQYEQjSJW jO1YHxqNLXtRlWS5bR/btcfPEus3GGTGrrvsMTNWIb6seO2gXWuqGXsll9z9w1YbdS gxLACIX7cTaGcVmgN6vAxD+hTv20yAyAA3bQRcwh9XYcYxu7Z0LsQ75lyzX5g+M4Zd RRBdAkPUu0MJ72Cmd6e9LRfl8ojuFa+EnTGLirAzW3+8k6Ga+8m0iO52BxVWph9vGg OviQTKorw5LTw== Date: Wed, 20 Dec 2023 11:31:05 +0000 To: Alice Ryhl , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Tiago Lam , Thomas Gleixner From: Benno Lossin Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 3/4] rust: sync: add `CondVar::wait_timeout` Message-ID: <3fba196a-8cb6-4ce9-9e67-bfb716a2d171@proton.me> In-Reply-To: <20231216-rb-new-condvar-methods-v2-3-b05ab61e6d5b@google.com> References: <20231216-rb-new-condvar-methods-v2-0-b05ab61e6d5b@google.com> <20231216-rb-new-condvar-methods-v2-3-b05ab61e6d5b@google.com> Feedback-ID: 71780778:user:proton Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 12/16/23 16:31, Alice Ryhl wrote: > @@ -102,7 +105,12 @@ pub fn new(name: &'static CStr, key: &'static LockCl= assKey) -> impl PinInit }) > } >=20 > - fn wait_internal(&self, wait_state: u32, guar= d: &mut Guard<'_, T, B>) { > + fn wait_internal( > + &self, > + wait_state: u32, > + guard: &mut Guard<'_, T, B>, > + timeout: c_long, > + ) -> c_long { > let wait =3D Opaque::::uninit(); >=20 > // SAFETY: `wait` points to valid memory. > @@ -113,11 +121,13 @@ fn wait_internal(&self, wait= _state: u32, guard: &mut Guar > bindings::prepare_to_wait_exclusive(self.wait_list.get(), wa= it.get(), wait_state as _) > }; >=20 > - // SAFETY: No arguments, switches to another thread. > - guard.do_unlocked(|| unsafe { bindings::schedule() }); > + // SAFETY: Switches to another thread. The timeout can be any nu= mber. > + let ret =3D guard.do_unlocked(|| unsafe { bindings::schedule_tim= eout(timeout) }); I am not sure what exactly the safety requirements of `schedule_timeout` are. I looked at the function and saw that the timout should not be negative. But aside from that only the the context switching should be relevant. What things are not allowed to do when calling `schedule` (aside from the stuff that klint catches)? Because if there are none, then I would put the "switches to another thread" part into a normal comment. --=20 Cheers, Benno >=20 > // SAFETY: Both `wait` and `wait_list` point to valid memory. > unsafe { bindings::finish_wait(self.wait_list.get(), wait.get())= }; > + > + ret > }