Skip to content

Commit

Permalink
Improve atomic_{load,store} documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
dalg24 committed Oct 16, 2024
1 parent 24e2330 commit 2232e7e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
19 changes: 12 additions & 7 deletions docs/source/API/core/atomics/atomic_load.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,27 @@
.. role:: cppkokkos(code)
:language: cppkokkos

Header File: ``<Kokkos_Core.hpp>``
Defined in header ``<Kokkos_Atomic.hpp>`` which is included from ``<Kokkos_Core.hpp>``

Usage
-----

.. code-block:: cpp
value = atomic_load(ptr_to_value);
auto current = atomic_load(&obj);
Atomically reads the value at the address given by ``ptr_to_value``.
Atomically obtains ``obj``'s value.

Description
-----------

.. cppkokkos:function:: template<class T> T atomic_load(T* const ptr_to_value);
.. cppkokkos:function:: template<class T> T atomic_load(T* ptr);
Atomically executes ``value = *ptr_to_value; return value;``.
* ``ptr_to_value``: address of the to be updated value.
* ``value``: value at address ``ptr_to_value``.
Atomically reads the content of ``*ptr`` and returns it (``T val = *ptr; return val;``).

- ``ptr``: address of the object whose current value is to be returned.

See also
--------
* `atomic_store <atomic_store.html>`_: atomically replaces the value of the referenced object with a non-atomic argument
* `atomic_exchange <atomic_exchange.html>`_: atomically replaces the value of the referenced object and obtains the value held previously
20 changes: 13 additions & 7 deletions docs/source/API/core/atomics/atomic_store.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,30 @@
.. role:: cppkokkos(code)
:language: cppkokkos

Header File: ``<Kokkos_Core.hpp>``
Defined in header ``<Kokkos_Atomic.hpp>`` which is included from ``<Kokkos_Core.hpp>``

Usage
-----

.. code-block:: cpp
atomic_store(ptr_to_value,new_value);
atomic_store(&obj, desired);
Atomically sets the value at the address given by ``ptr_to_value`` to ``new_value``.
Atomically replaces ``obj``'s value with ``desired``.

Description
-----------

.. cppkokkos:function:: template<class T> void atomic_store(T* const ptr_to_value, const T new_value);
.. cppkokkos:function:: template<class T> void atomic_store(T* ptr, std::identity_type_t<T> val);
Atomically executes ``*ptr_to_value = new_value;``.
Atomically writes ``val`` into ``*ptr`` (``*ptr = val;``).

- ``ptr_to_value``: address of the to be updated value.
- ``ptr``: address of the object whose value is to be replaced.

- ``new_value``: new value.
- ``val``: value to store in the referenced object.


See also
--------
* `atomic_load <atomic_load.html>`_: atomically obtains the value of the referenced object
* `atomic_exchange <atomic_exchange.html>`_: atomically replaces the value of the referenced object and obtains the value held previously

0 comments on commit 2232e7e

Please sign in to comment.