Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6100950rwr; Tue, 9 May 2023 10:11:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5sxmS3c3XuHIxT+U5H8vY6hGXv+u4wD/Q7f4tflKJ0+y+lTgISh9VJo0wAz2ybtg7AcE+b X-Received: by 2002:a17:90a:dc0b:b0:247:35c7:bd67 with SMTP id i11-20020a17090adc0b00b0024735c7bd67mr14523714pjv.46.1683652282607; Tue, 09 May 2023 10:11:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683652282; cv=none; d=google.com; s=arc-20160816; b=DUNtFPz2z6XdFUemhvPJcug7ucOp42fqPGC5LEsXey1FP9BxchaVY2xTKd/Xulk4QV jWdjVS0P303LpsUUOfT9NvH+9AbPI2E5r0iFtNNtc/T/stoNzu0pQyGKnF46pnGH3ga3 rPZeitV8w7DKGt52IMdDC2ZkQXUUnFdR6/NsJlfXAUPMUgqWAah4NEws91rSf+PVDsZi tj8ZlSMluDEeqpKKN/cGN8hI9yy/w0mQxG48r/tSMZAab4Nn8BAfdqaRNa0VBzK+YVom 0uCS2pEVJp1GfNvCDr4E5XLtzmBH/PdMhNUfLjFBJ29DMYvx4XvZ9hkKvOKl73xo+zgA 2JHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ry7U36vaXDdBTb0o6BnFM/rdvkZja/IMfv3muX44WIU=; b=LYqt8GxqiJ6AMh7whxJE/vvLSu7LzYFD1DapNoGM3isQb1udXP9S1wRZeQesE6dqhj iWSmsdyQxwWSCHT+BJ+UTEwIGRzZVTGw83uHkOcK9nblG45ffZWGEayRoiBpRrZVfi/O WQkCNXxqgeaosQ8qbCk/auPm/0qUthWUQJfiEyJhfygVYGtZ5ulWIwnhWLeess4OW43C FKff0jQMid+8uyLVLrQAN7rf+jgW8pnp3oQtG5Gy8xH+oDu94o7cxQplEkonRjL4fq38 2bhZkpqEGgRXpTb5JLJ5W2jugJB+l1dxODEqY7kTrYkoszTAWYjFzNhYfzALcuv2usys kp6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=hmk6zZus; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lx6-20020a17090b4b0600b0024e4df1b2e3si16569672pjb.123.2023.05.09.10.11.07; Tue, 09 May 2023 10:11:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=hmk6zZus; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235166AbjEIQ7S (ORCPT + 99 others); Tue, 9 May 2023 12:59:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234828AbjEIQ6U (ORCPT ); Tue, 9 May 2023 12:58:20 -0400 Received: from out-27.mta1.migadu.com (out-27.mta1.migadu.com [95.215.58.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D25B344AB for ; Tue, 9 May 2023 09:57:28 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1683651446; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ry7U36vaXDdBTb0o6BnFM/rdvkZja/IMfv3muX44WIU=; b=hmk6zZus9aPNjnuKozz487uUnEFHglhCyPnG192psE7jxpj0jtRd3lgfUFRLrnylBVNfYj jRDbGMhvjUKYwThlzVlIPGFJ+UaBu3N9ewJDUGEdB9RFZEMhxIAqI/VtVc98O4HdMGd3fq 7kdWwbvh5n+XJihcYdZVsTA2++XS67g= From: Kent Overstreet To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-bcachefs@vger.kernel.org Cc: Kent Overstreet , Coly Li , Kent Overstreet Subject: [PATCH 17/32] closures: closure_wait_event() Date: Tue, 9 May 2023 12:56:42 -0400 Message-Id: <20230509165657.1735798-18-kent.overstreet@linux.dev> In-Reply-To: <20230509165657.1735798-1-kent.overstreet@linux.dev> References: <20230509165657.1735798-1-kent.overstreet@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kent Overstreet Like wait_event() - except, because it uses closures and closure waitlists it doesn't have the restriction on modifying task state inside the condition check, like wait_event() does. Signed-off-by: Kent Overstreet Acked-by: Coly Li Signed-off-by: Kent Overstreet --- include/linux/closure.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/linux/closure.h b/include/linux/closure.h index 0ec9e7bc8d..36b4a83f9b 100644 --- a/include/linux/closure.h +++ b/include/linux/closure.h @@ -374,4 +374,26 @@ static inline void closure_call(struct closure *cl, closure_fn fn, continue_at_nobarrier(cl, fn, wq); } +#define __closure_wait_event(waitlist, _cond) \ +do { \ + struct closure cl; \ + \ + closure_init_stack(&cl); \ + \ + while (1) { \ + closure_wait(waitlist, &cl); \ + if (_cond) \ + break; \ + closure_sync(&cl); \ + } \ + closure_wake_up(waitlist); \ + closure_sync(&cl); \ +} while (0) + +#define closure_wait_event(waitlist, _cond) \ +do { \ + if (!(_cond)) \ + __closure_wait_event(waitlist, _cond); \ +} while (0) + #endif /* _LINUX_CLOSURE_H */ -- 2.40.1