if (atomic_cmpxchg(&cdata..., version) == 0) return 0; // we were first! return -EPERM; // somebody has changed the version before us! > > > > Shouldn't be rather > > > > > > > > if (atomic_cmpxchg() == 0) { > > > > if (atomic_read() != version) > > > > ...
> > if (atomic_cmpxchg(&cdata..., version) == 0) > > return 0; // we were first! > > return -EPERM; // somebody has changed the version before us! > > > > Which can fail if two callers are requesting the same version - in a > race the second one will get a fail - ...