### Function

# GLib atomic_pointer_exchange

since: 2.74

#### Declaration [src]

    gpointer
    g_atomic_pointer_exchange (
      void* atomic,
      gpointer newval
    )

#### Description [src]

Sets the `atomic` to `newval` and returns the old value from `atomic`.

This exchange is done atomically.

Think of this operation as an atomic version of `{ tmp = *atomic; *atomic = val; return tmp; }`.

This call acts as a full compiler and hardware memory barrier.

Available since: 2.74

#### Parameters

`atomic`

  Type: `void*`

  A pointer to a #gpointer-sized value.

  The argument can be `NULL`.
  The data is owned by the caller of the function.

`newval`

  Type: `gpointer`

  The value to replace with.

  The argument can be `NULL`.
  The data is owned by the caller of the function.

#### Return value

Type: `gpointer`

The value of `atomic` before the exchange.

The data is owned by the called function.
The return value can be `NULL`.