Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0e0358d9 authored by Ryan Prichard's avatar Ryan Prichard Committed by Android (Google) Code Review
Browse files

Merge "Use <atomic> instead of <stdatomic.h>" into main

parents c71357fb 6b06d8ec
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@
#include <utils/Log.h>

// not needed with the includes above, added to prevent transitive include dependency.
#include <atomic>
#include <chrono>
#include <thread>
#include <string_view>
@@ -3959,8 +3960,8 @@ audio_unique_id_t AudioFlinger::nextUniqueId(audio_unique_id_use_t use)
    const int maxRetries = use == AUDIO_UNIQUE_ID_USE_SESSION ? 3 : 1;
    for (int retry = 0; retry < maxRetries; retry++) {
        // The cast allows wraparound from max positive to min negative instead of abort
        uint32_t base = (uint32_t) atomic_fetch_add_explicit(&mNextUniqueIds[use],
                (uint_fast32_t) AUDIO_UNIQUE_ID_USE_MAX, memory_order_acq_rel);
        uint32_t base = (uint32_t) mNextUniqueIds[use].fetch_add(
                (uint_fast32_t) AUDIO_UNIQUE_ID_USE_MAX, std::memory_order_acq_rel);
        ALOG_ASSERT(audio_unique_id_get_use(base) == AUDIO_UNIQUE_ID_USE_UNSPECIFIED);
        // allow wrap by skipping 0 and -1 for session ids
        if (!(base == 0 || base == (~0u & ~AUDIO_UNIQUE_ID_USE_MASK))) {
+1 −1
Original line number Diff line number Diff line
@@ -699,7 +699,7 @@ private:
    std::map<pid_t, sp<NotificationClient>> mNotificationClients GUARDED_BY(clientMutex());

                // updated by atomic_fetch_add_explicit
    volatile atomic_uint_fast32_t mNextUniqueIds[AUDIO_UNIQUE_ID_USE_MAX];  // ctor init
    std::atomic<uint_fast32_t> mNextUniqueIds[AUDIO_UNIQUE_ID_USE_MAX];  // ctor init

    std::atomic<audio_mode_t> mMode = AUDIO_MODE_INVALID;
    std::atomic<bool> mBtNrecIsOff = false;
+2 −3
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@

#include "Configuration.h"
#include <time.h>
#include <cutils/atomic.h>
#include <utils/Log.h>
#include "StateQueue.h"

@@ -42,7 +41,7 @@ void StateQueueMutatorDump::dump(int fd)

template<typename T> const T* StateQueue<T>::poll()
{
    const T *next = (const T *) atomic_load_explicit(&mNext, memory_order_acquire);
    const T *next = (const T *) mNext.load(std::memory_order_acquire);

    if (next != mCurrent) {
        mAck = next;    // no additional barrier needed
@@ -125,7 +124,7 @@ template<typename T> bool StateQueue<T>::push(StateQueue<T>::block_t block)
        }

        // publish
        atomic_store_explicit(&mNext, (uintptr_t)mMutating, memory_order_release);
        mNext.store((uintptr_t)mMutating, std::memory_order_release);
        mExpecting = mMutating;

        // copy with circular wraparound
+2 −2
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

#pragma once

#include <stdatomic.h>
#include <atomic>

// The state queue template class was originally driven by this use case / requirements:
//  There are two threads: a fast mixer, and a normal mixer, and they share state.
@@ -185,7 +185,7 @@ private:
    T                 mStates[kN];      // written by mutator, read by observer

    // "volatile" is meaningless with SMP, but here it indicates that we're using atomic ops
    atomic_uintptr_t  mNext{}; // written by mutator to advance next, read by observer
    std::atomic<uintptr_t> mNext{};    // written by mutator to advance next, read by observer
    volatile const T* mAck = nullptr;  // written by observer to acknowledge advance of next,
                                       // read by mutator