@@ -96,6 +96,10 @@ enum worker_flags {
9696 WORKER_UNBOUND | WORKER_REBOUND ,
9797};
9898
99+ enum work_cancel_flags {
100+ WORK_CANCEL_DELAYED = 1 << 0 , /* canceling a delayed_work */
101+ };
102+
99103enum wq_internal_consts {
100104 NR_STD_WORKER_POOLS = 2 , /* # standard pools per cpu */
101105
@@ -2028,7 +2032,7 @@ static void pwq_dec_nr_in_flight(struct pool_workqueue *pwq, unsigned long work_
20282032/**
20292033 * try_to_grab_pending - steal work item from worklist and disable irq
20302034 * @work: work item to steal
2031- * @is_dwork: @work is a delayed_work
2035+ * @cflags: %WORK_CANCEL_ flags
20322036 * @irq_flags: place to store irq state
20332037 *
20342038 * Try to grab PENDING bit of @work. This function can handle @work in any
@@ -2055,7 +2059,7 @@ static void pwq_dec_nr_in_flight(struct pool_workqueue *pwq, unsigned long work_
20552059 *
20562060 * This function is safe to call from any context including IRQ handler.
20572061 */
2058- static int try_to_grab_pending (struct work_struct * work , bool is_dwork ,
2062+ static int try_to_grab_pending (struct work_struct * work , u32 cflags ,
20592063 unsigned long * irq_flags )
20602064{
20612065 struct worker_pool * pool ;
@@ -2064,7 +2068,7 @@ static int try_to_grab_pending(struct work_struct *work, bool is_dwork,
20642068 local_irq_save (* irq_flags );
20652069
20662070 /* try to steal the timer if it exists */
2067- if (is_dwork ) {
2071+ if (cflags & WORK_CANCEL_DELAYED ) {
20682072 struct delayed_work * dwork = to_delayed_work (work );
20692073
20702074 /*
@@ -2543,7 +2547,8 @@ bool mod_delayed_work_on(int cpu, struct workqueue_struct *wq,
25432547 int ret ;
25442548
25452549 do {
2546- ret = try_to_grab_pending (& dwork -> work , true, & irq_flags );
2550+ ret = try_to_grab_pending (& dwork -> work , WORK_CANCEL_DELAYED ,
2551+ & irq_flags );
25472552 } while (unlikely (ret == - EAGAIN ));
25482553
25492554 if (likely (ret >= 0 )) {
@@ -4103,13 +4108,13 @@ bool flush_rcu_work(struct rcu_work *rwork)
41034108}
41044109EXPORT_SYMBOL (flush_rcu_work );
41054110
4106- static bool __cancel_work (struct work_struct * work , bool is_dwork )
4111+ static bool __cancel_work (struct work_struct * work , u32 cflags )
41074112{
41084113 unsigned long irq_flags ;
41094114 int ret ;
41104115
41114116 do {
4112- ret = try_to_grab_pending (work , is_dwork , & irq_flags );
4117+ ret = try_to_grab_pending (work , cflags , & irq_flags );
41134118 } while (unlikely (ret == - EAGAIN ));
41144119
41154120 if (unlikely (ret < 0 ))
@@ -4134,14 +4139,14 @@ static int cwt_wakefn(wait_queue_entry_t *wait, unsigned mode, int sync, void *k
41344139 return autoremove_wake_function (wait , mode , sync , key );
41354140}
41364141
4137- static bool __cancel_work_sync (struct work_struct * work , bool is_dwork )
4142+ static bool __cancel_work_sync (struct work_struct * work , u32 cflags )
41384143{
41394144 static DECLARE_WAIT_QUEUE_HEAD (cancel_waitq );
41404145 unsigned long irq_flags ;
41414146 int ret ;
41424147
41434148 do {
4144- ret = try_to_grab_pending (work , is_dwork , & irq_flags );
4149+ ret = try_to_grab_pending (work , cflags , & irq_flags );
41454150 /*
41464151 * If someone else is already canceling, wait for it to
41474152 * finish. flush_work() doesn't work for PREEMPT_NONE
@@ -4203,7 +4208,7 @@ static bool __cancel_work_sync(struct work_struct *work, bool is_dwork)
42034208 */
42044209bool cancel_work (struct work_struct * work )
42054210{
4206- return __cancel_work (work , false );
4211+ return __cancel_work (work , 0 );
42074212}
42084213EXPORT_SYMBOL (cancel_work );
42094214
@@ -4227,7 +4232,7 @@ EXPORT_SYMBOL(cancel_work);
42274232 */
42284233bool cancel_work_sync (struct work_struct * work )
42294234{
4230- return __cancel_work_sync (work , false );
4235+ return __cancel_work_sync (work , 0 );
42314236}
42324237EXPORT_SYMBOL_GPL (cancel_work_sync );
42334238
@@ -4249,7 +4254,7 @@ EXPORT_SYMBOL_GPL(cancel_work_sync);
42494254 */
42504255bool cancel_delayed_work (struct delayed_work * dwork )
42514256{
4252- return __cancel_work (& dwork -> work , true );
4257+ return __cancel_work (& dwork -> work , WORK_CANCEL_DELAYED );
42534258}
42544259EXPORT_SYMBOL (cancel_delayed_work );
42554260
@@ -4264,7 +4269,7 @@ EXPORT_SYMBOL(cancel_delayed_work);
42644269 */
42654270bool cancel_delayed_work_sync (struct delayed_work * dwork )
42664271{
4267- return __cancel_work_sync (& dwork -> work , true );
4272+ return __cancel_work_sync (& dwork -> work , WORK_CANCEL_DELAYED );
42684273}
42694274EXPORT_SYMBOL (cancel_delayed_work_sync );
42704275
0 commit comments