Skip to content

Commit 68d0021

Browse files
repkjmberg-intel
authored andcommitted
wifi: cfg80211: Add wiphy_delayed_work_pending()
Add wiphy_delayed_work_pending() to check if any delayed work timer is pending, that can be used to be sure that wiphy_delayed_work_queue() won't postpone an already pending delayed work. Signed-off-by: Remi Pommarel <[email protected]> Link: https://patch.msgid.link/[email protected] [fix return value kernel-doc] Signed-off-by: Johannes Berg <[email protected]>
1 parent e1a9ae3 commit 68d0021

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

include/net/cfg80211.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6129,6 +6129,50 @@ void wiphy_delayed_work_cancel(struct wiphy *wiphy,
61296129
void wiphy_delayed_work_flush(struct wiphy *wiphy,
61306130
struct wiphy_delayed_work *dwork);
61316131

6132+
/**
6133+
* wiphy_delayed_work_pending - Find out whether a wiphy delayable
6134+
* work item is currently pending.
6135+
*
6136+
* @wiphy: the wiphy, for debug purposes
6137+
* @dwork: the delayed work in question
6138+
*
6139+
* Return: true if timer is pending, false otherwise
6140+
*
6141+
* How wiphy_delayed_work_queue() works is by setting a timer which
6142+
* when it expires calls wiphy_work_queue() to queue the wiphy work.
6143+
* Because wiphy_delayed_work_queue() uses mod_timer(), if it is
6144+
* called twice and the second call happens before the first call
6145+
* deadline, the work will rescheduled for the second deadline and
6146+
* won't run before that.
6147+
*
6148+
* wiphy_delayed_work_pending() can be used to detect if calling
6149+
* wiphy_work_delayed_work_queue() would start a new work schedule
6150+
* or delayed a previous one. As seen below it cannot be used to
6151+
* detect precisely if the work has finished to execute nor if it
6152+
* is currently executing.
6153+
*
6154+
* CPU0 CPU1
6155+
* wiphy_delayed_work_queue(wk)
6156+
* mod_timer(wk->timer)
6157+
* wiphy_delayed_work_pending(wk) -> true
6158+
*
6159+
* [...]
6160+
* expire_timers(wk->timer)
6161+
* detach_timer(wk->timer)
6162+
* wiphy_delayed_work_pending(wk) -> false
6163+
* wk->timer->function() |
6164+
* wiphy_work_queue(wk) | delayed work pending
6165+
* list_add_tail() | returns false but
6166+
* queue_work(cfg80211_wiphy_work) | wk->func() has not
6167+
* | been run yet
6168+
* [...] |
6169+
* cfg80211_wiphy_work() |
6170+
* wk->func() V
6171+
*
6172+
*/
6173+
bool wiphy_delayed_work_pending(struct wiphy *wiphy,
6174+
struct wiphy_delayed_work *dwork);
6175+
61326176
/**
61336177
* enum ieee80211_ap_reg_power - regulatory power for an Access Point
61346178
*

net/wireless/core.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,6 +1704,13 @@ void wiphy_delayed_work_flush(struct wiphy *wiphy,
17041704
}
17051705
EXPORT_SYMBOL_GPL(wiphy_delayed_work_flush);
17061706

1707+
bool wiphy_delayed_work_pending(struct wiphy *wiphy,
1708+
struct wiphy_delayed_work *dwork)
1709+
{
1710+
return timer_pending(&dwork->timer);
1711+
}
1712+
EXPORT_SYMBOL_GPL(wiphy_delayed_work_pending);
1713+
17071714
static int __init cfg80211_init(void)
17081715
{
17091716
int err;

0 commit comments

Comments
 (0)