Use templatized MQDescriptor
Test: Fmq unit tests and benchmarks
Bug: 33948735
Merged-In: Ie4adcd8885a0e1b9132b63a68f65380bdb38a19b
Change-Id: Ie4adcd8885a0e1b9132b63a68f65380bdb38a19b
diff --git a/benchmarks/msgq_benchmark_client.cpp b/benchmarks/msgq_benchmark_client.cpp
index 81c379d..06433cd 100644
--- a/benchmarks/msgq_benchmark_client.cpp
+++ b/benchmarks/msgq_benchmark_client.cpp
@@ -76,7 +76,8 @@
/*
* Request service to configure the client inbox queue.
*/
- service->configureClientInboxSyncReadWrite([this](bool ret, const MQDescriptorSync& in) {
+ service->configureClientInboxSyncReadWrite([this](bool ret,
+ const MQDescriptorSync<uint8_t>& in) {
ASSERT_TRUE(ret);
mFmqInbox = new (std::nothrow) MessageQueue<uint8_t, kSynchronizedReadWrite>(in);
});
@@ -86,7 +87,8 @@
/*
* Reqeust service to configure the client outbox queue.
*/
- service->configureClientOutboxSyncReadWrite([this](bool ret, const MQDescriptorSync& out) {
+ service->configureClientOutboxSyncReadWrite([this](bool ret,
+ const MQDescriptorSync<uint8_t>& out) {
ASSERT_TRUE(ret);
mFmqOutbox = new (std::nothrow) MessageQueue<uint8_t,
kSynchronizedReadWrite>(out);
diff --git a/benchmarks/msgq_benchmark_service.cpp b/benchmarks/msgq_benchmark_service.cpp
index 1dd5c94..8f57592 100644
--- a/benchmarks/msgq_benchmark_service.cpp
+++ b/benchmarks/msgq_benchmark_service.cpp
@@ -184,7 +184,7 @@
mFmqInbox = new (std::nothrow) android::hardware::MessageQueue<uint8_t,
kSynchronizedReadWrite>(kNumElementsInQueue);
if ((mFmqInbox == nullptr) || (mFmqInbox->isValid() == false)) {
- callback(false /* ret */, android::hardware::MQDescriptorSync(
+ callback(false /* ret */, android::hardware::MQDescriptorSync<uint8_t>(
std::vector<android::hardware::GrantorDescriptor>(),
nullptr /* nhandle */, 0 /* size */));
} else {
@@ -203,7 +203,7 @@
mFmqOutbox = new (std::nothrow) android::hardware::MessageQueue<uint8_t,
kSynchronizedReadWrite>(kNumElementsInQueue);
if (mFmqOutbox == nullptr) {
- callback(false /* ret */, android::hardware::MQDescriptorSync(
+ callback(false /* ret */, android::hardware::MQDescriptorSync<uint8_t>(
std::vector<android::hardware::GrantorDescriptor>(),
nullptr /* nhandle */, 0 /* size */));
} else {
diff --git a/include/fmq/MessageQueue.h b/include/fmq/MessageQueue.h
index 9f5ef31..997dc7d 100644
--- a/include/fmq/MessageQueue.h
+++ b/include/fmq/MessageQueue.h
@@ -34,7 +34,7 @@
* @param resetPointers bool indicating whether the read/write pointers
* should be reset or not.
*/
- MessageQueue(const MQDescriptor<flavor>& Desc, bool resetPointers = true);
+ MessageQueue(const MQDescriptor<T, flavor>& Desc, bool resetPointers = true);
~MessageQueue();
@@ -123,7 +123,7 @@
*
* @return Pointer to the MQDescriptor associated with the FMQ.
*/
- const MQDescriptor<flavor>* getDesc() const { return mDesc.get(); }
+ const MQDescriptor<T, flavor>* getDesc() const { return mDesc.get(); }
/**
* Get a pointer to the Event Flag word if there is one associated with this FMQ.
@@ -161,7 +161,7 @@
void unmapGrantorDescr(void* address, uint32_t grantorIdx);
void initMemory(bool resetPointers);
- std::unique_ptr<MQDescriptor<flavor>> mDesc;
+ std::unique_ptr<MQDescriptor<T, flavor>> mDesc;
uint8_t* mRing = nullptr;
/*
* TODO(b/31550092): Change to 32 bit read and write pointer counters.
@@ -179,7 +179,7 @@
* the native_handle is valid and T matches quantum size.
*/
if ((mDesc == nullptr) || !mDesc->isHandleValid() ||
- (mDesc->countGrantors() < MQDescriptor<flavor>::kMinGrantorCount) ||
+ (mDesc->countGrantors() < MQDescriptor<T, flavor>::kMinGrantorCount) ||
(mDesc->getQuantum() != sizeof(T))) {
return;
}
@@ -187,7 +187,7 @@
if (flavor == kSynchronizedReadWrite) {
mReadPtr =
reinterpret_cast<std::atomic<uint64_t>*>
- (mapGrantorDescr(MQDescriptor<flavor>::READPTRPOS));
+ (mapGrantorDescr(MQDescriptor<T, flavor>::READPTRPOS));
} else {
/*
* The unsynchronized write flavor of the FMQ may have multiple readers
@@ -200,7 +200,7 @@
mWritePtr =
reinterpret_cast<std::atomic<uint64_t>*>
- (mapGrantorDescr(MQDescriptor<flavor>::WRITEPTRPOS));
+ (mapGrantorDescr(MQDescriptor<T, flavor>::WRITEPTRPOS));
CHECK(mWritePtr != nullptr);
if (resetPointers) {
@@ -212,16 +212,16 @@
}
mRing = reinterpret_cast<uint8_t*>(mapGrantorDescr
- (MQDescriptor<flavor>::DATAPTRPOS));
+ (MQDescriptor<T, flavor>::DATAPTRPOS));
CHECK(mRing != nullptr);
mEvFlagWord = static_cast<std::atomic<uint32_t>*>(
- mapGrantorDescr(MQDescriptor<flavor>::EVFLAGWORDPOS));
+ mapGrantorDescr(MQDescriptor<T, flavor>::EVFLAGWORDPOS));
}
template <typename T, MQFlavor flavor>
-MessageQueue<T, flavor>::MessageQueue(const MQDescriptor<flavor>& Desc, bool resetPointers) {
- mDesc = std::unique_ptr<MQDescriptor<flavor>>(new (std::nothrow) MQDescriptor<flavor>(Desc));
+MessageQueue<T, flavor>::MessageQueue(const MQDescriptor<T, flavor>& Desc, bool resetPointers) {
+ mDesc = std::unique_ptr<MQDescriptor<T, flavor>>(new (std::nothrow) MQDescriptor<T, flavor>(Desc));
if (mDesc == nullptr) {
return;
}
@@ -267,8 +267,8 @@
}
mqHandle->data[0] = ashmemFd;
- mDesc = std::unique_ptr<MQDescriptor<flavor>>(
- new (std::nothrow) MQDescriptor<flavor>(kQueueSizeBytes,
+ mDesc = std::unique_ptr<MQDescriptor<T, flavor>>(
+ new (std::nothrow) MQDescriptor<T, flavor>(kQueueSizeBytes,
mqHandle,
sizeof(T),
configureEventFlagWord));
@@ -283,12 +283,12 @@
if (flavor == kUnsynchronizedWrite) {
delete mReadPtr;
} else {
- unmapGrantorDescr(mReadPtr, MQDescriptor<flavor>::READPTRPOS);
+ unmapGrantorDescr(mReadPtr, MQDescriptor<T, flavor>::READPTRPOS);
}
if (mWritePtr) unmapGrantorDescr(mWritePtr,
- MQDescriptor<flavor>::WRITEPTRPOS);
- if (mRing) unmapGrantorDescr(mRing, MQDescriptor<flavor>::DATAPTRPOS);
- if (mEvFlagWord) unmapGrantorDescr(mEvFlagWord, MQDescriptor<flavor>::EVFLAGWORDPOS);
+ MQDescriptor<T, flavor>::WRITEPTRPOS);
+ if (mRing) unmapGrantorDescr(mRing, MQDescriptor<T, flavor>::DATAPTRPOS);
+ if (mEvFlagWord) unmapGrantorDescr(mEvFlagWord, MQDescriptor<T, flavor>::EVFLAGWORDPOS);
}
template <typename T, MQFlavor flavor>
diff --git a/tests/msgq_test_client.cpp b/tests/msgq_test_client.cpp
index f707f7c..93a3edf 100644
--- a/tests/msgq_test_client.cpp
+++ b/tests/msgq_test_client.cpp
@@ -62,7 +62,7 @@
mService = ITestMsgQ::getService(clientTests::kServiceName);
ASSERT_NE(mService, nullptr);
mService->configureFmqSyncReadWrite([this](
- bool ret, const MQDescriptorSync& in) {
+ bool ret, const MQDescriptorSync<uint16_t>& in) {
ASSERT_TRUE(ret);
mQueue = new (std::nothrow) MessageQueue<uint16_t, kSynchronizedReadWrite>(in);
});
@@ -88,7 +88,7 @@
mService = ITestMsgQ::getService(clientTests::kServiceName);
ASSERT_NE(mService, nullptr);
mService->configureFmqUnsyncWrite(
- [this](bool ret, const MQDescriptorUnsync& in) {
+ [this](bool ret, const MQDescriptorUnsync<uint16_t>& in) {
ASSERT_TRUE(ret);
mQueue = new (std::nothrow) MessageQueue<uint16_t, kUnsynchronizedWrite>(in);
});
diff --git a/tests/msgq_test_service.cpp b/tests/msgq_test_service.cpp
index b23f304..0b690ab 100644
--- a/tests/msgq_test_service.cpp
+++ b/tests/msgq_test_service.cpp
@@ -134,7 +134,7 @@
new (std::nothrow) MessageQueue<uint16_t, kSynchronizedReadWrite>(
kNumElementsInQueue, true /* configureEventFlagWord */);
if ((mFmqSynchronized == nullptr) || (mFmqSynchronized->isValid() == false)) {
- callback(false /* ret */, MQDescriptorSync());
+ callback(false /* ret */, MQDescriptorSync<uint16_t>());
} else {
callback(true /* ret */, *mFmqSynchronized->getDesc());
}
@@ -149,7 +149,7 @@
kNumElementsInQueue);
if ((mFmqUnsynchronized == nullptr) ||
(mFmqUnsynchronized->isValid() == false)) {
- callback(false /* ret */, MQDescriptorUnsync());
+ callback(false /* ret */, MQDescriptorUnsync<uint16_t>());
} else {
callback(true /* ret */, *mFmqUnsynchronized->getDesc());
}