summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorHridya Valsaraju <hridya@google.com>2016-12-19 14:57:44 -0800
committerHridya Valsaraju <hridya@google.com>2016-12-21 14:01:21 -0800
commit92b79dc7938ad2b5e36aebef80d78b061db275b3 (patch)
tree2bbebc0e8c0082e0019d036578b97b4170bf1022 /include
parent8b0d5a5c20cfc786f783e44442787c5ea53f0001 (diff)
downloadplatform_system_libfmq-92b79dc7938ad2b5e36aebef80d78b061db275b3.tar.gz
platform_system_libfmq-92b79dc7938ad2b5e36aebef80d78b061db275b3.tar.bz2
platform_system_libfmq-92b79dc7938ad2b5e36aebef80d78b061db275b3.zip
Add EventFlag support in default MessageQueue constructor.
Also, fix bug in Wait() that was not resetting EventFlag word that caused a wakeup and return the bits that caused the wakeup correctly. Bug: 31223612 33295104 Test: FMQ unit tests Change-Id: I08ff912878282e0ce53612970e16232a8a2bbca5
Diffstat (limited to 'include')
-rw-r--r--include/fmq/MessageQueue.h47
1 files changed, 37 insertions, 10 deletions
diff --git a/include/fmq/MessageQueue.h b/include/fmq/MessageQueue.h
index cf95748..f7d2368 100644
--- a/include/fmq/MessageQueue.h
+++ b/include/fmq/MessageQueue.h
@@ -43,8 +43,10 @@ struct MessageQueue {
* that can contain a maximum of numElementsInQueue elements of type T.
*
* @param numElementsInQueue Capacity of the MessageQueue in terms of T.
+ * @param configureEventFlagWord Boolean that specifies if memory should
+ * also be allocated and mapped for an EventFlag word.
*/
- MessageQueue(size_t numElementsInQueue);
+ MessageQueue(size_t numElementsInQueue, bool configureEventFlagWord = false);
/**
* @return Number of items of type T that can be written into the FMQ
@@ -123,6 +125,13 @@ struct MessageQueue {
*/
const MQDescriptor<flavor>* getDesc() const { return mDesc.get(); }
+ /**
+ * Get a pointer to the Event Flag word if there is one associated with this FMQ.
+ *
+ * @return Pointer to an EventFlag word, will return nullptr if not configured
+ */
+ std::atomic<uint32_t>* getEventFlagWord() const { return mEvFlagWord; }
+
private:
struct region {
uint8_t* address;
@@ -153,12 +162,14 @@ private:
void initMemory(bool resetPointers);
std::unique_ptr<MQDescriptor<flavor>> mDesc;
- uint8_t* mRing;
+ uint8_t* mRing = nullptr;
/*
* TODO(b/31550092): Change to 32 bit read and write pointer counters.
*/
- std::atomic<uint64_t>* mReadPtr;
- std::atomic<uint64_t>* mWritePtr;
+ std::atomic<uint64_t>* mReadPtr = nullptr;
+ std::atomic<uint64_t>* mWritePtr = nullptr;
+
+ std::atomic<uint32_t>* mEvFlagWord = nullptr;
};
template <typename T, MQFlavor flavor>
@@ -203,6 +214,9 @@ void MessageQueue<T, flavor>::initMemory(bool resetPointers) {
mRing = reinterpret_cast<uint8_t*>(mapGrantorDescr
(MQDescriptor<flavor>::DATAPTRPOS));
CHECK(mRing != nullptr);
+
+ mEvFlagWord = static_cast<std::atomic<uint32_t>*>(
+ mapGrantorDescr(MQDescriptor<flavor>::EVFLAGWORDPOS));
}
template <typename T, MQFlavor flavor>
@@ -216,16 +230,25 @@ MessageQueue<T, flavor>::MessageQueue(const MQDescriptor<flavor>& Desc, bool res
}
template <typename T, MQFlavor flavor>
-MessageQueue<T, flavor>::MessageQueue(size_t numElementsInQueue) {
- size_t kQueueSizeBytes = numElementsInQueue * sizeof(T);
+MessageQueue<T, flavor>::MessageQueue(size_t numElementsInQueue, bool configureEventFlagWord) {
/*
* The FMQ needs to allocate memory for the ringbuffer as well as for the
- * read and write pointer counters. Also, Ashmem memory region size needs to
+ * read and write pointer counters. If an EventFlag word is to be configured,
+ * we also need to allocate memory for the same/
+ */
+ size_t kQueueSizeBytes = numElementsInQueue * sizeof(T);
+ size_t kMetaDataSize = 2 * sizeof(android::hardware::RingBufferPosition);
+
+ if (configureEventFlagWord) {
+ kMetaDataSize+= sizeof(std::atomic<uint32_t>);
+ }
+
+ /*
+ * Ashmem memory region size needs to
* be specified in page-aligned bytes.
*/
size_t kAshmemSizePageAligned =
- (kQueueSizeBytes + 2 * sizeof(android::hardware::RingBufferPosition) +
- PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
+ (kQueueSizeBytes + kMetaDataSize + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
/*
* Create an ashmem region to map the memory for the ringbuffer,
@@ -245,7 +268,10 @@ MessageQueue<T, flavor>::MessageQueue(size_t numElementsInQueue) {
mqHandle->data[0] = ashmemFd;
mDesc = std::unique_ptr<MQDescriptor<flavor>>(
- new (std::nothrow) MQDescriptor<flavor>(kQueueSizeBytes, mqHandle, sizeof(T)));
+ new (std::nothrow) MQDescriptor<flavor>(kQueueSizeBytes,
+ mqHandle,
+ sizeof(T),
+ configureEventFlagWord));
if (mDesc == nullptr) {
return;
}
@@ -262,6 +288,7 @@ MessageQueue<T, flavor>::~MessageQueue() {
if (mWritePtr) unmapGrantorDescr(mWritePtr,
MQDescriptor<flavor>::WRITEPTRPOS);
if (mRing) unmapGrantorDescr(mRing, MQDescriptor<flavor>::DATAPTRPOS);
+ if (mEvFlagWord) unmapGrantorDescr(mEvFlagWord, MQDescriptor<flavor>::EVFLAGWORDPOS);
}
template <typename T, MQFlavor flavor>