Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 2914
b: refs/heads/master
c: fd450b7
h: refs/heads/master
v: v3
  • Loading branch information
Oleg Nesterov authored and Linus Torvalds committed Jun 23, 2005
1 parent 87f27c5 commit 8fbf4cd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 55c888d6d09a0df236adfaf8ccf06ff5d0646775
refs/heads/master: fd450b7318b75343fd76b3d95416853e34e72c95
4 changes: 3 additions & 1 deletion trunk/include/linux/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ static inline void add_timer(struct timer_list * timer)
}

#ifdef CONFIG_SMP
extern int try_to_del_timer_sync(struct timer_list *timer);
extern int del_timer_sync(struct timer_list *timer);
#else
# define del_timer_sync(t) del_timer(t)
# define try_to_del_timer_sync(t) del_timer(t)
# define del_timer_sync(t) del_timer(t)
#endif

#define del_singleshot_timer_sync(t) del_timer_sync(t)
Expand Down
53 changes: 33 additions & 20 deletions trunk/kernel/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,34 @@ int del_timer(struct timer_list *timer)
EXPORT_SYMBOL(del_timer);

#ifdef CONFIG_SMP
/*
* This function tries to deactivate a timer. Upon successful (ret >= 0)
* exit the timer is not queued and the handler is not running on any CPU.
*
* It must not be called from interrupt contexts.
*/
int try_to_del_timer_sync(struct timer_list *timer)
{
timer_base_t *base;
unsigned long flags;
int ret = -1;

base = lock_timer_base(timer, &flags);

if (base->running_timer == timer)
goto out;

ret = 0;
if (timer_pending(timer)) {
detach_timer(timer, 1);
ret = 1;
}
out:
spin_unlock_irqrestore(&base->lock, flags);

return ret;
}

/***
* del_timer_sync - deactivate a timer and wait for the handler to finish.
* @timer: the timer to be deactivated
Expand All @@ -384,28 +412,13 @@ EXPORT_SYMBOL(del_timer);
*/
int del_timer_sync(struct timer_list *timer)
{
timer_base_t *base;
unsigned long flags;
int ret = -1;

check_timer(timer);

do {
base = lock_timer_base(timer, &flags);

if (base->running_timer == timer)
goto unlock;

ret = 0;
if (timer_pending(timer)) {
detach_timer(timer, 1);
ret = 1;
}
unlock:
spin_unlock_irqrestore(&base->lock, flags);
} while (ret < 0);

return ret;
for (;;) {
int ret = try_to_del_timer_sync(timer);
if (ret >= 0)
return ret;
}
}

EXPORT_SYMBOL(del_timer_sync);
Expand Down

0 comments on commit 8fbf4cd

Please sign in to comment.