Add another constructor to MQDescriptor.
The new constructor for MQDescriptor will create
a default GrantorDescriptor with fdIndex for all
grantors set to 0 and contiguous offsets.
Bug: 31710802
Test: Built and run all existing FMQ unit tests
and benchmarks.
Change-Id: Ic4ad707917bf37be2a44c65c1b101ee2bd1e2290
diff --git a/MQDescriptor.cpp b/MQDescriptor.cpp
index e768589..d620512 100644
--- a/MQDescriptor.cpp
+++ b/MQDescriptor.cpp
@@ -39,6 +39,32 @@
}
}
+MQDescriptor::MQDescriptor(size_t bufferSize, native_handle_t *nHandle,
+ int32_t flags, size_t messageSize)
+ : mHandle(nHandle), mQuantum(messageSize), mFlags(flags) {
+ mGrantors.resize(kMinGrantorCount);
+ /*
+ * Create a default grantor descriptor for read, write pointers and
+ * the data buffer. fdIndex parameter is set to 0 by default and
+ * the offset for each grantor is contiguous.
+ */
+ mGrantors[READPTRPOS] = {
+ 0 /* grantor flags */, 0 /* fdIndex */, 0 /* offset */,
+ sizeof(RingBufferPosition) /* extent */
+ };
+
+ mGrantors[WRITEPTRPOS] = {
+ 0 /* grantor flags */,
+ 0 /* fdIndex */,
+ sizeof(RingBufferPosition) /* offset */,
+ sizeof(RingBufferPosition) /* extent */
+ };
+ mGrantors[DATAPTRPOS] = {
+ 0 /* grantor flags */, 0 /* fdIndex */,
+ 2 * sizeof(RingBufferPosition) /* offset */, bufferSize /* extent */
+ };
+}
+
MQDescriptor::MQDescriptor(const MQDescriptor &other)
: mGrantors(other.mGrantors),
mHandle(nullptr),
diff --git a/include/hidl/MQDescriptor.h b/include/hidl/MQDescriptor.h
index 327b61c..c01a902 100644
--- a/include/hidl/MQDescriptor.h
+++ b/include/hidl/MQDescriptor.h
@@ -25,19 +25,22 @@
namespace android {
namespace hardware {
+typedef uint64_t RingBufferPosition;
+
struct GrantorDescriptor {
uint32_t flags;
uint32_t fdIndex;
uint32_t offset;
- uint32_t extent;
+ size_t extent;
};
-enum GrantorType : int { READPTRPOS = 0, WRITEPTRPOS, DATAPTRPOS };
-
struct MQDescriptor {
MQDescriptor(
const std::vector<GrantorDescriptor>& grantors,
- native_handle_t* nhandle, int32_t flags, size_t size);
+ native_handle_t* nHandle, int32_t flags, size_t size);
+
+ MQDescriptor(size_t bufferSize, native_handle_t* nHandle, int32_t flags,
+ size_t messageSize);
~MQDescriptor();
@@ -64,6 +67,12 @@
size_t countGrantors() const { return mGrantors.size(); }
std::vector<GrantorDescriptor> getGrantors() const;
const sp<NativeHandle> getNativeHandle() const;
+ /*
+ * There should atleast be GrantorDescriptors for the read counter, write
+ * counter and data buffer.
+ */
+ static constexpr int32_t kMinGrantorCount = 3;
+ enum GrantorType : int { READPTRPOS = 0, WRITEPTRPOS, DATAPTRPOS };
private:
::android::hardware::hidl_vec<GrantorDescriptor> mGrantors;