diff options
author | Rob Herring <robh@kernel.org> | 2014-01-17 16:01:27 -0600 |
---|---|---|
committer | Rob Herring <robh@kernel.org> | 2014-01-17 16:01:27 -0600 |
commit | 361128fcbf30f590a05c8e8789155364f37367db (patch) | |
tree | 7f7973599e286dfd48ea724a5b7fb4bca76b294e /drivers/tty/tty_ldsem.c | |
parent | e2897d7e0b0460dca91b52d55ce41c888363502d (diff) | |
parent | 482c43419fc204b4b658fa4acb80cd502e5fcbac (diff) | |
download | linux-361128fcbf30f590a05c8e8789155364f37367db.tar.bz2 |
Merge remote-tracking branch 'grant/devicetree/next' into for-3.14
Diffstat (limited to 'drivers/tty/tty_ldsem.c')
-rw-r--r-- | drivers/tty/tty_ldsem.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/drivers/tty/tty_ldsem.c b/drivers/tty/tty_ldsem.c index 22fad8ad5ac2..d8a55e87877f 100644 --- a/drivers/tty/tty_ldsem.c +++ b/drivers/tty/tty_ldsem.c @@ -86,11 +86,21 @@ static inline long ldsem_atomic_update(long delta, struct ld_semaphore *sem) return atomic_long_add_return(delta, (atomic_long_t *)&sem->count); } +/* + * ldsem_cmpxchg() updates @*old with the last-known sem->count value. + * Returns 1 if count was successfully changed; @*old will have @new value. + * Returns 0 if count was not changed; @*old will have most recent sem->count + */ static inline int ldsem_cmpxchg(long *old, long new, struct ld_semaphore *sem) { - long tmp = *old; - *old = atomic_long_cmpxchg(&sem->count, *old, new); - return *old == tmp; + long tmp = atomic_long_cmpxchg(&sem->count, *old, new); + if (tmp == *old) { + *old = new; + return 1; + } else { + *old = tmp; + return 0; + } } /* |