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

Commit 2ceb320e authored by Tianyu Jiang's avatar Tianyu Jiang
Browse files

Check atomics in shared memory are lock free

when they are created in bufferhub server side in BufferNode, and client
side in BufferHubBuffer.

Fix: 117849512
Test: BufferHub_test BufferHubServer_test

Change-Id: Ifc5b681a6a86fa02cb598b33bf68dfefc07a76f9
parent 49c55bb8
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -169,6 +169,13 @@ int BufferHubBuffer::ImportGraphicBuffer() {
    buffer_state_ = &metadata_header->buffer_state;
    fence_state_ = &metadata_header->fence_state;
    active_clients_bit_mask_ = &metadata_header->active_clients_bit_mask;
    // The C++ standard recommends (but does not require) that lock-free atomic operations are
    // also address-free, that is, suitable for communication between processes using shared
    // memory.
    LOG_ALWAYS_FATAL_IF(!std::atomic_is_lock_free(buffer_state_) ||
                                !std::atomic_is_lock_free(fence_state_) ||
                                !std::atomic_is_lock_free(active_clients_bit_mask_),
                        "Atomic variables in ashmen are not lock free.");

    // Import the buffer: We only need to hold on the native_handle_t here so that
    // GraphicBuffer instance can be created in future.
+8 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

#include <bufferhub/BufferHubService.h>
#include <bufferhub/BufferNode.h>
#include <log/log.h>
#include <ui/GraphicBufferAllocator.h>

namespace android {
@@ -18,6 +19,13 @@ void BufferNode::InitializeMetadata() {
    fence_state_ = new (&metadata_header->fence_state) std::atomic<uint32_t>(0);
    active_clients_bit_mask_ =
            new (&metadata_header->active_clients_bit_mask) std::atomic<uint32_t>(0);
    // The C++ standard recommends (but does not require) that lock-free atomic operations are
    // also address-free, that is, suitable for communication between processes using shared
    // memory.
    LOG_ALWAYS_FATAL_IF(!std::atomic_is_lock_free(buffer_state_) ||
                                !std::atomic_is_lock_free(fence_state_) ||
                                !std::atomic_is_lock_free(active_clients_bit_mask_),
                        "Atomic variables in ashmen are not lock free.");
}

// Allocates a new BufferNode.