lkml.org 
[lkml]   [2019]   [Apr]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v4 11/16] locking/rwsem: Enable readers spinning on writer
On Sat, Apr 13, 2019 at 01:22:54PM -0400, Waiman Long wrote:
> +/*
> + * Try to acquire read lock before the reader is put on wait queue.
> + * Lock acquisition isn't allowed if the rwsem is locked or a writer handoff
> + * is ongoing.
> + */
> +static inline bool rwsem_try_read_lock_unqueued(struct rw_semaphore *sem)
> +{
> + long count = atomic_long_read(&sem->count);
> +
> + if (RWSEM_COUNT_WLOCKED_OR_HANDOFF(count))
> + return false;
> +
> + count = atomic_long_fetch_add_acquire(RWSEM_READER_BIAS, &sem->count);
> + if (!RWSEM_COUNT_WLOCKED_OR_HANDOFF(count)) {
> + rwsem_set_reader_owned(sem);
> + lockevent_inc(rwsem_opt_rlock);
> + return true;
> + }
> +
> + /* Back out the change */
> + atomic_long_add(-RWSEM_READER_BIAS, &sem->count);
> + return false;
> +}

Doesn't a cmpxchg 'loop' make more sense here?

\
 
 \ /
  Last update: 2019-04-17 15:59    [W:0.423 / U:0.264 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site