Received: by 2002:a05:7208:13ce:b0:7f:395a:35b6 with SMTP id r14csp8125rbe; Wed, 28 Feb 2024 10:19:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUNjH/+fNB3yfk/TyAb6ki+UU72UGmdY24NwC2jtw5krrDbOlwCFF5Aq+5VepWIR2+WXk+Ik0BMUDODHNvF+uWIpgKHKP9gE6+9GCMF/A== X-Google-Smtp-Source: AGHT+IHsHTlxyPgg+XQ9d9EAAqfdN5KSRNws9Jc6AG+rsjAIypzePcEHOOMTtcDRJLQxnSlfRGyL X-Received: by 2002:a05:6a21:3a83:b0:1a0:60b2:45b with SMTP id zv3-20020a056a213a8300b001a060b2045bmr53214pzb.6.1709144346693; Wed, 28 Feb 2024 10:19:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709144346; cv=pass; d=google.com; s=arc-20160816; b=bc57g9n04VvA51Qob7XIFFeZbHz1QsLCRU2JLHvuvMkgv5h/A4fUwrzTwWFA9ECN5v hp6dX5qARp3ozCqKl+2N9OOfVfAUxMnl2tPKVbQhhxla3MThCp7ectPF6TMkXZWHS3iF 96FGajpiI7/ur/WHj9aCtKGu0RpdVGZd4mPPj/SxPOfNliQm7gmLscaw/OvVFr7fTi7O 6lgrDEgGNhbEOBc7CMPiglYH38+9EWEout9xlKcSePesStjxPCXSss7SWYWqm+xWJm+o xrAk523t6vFMJRY8XltAO4+2Gcn9i3fmzMXiWQWZCNTDkpyqND/MCwitAjpe12/zKk93 yVPA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=yYZPAWRso4kZ0IbrwPw0ArpV7c3Fq15yCkQN2Ac6BqQ=; fh=jl9/kuBYo3Gn2BBz0zErs9UPETds1jCciNhLeHU6Px8=; b=EsrhipOZ5wHX4IlvdkICl4tR4nzIShSUAhT0SkL0XHzP854WyqM9O09Ojbx5yhm0XO g1r/KRdnG7drFNi7crYlSnoO2Ho/UcIUJhnVfCcbbX6J5kh/meCA4Bx/AfuZChoFkXuC XTsWnEuvegHaeSMyvQF5INneGndKSgUajEShI5mtDB0EekOsmOM6Vc7hsGI11npvw2c4 hNn+FkeqLl2ZDpN8AXmWM7esmjaYXjrd0pA31p3A8RmvIDAb7By+oM+m0Dt8vZPWRmQq Gtcwq01ETkH/32IRl3+jfZNuuwQKMtpVz8F4amBlNDKETnvlwRHZeDyKDa5Ask1mMKCw BxOA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=aJKdUie4; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-85523-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85523-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id jv11-20020a170903058b00b001dbcf6678b0si3682941plb.258.2024.02.28.10.19.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 10:19:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85523-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=aJKdUie4; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-85523-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85523-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 674AE288827 for ; Wed, 28 Feb 2024 18:19:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EA70A40863; Wed, 28 Feb 2024 18:18:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="aJKdUie4" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CCBE34084C for ; Wed, 28 Feb 2024 18:18:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709144339; cv=none; b=MIe7fzFvli5hfc8KeJPHbcA5wMeiGZDcOh3dvBkwhjSy90HJtRV/ch697rdszFoTdPPbIHFpLwSpKJEfIFLxNULufEyCj2aOjTV9N3LXYVrCax4NhuQ/i/tGgg9bCXjp5km4xT+ehhIKQ/GrvN6gbYWmMNbGNCaj6dBgGRr2LB0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709144339; c=relaxed/simple; bh=ctQuxA/YbpcInqTpD6+LUKnEtN3IvRYl52XsonnTBRw=; h=From:To:Cc:Subject:Date:Message-Id; b=N7l1fRtOzcH2TKUbPqGlIWj7/EzwDHBz6Qr7RIl5fm+KPSWNRjVHek4lB23ICRXgfJCx9p5MTuXeW3WADSIyd7BZvOuWA3pjBoI886qFzZA8HUk3vES2fgozX/tdzp2UPJeEfS/UuQgxT2Ph2FWX9kMjC/BPTvHftGw3Z3TzhFU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=aJKdUie4; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: from apais-vm1.0synte4vioeebbvidf5q0vz2ua.xx.internal.cloudapp.net (unknown [52.183.86.224]) by linux.microsoft.com (Postfix) with ESMTPSA id 7357E20B74C0; Wed, 28 Feb 2024 10:18:57 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 7357E20B74C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1709144337; bh=yYZPAWRso4kZ0IbrwPw0ArpV7c3Fq15yCkQN2Ac6BqQ=; h=From:To:Cc:Subject:Date:From; b=aJKdUie4ndiI+3TiPDgJ2JFkI1p84w+PHi++1EUxFy5pgJlfjYP6f64Cvi5HvZ9e6 JJOTsAmJuHY+uli/YfEZc2r18f82up0hLmHDweFvDU2kfmalLCchD6fiOq/eMjBKor aDe0VRqoDGWUExmgCzjs67uw1aSy26Nrb/sEQSII= From: Allen Pais To: tj@kernel.org Cc: jiangshanlai@gmail.com, linux-kernel@vger.kernel.org Subject: [PATCH] kernel: Introduce enable_and_queue_work() convenience function Date: Wed, 28 Feb 2024 18:18:50 +0000 Message-Id: <20240228181850.5895-1-apais@linux.microsoft.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The enable_and_queue_work() function is introduced to streamline the process of enabling and queuing a work item on a specific workqueue. This function combines the functionalities of enable_work() and queue_work() in a single call, providing a concise and convenient API for enabling and queuing work items. The function accepts a target workqueue and a work item as parameters. It first attempts to enable the work item using enable_work(). If the enable operation is successful, the work item is then queued on the specified workqueue using queue_work(). The function returns true if the work item was successfully enabled and queued, and false otherwise. This addition aims to enhance code readability and maintainability by providing a unified interface for the common use case of enabling and queuing work items on a workqueue. Signed-off-by: Allen Pais --- include/linux/workqueue.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h index aedfb81f9c49..31bbd38ef8c8 100644 --- a/include/linux/workqueue.h +++ b/include/linux/workqueue.h @@ -678,6 +678,29 @@ static inline bool schedule_work(struct work_struct *work) return queue_work(system_wq, work); } +/** + * enable_and_queue_work - Enable and queue a work item on a specific workqueue + * @wq: The target workqueue + * @work: The work item to be enabled and queued + * + * This function attempts to enable the specified work item using enable_work(). + * If the enable operation is successful, the work item is then queued on the + * provided workqueue using queue_work(). It returns %true if the work item was + * successfully enabled and queued, and %false otherwise. + * + * This function combines the operations of enable_work() and queue_work(), + * providing a convenient way to enable and queue a work item in a single call. + */ +static inline bool enable_and_queue_work(struct workqueue_struct *wq, + struct work_struct *work) +{ + if (enable_work(work)) { + queue_work(wq, work); + return true; + } + return false; +} + /* * Detect attempt to flush system-wide workqueues at compile time when possible. * Warn attempt to flush system-wide workqueues at runtime. -- 2.17.1