lkml.org 
[lkml]   [2015]   [Feb]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
SubjectRe: [PATCH 6/7 linux-next] wan: cosa: replace current->state by set_current_state()
From
Date
On Fri, 2015-02-20 at 19:58 +0100, Peter Zijlstra wrote:
> On Fri, Feb 20, 2015 at 09:34:28PM +0300, Sergei Shtylyov wrote:
> > Hello.
> >
> > On 02/20/2015 09:12 PM, Fabian Frederick wrote:
> >
> > >Use helper functions to access current->state.
> > >Direct assignments are prone to races and therefore buggy.
> >
> > >current->state = TASK_RUNNING is replaced by __set_current_state()
> >
> > You sometimes use __set_current_state() and sometimes set_current_state().
>
> It depends on which state; setting yourself TASK_RUNNING is free of
> wakeup races -- you're already running after all, so it can safely use
> __set_current_state().

Maybe this might be self documented in set_current_state(),
as we have about 120 calls to __set_current_state(TASK_RUNNING)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 41c60e5302d7..26133da6445e 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -275,7 +275,11 @@ extern char ___assert_task_state[1 - 2*!!(
#define set_current_state(state_value) \
do { \
current->task_state_change = _THIS_IP_; \
- set_mb(current->state, (state_value)); \
+ if (__builtin_constant_p(state_value) && \
+ (state_value) == TASK_RUNNING) \
+ current->state = (state_value); \
+ else \
+ set_mb(current->state, (state_value)); \
} while (0)

#else




\
 
 \ /
  Last update: 2015-02-20 21:01    [W:0.918 / U:0.556 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site