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

Commit a06a9ff8 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Check atomics in shared memory are lock free"

parents 530e86d9 2ceb320e
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.