Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atomic operations on pointers #22887

Closed
nordic-krch opened this issue Feb 18, 2020 · 1 comment · Fixed by #22915
Closed

Atomic operations on pointers #22887

nordic-krch opened this issue Feb 18, 2020 · 1 comment · Fixed by #22915
Assignees
Labels
area: Kernel Feature Request A request for a new feature

Comments

@nordic-krch
Copy link
Contributor

Is your feature request related to a problem? Please describe.

Currently atomic_t in atomic.h is set as int. On 32 bit platforms it is then ok to use it with pointers since they are the same size but not on 64 bit platforms. Code like:

int *p = (int *)0x12348985679890;
bool res = atomic_cas((atomic_t *)&p, (atomic_val_t)p, 0);

compiles with warning on qemu_x86_64 and sets to 0 only bottom 32 bits and returns true.

On the other hand using __atomic_compare_exchange_n directly works fine for pointers and integers.

I intend to use atomic_cas with pointers to locklessly control access to a module which has callback (if callback is set module is busy) and it cannot be done right now for 64 bit platforms. Something like:

if (atomic_cas(&obj->callback, NULL, callback) == false) {
  return -EBUSY;
}

Describe the solution you'd l`ike

Create atomic_ptr_t type and set of atomic_ptr_cas(), atomic_ptr_set(), atomic_ptr_get() and atomic_ptr_clear() functions.

@nordic-krch nordic-krch added the Feature Request A request for a new feature label Feb 18, 2020
@andrewboie
Copy link
Contributor

We'll need this for #15138 as well

Where this gets annoying is the platforms that implement their own atomic ops using custom assembly.

I wonder if we could just change atomic_t to uintptr_t instead of int

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Kernel Feature Request A request for a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants