diff options
author | Devin Moore <devinmoore@google.com> | 2020-08-17 20:17:09 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-08-17 20:17:09 +0000 |
commit | 215a30b8baa628531d1d8f1374ce1470f835d182 (patch) | |
tree | 82aac13435b679fc8035f5d85e7e303e2182eb11 | |
parent | d73a30e86efefe27ef5b67c907287d38ed612d44 (diff) | |
parent | f9893e8017114796e6e94756cfebee8270548ed0 (diff) | |
download | platform_system_libhidl-215a30b8baa628531d1d8f1374ce1470f835d182.tar.gz platform_system_libhidl-215a30b8baa628531d1d8f1374ce1470f835d182.tar.bz2 platform_system_libhidl-215a30b8baa628531d1d8f1374ce1470f835d182.zip |
Move definition of MessageQueue flavor to libfmq-base am: f9893e8017
Original change: https://android-review.googlesource.com/c/platform/system/libhidl/+/1370777
Change-Id: If72b6ee6b9ed6d4404d4a87d3a362440dc465a92
-rw-r--r-- | Android.bp | 7 | ||||
-rw-r--r-- | base/include/hidl/MQDescriptor.h | 82 |
2 files changed, 22 insertions, 67 deletions
@@ -158,6 +158,13 @@ cc_defaults { "transport/include", ], + header_libs: [ + "libfmq-base", + ], + export_header_lib_headers: [ + "libfmq-base", + ], + generated_sources: [ "android.hidl.manager@1.0_genc++", "android.hidl.manager@1.1_genc++", diff --git a/base/include/hidl/MQDescriptor.h b/base/include/hidl/MQDescriptor.h index eb244e57..6a0bc257 100644 --- a/base/include/hidl/MQDescriptor.h +++ b/base/include/hidl/MQDescriptor.h @@ -20,14 +20,13 @@ #include <unistd.h> #include <cutils/native_handle.h> +#include <fmq/MQDescriptorBase.h> #include <hidl/HidlInternal.h> #include <hidl/HidlSupport.h> namespace android { namespace hardware { -typedef uint64_t RingBufferPosition; - struct GrantorDescriptor { uint32_t flags __attribute__ ((aligned(4))); uint32_t fdIndex __attribute__ ((aligned(4))); @@ -42,21 +41,6 @@ static_assert(offsetof(GrantorDescriptor, extent) == 16, "wrong offset"); static_assert(sizeof(GrantorDescriptor) == 24, "wrong size"); static_assert(__alignof(GrantorDescriptor) == 8, "wrong alignment"); -enum MQFlavor : uint32_t { - /* - * kSynchronizedReadWrite represents the wait-free synchronized flavor of the - * FMQ. It is intended to be have a single reader and single writer. - * Attempts to overflow/underflow returns a failure. - */ - kSynchronizedReadWrite = 0x01, - /* - * kUnsynchronizedWrite represents the flavor of FMQ where writes always - * succeed. This flavor allows one writer and many readers. A read operation - * can detect an overwrite and reset the read counter. - */ - kUnsynchronizedWrite = 0x02 -}; - template <typename T, MQFlavor flavor> struct MQDescriptor { // Takes ownership of handle @@ -87,6 +71,8 @@ struct MQDescriptor { return mGrantors; } + // This should be removed if no one is using it. We shouldn't be returning + // a mutable reference if it's not necessary. TODO(b/162465295). inline ::android::hardware::hidl_vec<GrantorDescriptor> &grantors() { return mGrantors; } @@ -101,42 +87,7 @@ struct MQDescriptor { static const size_t kOffsetOfGrantors; static const size_t kOffsetOfHandle; - enum GrantorType : int { READPTRPOS = 0, WRITEPTRPOS, DATAPTRPOS, EVFLAGWORDPOS }; - - /* - * There should at least be GrantorDescriptors for the read counter, write - * counter and data buffer. A GrantorDescriptor for an EventFlag word is - * not required if there is no need for blocking FMQ operations. - */ - static constexpr int32_t kMinGrantorCount = DATAPTRPOS + 1; - - /* - * Minimum number of GrantorDescriptors required if EventFlag support is - * needed for blocking FMQ operations. - */ - static constexpr int32_t kMinGrantorCountForEvFlagSupport = EVFLAGWORDPOS + 1; - //TODO(b/34160777) Identify a better solution that supports remoting. - static inline size_t alignToWordBoundary(size_t length) { - constexpr size_t kAlignmentSize = 64; - if (kAlignmentSize % __WORDSIZE != 0) { - details::logAlwaysFatal("Incompatible word size"); - } - - /* - * Check if alignment to word boundary would cause an overflow. - */ - if (length > SIZE_MAX - kAlignmentSize/8 + 1) { - details::logAlwaysFatal("Queue size too large"); - } - - return (length + kAlignmentSize/8 - 1) & ~(kAlignmentSize/8 - 1U); - } - - static inline size_t isAlignedToWordBoundary(size_t offset) { - constexpr size_t kAlignmentSize = 64; - return (offset & (kAlignmentSize/8 - 1)) == 0; - } private: ::android::hardware::hidl_vec<GrantorDescriptor> mGrantors; ::android::hardware::details::hidl_pointer<native_handle_t> mHandle; @@ -170,9 +121,6 @@ MQDescriptor<T, flavor>::MQDescriptor(const std::vector<GrantorDescriptor>& gran : mHandle(nhandle), mQuantum(static_cast<uint32_t>(size)), mFlags(flavor) { mGrantors.resize(grantors.size()); for (size_t i = 0; i < grantors.size(); ++i) { - if (isAlignedToWordBoundary(grantors[i].offset) == false) { - details::logAlwaysFatal("Grantor offsets need to be aligned"); - } mGrantors[i] = grantors[i]; } } @@ -185,13 +133,16 @@ MQDescriptor<T, flavor>::MQDescriptor(size_t bufferSize, native_handle_t* nHandl * If configureEventFlag is true, allocate an additional spot in mGrantor * for containing the fd and offset for mmapping the EventFlag word. */ - mGrantors.resize(configureEventFlag? kMinGrantorCountForEvFlagSupport : kMinGrantorCount); + mGrantors.resize(configureEventFlag ? details::kMinGrantorCountForEvFlagSupport + : details::kMinGrantorCount); size_t memSize[] = { - sizeof(RingBufferPosition), /* memory to be allocated for read pointer counter */ - sizeof(RingBufferPosition), /* memory to be allocated for write pointer counter */ - bufferSize, /* memory to be allocated for data buffer */ - sizeof(std::atomic<uint32_t>)/* memory to be allocated for EventFlag word */ + sizeof(details::RingBufferPosition), /* memory to be allocated for read pointer counter + */ + sizeof(details::RingBufferPosition), /* memory to be allocated for write pointer counter + */ + bufferSize, /* memory to be allocated for data buffer */ + sizeof(std::atomic<uint32_t>) /* memory to be allocated for EventFlag word */ }; /* @@ -202,12 +153,9 @@ MQDescriptor<T, flavor>::MQDescriptor(size_t bufferSize, native_handle_t* nHandl for (size_t grantorPos = 0, offset = 0; grantorPos < mGrantors.size(); offset += memSize[grantorPos++]) { - mGrantors[grantorPos] = { - 0 /* grantor flags */, - 0 /* fdIndex */, - static_cast<uint32_t>(alignToWordBoundary(offset)), - memSize[grantorPos] - }; + mGrantors[grantorPos] = {0 /* grantor flags */, 0 /* fdIndex */, + static_cast<uint32_t>(details::alignToWordBoundary(offset)), + memSize[grantorPos]}; } } @@ -253,7 +201,7 @@ MQDescriptor<T, flavor>::~MQDescriptor() { template<typename T, MQFlavor flavor> size_t MQDescriptor<T, flavor>::getSize() const { - return static_cast<size_t>(mGrantors[DATAPTRPOS].extent); + return static_cast<size_t>(mGrantors[details::DATAPTRPOS].extent); } template<typename T, MQFlavor flavor> |