diff options
-rw-r--r-- | include/linux/workqueue.h | 17 | ||||
-rw-r--r-- | kernel/workqueue.c | 30 |
2 files changed, 31 insertions, 16 deletions
diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h index d86b320319e0..4898289564ab 100644 --- a/include/linux/workqueue.h +++ b/include/linux/workqueue.h | |||
@@ -420,6 +420,7 @@ extern bool flush_work(struct work_struct *work); | |||
420 | extern bool cancel_work_sync(struct work_struct *work); | 420 | extern bool cancel_work_sync(struct work_struct *work); |
421 | 421 | ||
422 | extern bool flush_delayed_work(struct delayed_work *dwork); | 422 | extern bool flush_delayed_work(struct delayed_work *dwork); |
423 | extern bool cancel_delayed_work(struct delayed_work *dwork); | ||
423 | extern bool cancel_delayed_work_sync(struct delayed_work *dwork); | 424 | extern bool cancel_delayed_work_sync(struct delayed_work *dwork); |
424 | 425 | ||
425 | extern void workqueue_set_max_active(struct workqueue_struct *wq, | 426 | extern void workqueue_set_max_active(struct workqueue_struct *wq, |
@@ -429,22 +430,6 @@ extern unsigned int work_cpu(struct work_struct *work); | |||
429 | extern unsigned int work_busy(struct work_struct *work); | 430 | extern unsigned int work_busy(struct work_struct *work); |
430 | 431 | ||
431 | /* | 432 | /* |
432 | * Kill off a pending schedule_delayed_work(). Note that the work callback | ||
433 | * function may still be running on return from cancel_delayed_work(), unless | ||
434 | * it returns 1 and the work doesn't re-arm itself. Run flush_workqueue() or | ||
435 | * cancel_work_sync() to wait on it. | ||
436 | */ | ||
437 | static inline bool cancel_delayed_work(struct delayed_work *work) | ||
438 | { | ||
439 | bool ret; | ||
440 | |||
441 | ret = del_timer_sync(&work->timer); | ||
442 | if (ret) | ||
443 | work_clear_pending(&work->work); | ||
444 | return ret; | ||
445 | } | ||
446 | |||
447 | /* | ||
448 | * Like above, but uses del_timer() instead of del_timer_sync(). This means, | 433 | * Like above, but uses del_timer() instead of del_timer_sync(). This means, |
449 | * if it returns 0 the timer function may be running and the queueing is in | 434 | * if it returns 0 the timer function may be running and the queueing is in |
450 | * progress. | 435 | * progress. |
diff --git a/kernel/workqueue.c b/kernel/workqueue.c index b394df8beaee..039d0fae171a 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c | |||
@@ -2949,6 +2949,36 @@ bool flush_delayed_work(struct delayed_work *dwork) | |||
2949 | EXPORT_SYMBOL(flush_delayed_work); | 2949 | EXPORT_SYMBOL(flush_delayed_work); |
2950 | 2950 | ||
2951 | /** | 2951 | /** |
2952 | * cancel_delayed_work - cancel a delayed work | ||
2953 | * @dwork: delayed_work to cancel | ||
2954 | * | ||
2955 | * Kill off a pending delayed_work. Returns %true if @dwork was pending | ||
2956 | * and canceled; %false if wasn't pending. Note that the work callback | ||
2957 | * function may still be running on return, unless it returns %true and the | ||
2958 | * work doesn't re-arm itself. Explicitly flush or use | ||
2959 | * cancel_delayed_work_sync() to wait on it. | ||
2960 | * | ||
2961 | * This function is safe to call from any context including IRQ handler. | ||
2962 | */ | ||
2963 | bool cancel_delayed_work(struct delayed_work *dwork) | ||
2964 | { | ||
2965 | unsigned long flags; | ||
2966 | int ret; | ||
2967 | |||
2968 | do { | ||
2969 | ret = try_to_grab_pending(&dwork->work, true, &flags); | ||
2970 | } while (unlikely(ret == -EAGAIN)); | ||
2971 | |||
2972 | if (unlikely(ret < 0)) | ||
2973 | return false; | ||
2974 | |||
2975 | set_work_cpu_and_clear_pending(&dwork->work, work_cpu(&dwork->work)); | ||
2976 | local_irq_restore(flags); | ||
2977 | return true; | ||
2978 | } | ||
2979 | EXPORT_SYMBOL(cancel_delayed_work); | ||
2980 | |||
2981 | /** | ||
2952 | * cancel_delayed_work_sync - cancel a delayed work and wait for it to finish | 2982 | * cancel_delayed_work_sync - cancel a delayed work and wait for it to finish |
2953 | * @dwork: the delayed work cancel | 2983 | * @dwork: the delayed work cancel |
2954 | * | 2984 | * |